90 lines
2.9 KiB
Python
90 lines
2.9 KiB
Python
from fastapi import APIRouter,Depends
|
|
from fastapi.responses import JSONResponse
|
|
from fastapi import HTTPException
|
|
from pydantic import BaseModel
|
|
from db_setup import get_session
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from interview.views import Calendar
|
|
from users.permissions import PermissionTag,require_permission
|
|
from dotenv import load_dotenv
|
|
load_dotenv()
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class CalendarCreateBody(BaseModel):
|
|
duration_minutes: int | None = 30
|
|
|
|
|
|
class CalendarRescheduleBody(BaseModel):
|
|
instant: str
|
|
duration_minutes: int | None = 30
|
|
|
|
|
|
class CalendarCancelBody(BaseModel):
|
|
comment: str | None = None
|
|
|
|
|
|
@router.post("/interview/{interview_id}/calendar-event")
|
|
async def create_calendar_event(
|
|
interview_id: str,
|
|
payload: CalendarCreateBody | None = None,
|
|
current_user: dict = Depends(require_permission(PermissionTag.INTERVIEWS_CREATE)),
|
|
session: AsyncSession = Depends(get_session),
|
|
):
|
|
try:
|
|
body=payload or CalendarCreateBody()
|
|
service=Calendar(session=session)
|
|
data=await service.create_for_interview(
|
|
interview_id,
|
|
duration_minutes=body.duration_minutes,
|
|
current_user=current_user,
|
|
)
|
|
return JSONResponse(content={"data":data,"total":1,"status_code":200})
|
|
except HTTPException:
|
|
raise
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500,detail=str(e))
|
|
|
|
|
|
@router.patch("/interview/{interview_id}/calendar-event/reschedule")
|
|
async def reschedule_calendar_event(
|
|
interview_id: str,
|
|
payload: CalendarRescheduleBody,
|
|
current_user: dict = Depends(require_permission(PermissionTag.INTERVIEWS_EDIT)),
|
|
session: AsyncSession = Depends(get_session),
|
|
):
|
|
try:
|
|
service=Calendar(session=session)
|
|
data=await service.reschedule_for_interview(
|
|
interview_id,
|
|
instant=payload.instant,
|
|
duration_minutes=payload.duration_minutes,
|
|
current_user=current_user,
|
|
)
|
|
return JSONResponse(content={"data":data,"total":1,"status_code":200})
|
|
except HTTPException:
|
|
raise
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500,detail=str(e))
|
|
|
|
|
|
@router.post("/interview/{interview_id}/calendar-event/cancel")
|
|
async def cancel_calendar_event(
|
|
interview_id: str,
|
|
payload: CalendarCancelBody | None = None,
|
|
current_user: dict = Depends(require_permission(PermissionTag.INTERVIEWS_EDIT)),
|
|
session: AsyncSession = Depends(get_session),
|
|
):
|
|
try:
|
|
body=payload or CalendarCancelBody()
|
|
service=Calendar(session=session)
|
|
data=await service.cancel_for_interview(
|
|
interview_id,comment=body.comment,current_user=current_user,
|
|
)
|
|
return JSONResponse(content={"data":data,"total":1,"status_code":200})
|
|
except HTTPException:
|
|
raise
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500,detail=str(e))
|