Feat: add update_student to service

This commit is contained in:
2022-12-30 10:34:20 +01:00
parent 94c942d055
commit 066990d109
3 changed files with 135 additions and 9 deletions

View File

@@ -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