def get_stud(student_number): c.execute("SELECT * FROM students WHERE student_number=%s", (str(student_number), )) res = c.fetchone() if res: return Student(res[0], res[1], res[3]) return None
def query_student(self, filters=None) -> List[Student]: c = self.connection.cursor() if filters is None: c.execute("SELECT * FROM students") else: terms = [] where_text = "" if "student_number" in filters: if where_text == "": where_text += " WHERE" else: where_text += " AND" where_text += " student_number=%s" terms.append(filters["student_number"]) if "first_name" in filters: if where_text == "": where_text += " WHERE" else: where_text += " AND" where_text += " first_name=%s" terms.append(filters["first_name"]) if "last_name" in filters: if where_text == "": where_text += " WHERE" else: where_text += " AND" where_text += " last_name=%s" terms.append(filters["last_name"]) c.execute("SELECT * FROM students" + where_text, tuple(terms)) students = c.fetchall() if len(students) > 0: students = map(lambda res: Student(res[0], res[1], res[3]), students) return list(students)
def create_student(self, first_name: str, last_name: str, student_number: str, password: str) -> Result[Student, str]: password_hash = self.password_authenticator.crypto_context.hash( password) student = Student(first_name, last_name, student_number) return self.student_persistence.create_student(student, password_hash)
def get_student(self, user_identity: str) -> Option[Student]: c = self.connection.cursor() term = (user_identity, ) c.execute("SELECT * FROM students WHERE student_number=%s", term) student = None res = c.fetchone() if res: student = Student(res[0], res[1], res[3]) return maybe(student)
def fake_student() -> Student: return Student(fake.first_name(), fake.last_name(), fake.pystr())