def put(self, article_id): """Update eines bestimmten Artikel-Objekts.""" adm = Administration() art = Article.from_dict(api.payload) if art is not None: art.set_id(article_id) adm.save_article(art) return '', 200 else: return '', 500
def create_article(self, name: str, group_id: int): """Artikel erstellen :param name: Name :param group_id: ID der zugehörigen Gruppe :return: Artikel-Objekt """ article = Article() article.set_id(0), article.set_name(name), article.set_group(group_id) with ArticleMapper() as mapper: return mapper.insert(article)
def post(self, group_id): """Anlegen eines neuen Artikel-Objekts.""" adm = Administration() art = adm.get_group_by_id(group_id) proposal = Article.from_dict(api.payload) if art is not None and proposal is not None: result = adm.create_article(proposal.get_name(), group_id) return result else: return "Group unkown or payload not valid", 500
def find_all(self): """Auslesen aller vorhandenen Artikel :return Eine Sammlung aller Artikel-Objekten. """ cursor = self._connection.cursor() command = "SELECT * FROM holma.article" cursor.execute(command) tuples = cursor.fetchall() result = Article.from_tuples(tuples) self._connection.commit() cursor.close() return result
def find_by_group(self, group_id): """Auslesen von Artikeln durch Fremdschlüssel (group_id) geg. Gruppe :param group_id: :return: Eine Sammlung mit Artikel-Objekten. """ cursor = self._connection.cursor() command = "SELECT * FROM holma.article " \ "WHERE group_id={}".format(group_id) cursor.execute(command) tuples = cursor.fetchall() result = Article.from_tuples(tuples) self._connection.commit() cursor.close() return result
def find_by_name(self, name): """Auslesen von Artikeln durch Name :param name: :return Eine Sammlung mit Artikel-Objekten. """ cursor = self._connection.cursor() command = "SELECT * FROM holma.article WHERE name LIKE '{}' " \ "ORDER BY name".format(name) cursor.execute(command) tuples = cursor.fetchall() result = Article.from_tuples(tuples) self._connection.commit() cursor.close() return result
def find_by_id(self, article_id): """Eindeutiges Auslesen eines Artikels durch ID :param article_id: :return Artikel-Objekt, das der übergebenen ID entspricht oder None wenn DB-Tupel nicht vorhanden ist. """ cursor = self._connection.cursor() command = "SELECT * FROM holma.article " \ "WHERE article_id={}".format(article_id) cursor.execute(command) tuples = cursor.fetchall() result = Article.from_tuples(tuples) self._connection.commit() cursor.close() if len(result) == 0: return None return result[0]