Feat: add put for student and fix fixture around database
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user