def put(self, id): """Student werden aktualisiert""" adm = ProjectAdministration() student = Student.from_dict(api.payload) if student is None: return "Student konnte nicht geändert werden", 500 else: student.set_id(id) adm.save_student(student) return "Student wurde erfolgreich geändert", 200
def post(self): """Student erstellen""" adm = ProjectAdministration() student = Student.from_dict(api.payload) if student is not None: c = adm.create_student(student.get_user_id(), student.get_name(), student.get_course(), student.get_matriculation_number(), student.get_mail(), student.get_google_id()) return c, 200 else: return '', 500
def post(self): """Anlegen eines neuen student-Objekts. """ adm = ProjectAdministration() std = Student.from_dict(api.payload) if std is not None: """ Wir verwenden id, evaluator, to_be_assessed, passed, grade des Proposals für die Erzeugung eines Customer-Objekts. Das serverseitig erzeugte Objekt ist das maßgebliche und wird auch dem Client zurückgegeben. """ s = adm.create_student(std.get_creation_time(), std.get_name(), std.get_matriculation_nr(), std.get_course_abbr()) return s, 200 else: return '', 500
def put(self, id): """Update eines bestimmten Student-Objekts. **ACHTUNG:** Relevante id ist die id, die mittels URI bereitgestellt und somit als Methodenparameter verwendet wird. Dieser Parameter überschreibt das ID-Attribut des im Payload der Anfrage übermittelten Customer-Objekts. """ adm = ProjectAdministration() stu = Student.from_dict(api.payload) if stu is not None: """Hierdurch wird die id des zu überschreibenden (vgl. Update) Transaction-Objekts gesetzt. Siehe Hinweise oben. """ stu.set_id(id) adm.save_student(stu) return '', 200 else: return '', 500
def find_by_user_id(self, user_id): """Suchen eines Studenten anhand der User_ID.""" result = [] cursor = self._cnx.cursor() command = "SELECT * FROM student WHERE user_id like '{}'".format( user_id) cursor.execute(command) tuples = cursor.fetchall() for (id, user_id, name, course, matriculation_number, mail, google_id, create_time) \ in tuples: student = Student() student.set_id(id) student.set_user_id(user_id) student.set_name(name) student.set_course(course) student.set_matriculation_number(matriculation_number) student.set_mail(mail) student.set_google_id(google_id) student.set_create_time(create_time) result.append(student) self._cnx.commit() cursor.close() return result
def find_by_key(self, id): """Suchen eines Studenten mit vorgegebener ID""" result = [] cursor = self._cnx.cursor() command = "SELECT * FROM student WHERE id like '{}'".format(id) cursor.execute(command) tuples = cursor.fetchall() if len(tuples) != 0: for (id, user_id, name, course, matriculation_number, mail, google_id, create_time) \ in tuples: student = Student() student.set_id(id) student.set_user_id(user_id) student.set_name(name) student.set_course(course) student.set_matriculation_number(matriculation_number) student.set_mail(mail) student.set_google_id(google_id) student.set_create_time(create_time) result.append(student) result = student else: result = None self._cnx.commit() cursor.close() return result
def find_all(self): """Auslesen aller Studenten""" result = [] cursor = self._cnx.cursor() command = "SELECT * FROM student" cursor.execute(command) tuples = cursor.fetchall() for (id, user_id, name, course, matriculation_number, mail, google_id, create_time) \ in tuples: student = Student() student.set_id(id) student.set_user_id(user_id) student.set_name(name) student.set_course(course) student.set_matriculation_number(matriculation_number) student.set_mail(mail) student.set_google_id(google_id) student.set_create_time(create_time) result.append(student) self._cnx.commit() cursor.close() return result
def find_all(self): result = [] cursor = self._cnx.cursor() cursor.execute( "SELECT id, creation_time, name, matriculation_nr, course_abbr FROM student" ) tuples = cursor.fetchall() for (id, creation_time, name, matriculation_nr, course_abbr) in tuples: student = Student() student.set_id(id) student.set_creation_time(creation_time) student.set_name(name) student.set_matriculation_nr(matriculation_nr) student.set_course_abbr(course_abbr) result.append(student) self._cnx.commit() cursor.close() return result
def find_by_id(self, id): result = None cursor = self._cnx.cursor() command = "SELECT id, creation_time, name, matriculation_nr, course_abbr FROM student WHERE id={}".format( id) cursor.execute(command) tuples = cursor.fetchall() if tuples[0] is not None: (id, creation_time, name, matriculation_nr, course_abbr) = tuples[0] student = Student() student.set_id(id) student.set_creation_time(creation_time) student.set_name(name) student.set_matriculation_nr(matriculation_nr) student.set_course_abbr(course_abbr) result = student self._cnx.commit() cursor.close() return result
def find_student_by_course_abbr(self, course_abbr): result = None cursor = self._cnx.cursor() command = "SELECT id, creation_time, name, matriculation_nr, course_abbr FROM student WHERE course_abbr={}".format( course_abbr) cursor.execute(command) tuples = cursor.fetchall() try: (id, creation_time, name, matriculation_nr, course_abbr) = tuples[0] student = Student() student.set_id(id) student.set_creation_time(creation_time) student.set_name(name) student.set_matriculation_nr(matriculation_nr) student.set_course_abbr(course_abbr) result = student except IndexError: result = None self._cnx.commit() cursor.close() return result
def find_by_mail(self, email): result = None cursor = self._cnx.cursor() command = "SELECT * FROM student WHERE email LIKE '%{}%'".format(email) cursor.execute(command) tuples = cursor.fetchall() try: (id, creation_time, name, matriculation_nr, course_abbr, email, google_user_id) = tuples[0] student = Student() student.set_id(id) student.set_creation_time(creation_time) student.set_name(name) student.set_matriculation_nr(matriculation_nr) student.set_course_abbr(course_abbr) student.set_email(email) student.set_google_user_id(google_user_id) result = student except IndexError: result = None self._cnx.commit() cursor.close() return result
def find_by_id(self, id): """Suchen eines Studenten nach der übergebenen ID. :param id Primärschlüsselattribut eines Studenten aus der Datenbank :return Student-Objekt, welche mit der ID übereinstimmt, None wenn kein Eintrag gefunden wurde """ result = None cursor = self._connection.cursor() command = "SELECT id, name, email, google_user_id, mat_nr, kuerzel FROM studenten WHERE id='{}'".format( id) cursor.execute(command) tuples = cursor.fetchall() try: (id, name, email, google_user_id, mat_nr, kuerzel) = tuples[0] student = Student() student.set_id(id) student.set_name(name) student.set_email(email) student.set_google_user_id(google_user_id) student.set_mat_nr(mat_nr) student.set_kuerzel(kuerzel) result = student except IndexError: """Der IndexError wird oben beim Zugriff auf tuples[0] auftreten, wenn der vorherige SELECT-Aufruf keine Tupel liefert, sondern tuples = cursor.fetchall() eine leere Sequenz zurück gibt.""" result = None self._connection.commit() cursor.close() return result
def find_all(self): """Auslesen aller Studenten aus der Datenbank :return Alle Studenten-Objekte im System """ result = [] cursor = self._connection.cursor() cursor.execute("SELECT * from studenten") tuples = cursor.fetchall() for (id, name, email, google_user_id, rolle, mat_nr, kuerzel) in tuples: student = Student() student.set_id(id) student.set_name(name) student.set_email(email) student.set_google_user_id(google_user_id) student.set_rolle(rolle) student.set_mat_nr(mat_nr) student.set_kuerzel(kuerzel) result.append(student) self._connection.commit() cursor.close() return result
from server.bo.Person import Person from server.bo.Student import Student p = Person() p.set_id(1) p.set_rolle(Person.ROLLE_DOZENT) p.set_name("Peter Thies") print(p) s = Student() s.set_id(2) s.set_name("Daria") print(s)
def create_student(self, user_id, name, course, matriculation_number, mail, google_id): """Erstellen des Studenten""" student = Student() student.set_user_id(user_id) student.set_name(name) student.set_course(course) student.set_matriculation_number(matriculation_number) student.set_mail(mail) student.set_google_id(google_id) student.set_id(1) with StudentMapper() as mapper: return mapper.insert(student)
def create_student(self, creation_time, name, matriculation_nr, course_abbr): """Einen Studenten anlegen""" student = Student() student.set_creation_time(creation_time) student.set_name(name) student.set_matriculation_nr(matriculation_nr) student.set_course_abbr(course_abbr) student.set_id(1) with StudentMapper() as mapper: return mapper.insert(student)