This commit is contained in:
@@ -1,20 +1,26 @@
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter
|
||||
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_profiles(db: SessionDep) -> List[AssignmentResponse]:
|
||||
def get_all_assignments(db: SessionDep) -> List[AssignmentResponse]:
|
||||
results: List[AssignmentResponse] = []
|
||||
profiles = db.query(Assignment).all()
|
||||
for profile in profiles:
|
||||
response = to_response(profile)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user