def create_person(self, creation_date, name, google_id, role_id): """Eine Person anlegen""" person = Person() person.set_name(name) person.set_google_id(google_id) person.set_role_id(role_id) person.set_id(1) with PersonMapper() as mapper: return mapper.insert(person)
def post(self): """Anlegen eines neuen Personen-Objekts""" adm = ProjectAdministration() proposal = Person.from_dict(api.payload) if proposal is not None: pers = adm.create_person(proposal.get_creation_date(), proposal.get_name(), proposal.get_google_id(), proposal.get_role_id()) return pers, 200 else: return '', 500
def put(self): """Update eines bestimmten Personen-Objekts.""" adm = ProjectAdministration() pers = Person.from_dict(api.payload) print(pers) if pers is not None: adm.save_person(pers) return pers, 200 else: return '', 500
def find_by_name(self, name): """Auslesen aller Personen anhand des Namens. :param name :return Eine Sammlung mit Person-Objekten, die sämtliche Personen mit dem gewünschten Namen enthält. """ result = [] cursor = self._cnx.cursor() command = "SELECT person_id, creation_date, name, google_id, role_id FROM person WHERE name='{}' ORDER BY name".format( name) cursor.execute(command) tuples = cursor.fetchall() for (id, creation_date, name, google_id, role_id) in tuples: person = Person() person.set_id(id) person.set_creation_date(creation_date) person.set_name(name) person.set_google_id(google_id) person.set_role_id(role_id) result = person self._cnx.commit() cursor.close() return result
def find_by_role_id(self, role_id): """Auslesen aller Personen anhand der Rolle. :param role_id :return Eine Sammlung mit Person-Objekten, die sämtliche Personen mit der gewünschten Rolle enthält. """ result = [] cursor = self._cnx.cursor() command = "SELECT * FROM person WHERE role_id='{}' ORDER BY role_id".format( role_id) cursor.execute(command) tuples = cursor.fetchall() for (id, creation_date, name, google_id, role_id) in tuples: person = Person() person.set_id(id) person.set_creation_date(creation_date) person.set_name(name) person.set_google_id(google_id) person.set_role_id(role_id) result.append(person) self._cnx.commit() cursor.close() return result
def find_by_id(self, id): """Auslesen einer Person durch die ID :param id :return Person-Objekt, das der übergebenen ID entspricht """ result = [] cursor = self._cnx.cursor() command = "SELECT person_id, creation_date, name, google_id, role_id FROM person WHERE person_id={} ORDER BY person_id".format( id) cursor.execute(command) tuples = cursor.fetchall() for (id, creation_date, name, google_id, role_id) in tuples: person = Person() person.set_id(id) person.set_creation_date(creation_date) person.set_name(name) person.set_google_id(google_id) person.set_role_id(role_id) result = person self._cnx.commit() cursor.close() return result
def find_by_google_id(self, google_id): """Auslesen einer Person durch die Google-ID :param google_id :return Person-Objekt, das der übergebenen Google-ID entspricht """ result = [] cursor = self._cnx.cursor() command = "SELECT person_id, creation_date, name, google_id, role_id FROM person WHERE google_id='{}' ORDER BY google_id".format( google_id) cursor.execute(command) tuples = cursor.fetchall() try: (id, creation_date, name, google_id, role_id) = tuples[0] person = Person() person.set_id(id) person.set_creation_date(creation_date) person.set_name(name) person.set_google_id(google_id) person.set_role_id(role_id) result = person except IndexError: result = None self._cnx.commit() cursor.close() return result
def find_all(self): """Auslesen aller vorhandenen Personen. :return Eine Sammlung aller Personen-Objekte """ result = [] cursor = self._cnx.cursor() cursor.execute("SELECT * FROM person") tuples = cursor.fetchall() for (id, creation_date, name, google_id, role_id) in tuples: person = Person() person.set_id(id) person.set_creation_date(creation_date) person.set_name(name) person.set_google_id(google_id) person.set_role_id(role_id) result.append(person) self._cnx.commit() cursor.close() return result