示例#1
0
    def get_all_groups(self):
        """Alle Gruppen der Datenbank abfragen

        :return: Liste mit Gruppen
        """
        with GroupMapper() as mapper:
            return mapper.find_all()
示例#2
0
    def get_groups_by_name(self, name: str):
        """Gruppen anhand ihres Namens finden

        :param name: Name
        :return: Liste mit Gruppen
        """
        with GroupMapper() as mapper:
            return mapper.find_by_name(name)
示例#3
0
    def get_group_by_id(self, group_id: int):
        """Gruppe anhand ihrer ID ausgeben

        :param group_id: ID der Gruppe
        :return: Gruppen-Objekt
        """
        with GroupMapper() as mapper:
            return mapper.find_by_id(group_id)
示例#4
0
    def save_group(self, group: Group):
        """Gruppe aktualisieren

        :param group: Gruppen-Objekt
        :return: Aktualisiertes Gruppen-Objekt
        """
        group.set_last_updated(datetime.now())
        with GroupMapper() as mapper:
            return mapper.update(group)
示例#5
0
    def create_group(self, name: str, user_id: int):
        """Gruppe erstellen

        :param name: Name
        :param user_id: ID des Erstellers
        :return: Gruppen-Objekt
        """
        group = Group()
        group.set_id(0)
        group.set_name(name)
        group.set_owner(user_id)
        with GroupMapper() as mapper:
            return mapper.insert(group)
示例#6
0
    def delete_user(self, user):
        """User löschen

        :param user: User-Objekt
        :return:
        """
        with UserGroupRelationsMapper() as mapper:
            mapper.delete_user_relations(user)

        with ListEntryMapper() as mapper:
            mapper.delete_purchasing_user(user)

        with GroupMapper() as mapper:
            mapper.delete_owner(user)

        with UserMapper() as mapper:
            mapper.delete(user)
示例#7
0
    def remove_member_from_group(self, group: Group, user: User):
        """User von einer Gruppe entfernen und allen zugehörigen
        Beziehungen lösen

        :param group: Gruppen-Objekt
        :param user: User-Objekt
        :return:
        """
        with GroupMapper() as mapper:
            mapper.delete_owner(user, group)

        with ShoppingListMapper() as mapper:
            shopping_lists = mapper.find_by_group(group)

            with ListEntryMapper() as mapper:
                for shopping_list in shopping_lists:
                    mapper.delete_purchasing_user(user, shopping_list)

        with UserGroupRelationsMapper() as mapper:
            mapper.remove_user_from_group(group, user)
示例#8
0
    def delete_group(self, group: Group):
        """Gruppe und zugehörige Beziehungen löschen

        :param group: Gruppen-Objekt
        :return:
        """

        # User löschen
        with UserGroupRelationsMapper() as mapper:
            mapper.delete_group_relations(group)

        # Standardartikel löschen
        with ListEntryMapper() as mapper:
            mapper.delete_standardarticle_by_group(group)

        # Shoppinglists löschen
        with ShoppingListMapper() as shopping_list_mapper:
            shopping_lists = shopping_list_mapper.find_by_group(group)

            # Listeineinträge anhand der ShoppingLists löschen
            with ListEntryMapper() as mapper:
                for shopping_list in shopping_lists:
                    mapper.delete_by_shopping_list(shopping_list)

            shopping_list_mapper.delete_by_group(group)

        # Artikel löschen
        with ArticleMapper() as article_mapper:
            articles = article_mapper.find_by_group(group.get_id())

            # Übrige Listeneinträge nach Artikel löschen
            with ListEntryMapper() as mapper:
                for article in articles:
                    mapper.delete_by_article(article)

            article_mapper.delete_by_group(group)

        # Gruppe löschen
        with GroupMapper() as mapper:
            mapper.delete(group)