Feat: add gets and delete api paths for students

This commit is contained in:
2022-12-30 14:41:23 +01:00
parent f3302e2132
commit 07595f1fd8
3 changed files with 77 additions and 4 deletions

View File

@@ -77,12 +77,29 @@ class StudentSQLiteRepository(AbstractRepository):
rows = cursor.fetchall()
return [self._rebuild_student(r, tribes) for r in rows]
def delete(self, student: Student) -> None:
def list_id(self):
cursor = self.conn.cursor()
cursor.execute(
"""
SELECT id FROM students
"""
)
rows = cursor.fetchall()
return [r[0] for r in rows]
def delete(self, id: str) -> None:
students_id = self.list_id()
if id not in students_id:
raise StudentRepositoryError(
f"The student {id} doesn't exists. Can't delete it."
)
self.conn.execute(
"""
DELETE FROM students WHERE id=:id
""",
{
"id": student.id,
"id": id,
},
)