Skip to content

Instantly share code, notes, and snippets.

@koorukuroo
Created April 20, 2026 06:24
Show Gist options
  • Select an option

  • Save koorukuroo/2ad5e577d652f3d9fc98eed7dd76bd45 to your computer and use it in GitHub Desktop.

Select an option

Save koorukuroo/2ad5e577d652f3d9fc98eed7dd76bd45 to your computer and use it in GitHub Desktop.
@app.put("/api/v1/requests/{request_id}/status",
response_model=RequestResponse,
tags=["점검 요청"])
def update_status(request_id: int,
update: StatusUpdate,
db: Session = Depends(get_db)):
req = db.query(InspectionRequest) \
.filter(InspectionRequest.id == request_id) \
.first()
if not req:
raise HTTPException(
status_code=404,
detail="점검 요청을 찾을 수 없습니다")
# 상태 전이 검증
allowed = VALID_TRANSITIONS.get(req.status, [])
if update.status not in allowed:
raise HTTPException(
status_code=400,
detail=f"'{req.status}'에서 "
f"'{update.status}'로 변경 불가. "
f"가능: {allowed}")
# 상태 이력 기록 + 업데이트
history = StatusHistory(
request_id=req.id,
from_status=req.status,
to_status=update.status,
changed_by=update.changed_by,
comment=update.comment)
req.status = update.status
if update.assignee_id:
req.assignee_id = update.assignee_id
db.add(history)
db.commit()
db.refresh(req)
return req
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment