from typing import List from fastapi import APIRouter, HTTPException from kontor_model.db.models.admin import Assignment from src.db.session import SessionDep from kontor_model.schema.user.assignment import AssignmentResponse, to_response router = APIRouter() @router.get("/assignments", response_model=List[AssignmentResponse]) def get_all_assignments(db: SessionDep) -> List[AssignmentResponse]: results: List[AssignmentResponse] = [] assignments = db.query(Assignment).all() for assignment in assignments: response = to_response(assignment) results.append(response) return results @router.get("/assignments/{assignment_id}", response_model=AssignmentResponse) def get_assignment(assignment_id: str, db: SessionDep) -> AssignmentResponse: assignment = db.get(Assignment, assignment_id) if assignment is None: raise HTTPException(status_code=404, detail="Assignment could not be found") response = to_response(assignment) return response