Feat: add gets and delete api paths for students
This commit is contained in:
@@ -37,7 +37,6 @@ app = FastAPI()
|
||||
|
||||
@app.post("/tribes", status_code=status.HTTP_201_CREATED, response_model=TribeModel)
|
||||
async def post_tribe(item: TribeModel):
|
||||
|
||||
try:
|
||||
tribe = services.add_tribe(
|
||||
name=item.name, level=item.level, tribe_repo=tribe_repo, conn=conn
|
||||
@@ -120,6 +119,21 @@ async def post_student(item: StudentModel):
|
||||
return student.to_dict()
|
||||
|
||||
|
||||
@app.get("/students/{id}", status_code=status.HTTP_200_OK, response_model=StudentModel)
|
||||
async def get_student(id: str):
|
||||
tribes = tribe_repo.list()
|
||||
student = student_repo.get(id, tribes)
|
||||
return student.to_dict()
|
||||
|
||||
|
||||
@app.get("/students", status_code=status.HTTP_200_OK, response_model=list[StudentModel])
|
||||
async def list_students():
|
||||
tribes = tribe_repo.list()
|
||||
students = student_repo.list(tribes)
|
||||
|
||||
return [t.to_dict() for t in students]
|
||||
|
||||
|
||||
@app.put(
|
||||
"/students/{student_id}",
|
||||
status_code=status.HTTP_200_OK,
|
||||
@@ -153,3 +167,24 @@ async def put_student(student_id, item: StudentModel):
|
||||
)
|
||||
|
||||
return student.to_dict()
|
||||
|
||||
|
||||
@app.delete(
|
||||
"/students/{student_id}",
|
||||
)
|
||||
async def delete_student(student_id):
|
||||
try:
|
||||
student = services.delete_student(
|
||||
id=student_id,
|
||||
student_repo=student_repo,
|
||||
conn=conn,
|
||||
)
|
||||
except StudentDoesExist:
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
content=f"The student ({student_id=}) does not exists. You can't delete it.",
|
||||
)
|
||||
|
||||
return Response(
|
||||
status_code=status.HTTP_204_NO_CONTENT,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user