27 lines
982 B
Python
27 lines
982 B
Python
from typing import List
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
|
|
from src.db.models.admin import Assignment
|
|
from src.db.session import SessionDep
|
|
from src.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
|