Feat: add update_student to service
This commit is contained in:
@@ -26,10 +26,11 @@ class StudentSQLiteRepository(AbstractRepository):
|
||||
def update(self, student: Student) -> None:
|
||||
search_student = self.conn.execute(
|
||||
"""
|
||||
SELECT id FROM students WHERE id=:id
|
||||
""",
|
||||
SELECT id FROM students WHERE id=:id
|
||||
""",
|
||||
{"id": student.id},
|
||||
).fetchone()
|
||||
|
||||
if search_student is None:
|
||||
raise StudentRepositoryError(f"The student ({student.id=}) does not exists")
|
||||
|
||||
|
||||
@@ -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