| 12345678910111213141516171819202122232425262728293031323334353637 |
- """值班排班 · 公开抢班 API(免登录)"""
- from __future__ import annotations
- from fastapi import APIRouter, Depends, HTTPException
- from sqlalchemy.orm import Session
- from app.core.database import get_db
- from app.core.response import error_response, success_response
- from app.schemas.duty import DutyGrabBody
- from app.services import duty_schedule as duty_svc
- from app.services.duty_schedule import DutyBizError
- router = APIRouter(prefix="/public/duty", tags=["值班排班-公开"])
- @router.get("/{token}")
- def public_page(token: str, db: Session = Depends(get_db)):
- try:
- data = duty_svc.get_public_page(db, token)
- return success_response(data)
- except DutyBizError as exc:
- msg = str(exc)
- if "无效" in msg:
- raise HTTPException(status_code=404, detail=msg)
- return error_response(400, msg)
- @router.post("/{token}/grab")
- def public_grab(token: str, body: DutyGrabBody, db: Session = Depends(get_db)):
- try:
- data = duty_svc.grab(db, token, body.shiftType, body.userId)
- return success_response(data, message="报名成功")
- except DutyBizError as exc:
- msg = str(exc)
- if "无效" in msg:
- raise HTTPException(status_code=404, detail=msg)
- return error_response(400, msg)
|