from typing import Annotated from fastapi import APIRouter, Depends, HTTPException from scheduler.api.dependencies import get_schedule_service from scheduler.core.schemas.schedule import ( ClockInRequest, ClockOutRequest, CreateScheduleRequest, GenerateWeeklyScheduleRequest, ScheduleResponse, WeeklyScheduleResponse, ) from scheduler.core.services.schedule_service import ScheduleService router = APIRouter(tags=["schedules"]) @router.post("/schedules", response_model=ScheduleResponse) def create_schedule(payload: CreateScheduleRequest, service: Annotated[ScheduleService, Depends(get_schedule_service)]): schedule = service.create_schedule(payload.user_id, payload.enter_time, payload.day_of_week, payload.out_time) if schedule is None: raise HTTPException(status_code=404, detail="Employee not found") return schedule @router.post("/employees/{id}/clock-in", response_model=ScheduleResponse) def clock_in( id: int, payload: ClockInRequest, service: Annotated[ScheduleService, Depends(get_schedule_service)], ): schedule = service.clock_in( id, day_of_week=payload.day_of_week, enter_time=payload.enter_time, ) if schedule is None: raise HTTPException(status_code=404, detail="Employee not found") return schedule @router.put("/employees/{id}/clock-out", response_model=ScheduleResponse) def clock_out( id: int, payload: ClockOutRequest, service: Annotated[ScheduleService, Depends(get_schedule_service)], ): schedule = service.clock_out(id, payload.day_of_week, payload.out_time) if schedule is None: raise HTTPException(status_code=404, detail="Schedule not found") return schedule @router.get("/schedules/weekly", response_model=WeeklyScheduleResponse) def get_weekly_schedule(service: Annotated[ScheduleService, Depends(get_schedule_service)]): return service.get_weekly_schedule() @router.post("/schedules/weekly/generate", response_model=WeeklyScheduleResponse) def generate_weekly_schedule( payload: GenerateWeeklyScheduleRequest, service: Annotated[ScheduleService, Depends(get_schedule_service)], ): schedule = service.generate_weekly_schedule(payload.company_id) if schedule is None: raise HTTPException(status_code=404, detail="Company not found") return schedule