Feat: add put for student and fix fixture around database

This commit is contained in:
2022-12-29 17:47:40 +01:00
parent c541d0063f
commit 5cf062c7a0
8 changed files with 94 additions and 87 deletions

View File

@@ -86,3 +86,26 @@ async def post_student(item: StudentModel):
conn.commit()
return student.to_dict()
@app.put(
"/students/{student_id}",
status_code=status.HTTP_200_OK,
response_model=StudentModel,
)
async def put_student(student_id, item: StudentModel):
tribe_name = item.tribe_name
try:
tribe = tribe_repo.get(tribe_name)
except TribeRepositoryError:
return JSONResponse(
status_code=status.HTTP_409_CONFLICT,
content=f"The tribe {tribe_name} does not exists. You can't add a student in it.",
)
student = Student(name=item.name, tribe=tribe, id=student_id)
student_repo.update(student)
conn.commit()
return student.to_dict()