Feat: add update_student to service
This commit is contained in:
@@ -74,3 +74,32 @@ def add_student(
|
||||
|
||||
conn.commit()
|
||||
return student
|
||||
|
||||
|
||||
def update_student(
|
||||
id: str,
|
||||
name: str,
|
||||
tribe: str,
|
||||
student_repo: AbstractRepository,
|
||||
tribe_repo: AbstractRepository,
|
||||
conn,
|
||||
) -> Student:
|
||||
|
||||
try:
|
||||
_tribe = tribe_repo.get(tribe)
|
||||
except TribeRepositoryError:
|
||||
raise TribeDoesNotExist(
|
||||
f"The tribe {tribe} does not exists. Can't update a student with it"
|
||||
)
|
||||
|
||||
student = Student(id=id, name=name, tribe=_tribe)
|
||||
|
||||
try:
|
||||
student_repo.update(student)
|
||||
except StudentRepositoryError:
|
||||
raise StudentDoesExist(
|
||||
f"The student {student.name} ({student.id=}) does not exists. Can't update it."
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
return student
|
||||
|
||||
Reference in New Issue
Block a user