Пример #1
0
class AlbumCategoryQueryService:
    def __init__(self):
        self.album_category_datasource = CategoryDataSource()

    def find_user_all(self, author_id: AuthorID):
        album_categorys = self.album_category_datasource.find_user_all(
            author_id, CategoryType['ALBUM_CATEGORY'])
        user_album_category_list = CategoryList(album_categorys)
        return user_album_category_list

    def find(self, album_category_id: CategoryID):
        album_category = self.album_category_datasource.find(album_category_id)
        if album_category == None:
            return None
        return album_category
Пример #2
0
class CommonCategoryQueryService:
    def __init__(self):
        self.common_category_datasource = CategoryDataSource()

    def find_user_all(self, author_id: AuthorID):
        common_categorys = self.common_category_datasource.find_user_all(
            author_id, CategoryType['COMMON_CATEGORY'])
        user_common_category_list = CategoryList(common_categorys)
        return user_common_category_list

    def find(self, common_category_id: CategoryID):
        common_category = self.common_category_datasource.find(
            common_category_id)
        if common_category == None:
            return None
        return common_category
Пример #3
0
class CommonCategoryCommandService:
    def __init__(self):
        self.common_category_datasource = CategoryDataSource()

    def register(self, common_category: CommonCategory):
        result = self.common_category_datasource.register(common_category)
        return common_category

    def update(self, org_common_category: CommonCategory,
               new_common_category: CommonCategory):
        if org_common_category.can_update():
            updated_common_category = self.common_category_datasource.update(
                new_common_category)
        return updated_common_category

    def delete(self, common_category: CommonCategory):
        if common_category.can_delete():
            deleted_common_category = self.common_category_datasource.delete(
                common_category)
        return deleted_common_category
Пример #4
0
class AlbumCategoryCommandService:
    def __init__(self):
        self.album_category_datasource = CategoryDataSource()
        self.album_content_command_service = AlbumContentCommandService()
        self.album_content_query_service = AlbumContentQueryService()

    def register(self, album_id: AlbumID, album_category: AlbumCategory):
        self.album_category_datasource.register(album_category)
        # album_contentに登録する
        # albumcontentを渡すようにする
        data = {}
        data['album_id'] = album_id
        data['content'] = album_category
        album_content_factory = AlbumContentFactory()
        album_content = album_content_factory.create(data)
        self.album_content_command_service.register(album_content)

    def update(self, org_album_category: AlbumCategory,
               new_album_category: AlbumCategory):
        if org_album_category.can_update():
            self.album_category_datasource.update(new_album_category)
            return True
        return False

    def delete(self, album_id: AlbumID, album_category: AlbumCategory):
        if album_category.can_delete() is False:
            return False
        self.album_category_datasource.delete(album_category)
        album_content = self.album_content_query_service.find(
            album_id, album_category.category_id)
        # albumcontentを渡すようにする
        self.album_content_command_service.delete(album_content)
        return True
Пример #5
0
class CategoryQueryService:
    def __init__(self):
        self.category_datasource = CategoryDataSource()
        self.category_folder_link_datasource = CategoryFolderLinkDataSource()

    def find_linked_folder(self, category_id: CategoryID):
        return self.category_folder_link_datasource.find_linked_folder(
            category_id)

    def find(self, category_id: CategoryID):
        category = self.category_datasource.find(category_id)
        if category == None:
            return None
        return category
Пример #6
0
 def __init__(self):
     self.category_datasource = CategoryDataSource()
     self.category_folder_link_datasource = CategoryFolderLinkDataSource()
Пример #7
0
 def __init__(self):
     self.common_category_datasource = CategoryDataSource()
Пример #8
0
 def __init__(self):
     self.album_category_datasource = CategoryDataSource()
     self.album_content_command_service = AlbumContentCommandService()
     self.album_content_query_service = AlbumContentQueryService()
Пример #9
0
 def __init__(self):
     self.album_category_datasource = CategoryDataSource()
Пример #10
0
 def __init__(self):
     self.datasource = DataSource()
     self.folder_datasource = FolderDataSource()
     self.category_datasource = CategoryDataSource()
     self.db_prefix = self.datasource.get_prefix()
Пример #11
0
class AlbumContentDataSource:
    def __init__(self):
        self.datasource = DataSource()
        self.folder_datasource = FolderDataSource()
        self.category_datasource = CategoryDataSource()
        self.db_prefix = self.datasource.get_prefix()

    def find_by_album_id(self, album_id: AlbumID):
        sql = 'SELECT * FROM {}_album_content WHERE album_id=%s AND delete_status=%s;'.format(
            self.db_prefix)
        parameter = [album_id.value, DeleteStatus.UNDELETED.name]
        album_content_rel_list = self.datasource.get(sql, parameter, True)
        if len(album_content_rel_list) == 0:
            return None
        content_obj_list = []
        for album_content_rel in album_content_rel_list:
            content_obj_list.append(
                self._rel_to_album_content_obj(album_content_rel))

        data = {'album_id': album_id, 'content_obj_list': content_obj_list}
        return AlbumContentList.from_dict(data)

    def find_linked_content(self, album_id: AlbumID, content_id: ContentID):
        sql = 'SELECT * FROM {}_category_folder_link INNER JOIN {}_folder ON {}_category_folder_link.folder_id = {}_folder.folder_id WHERE category_id=%s'.format(
            self.db_prefix,
            self.db_prefix,
            self.db_prefix,
            self.db_prefix,
        )
        parameter = [content_id.value]
        content_dict_list = self.datasource.get(sql, parameter, True)
        content_obj_list = []
        album_content_dict = {}
        for content_dict in content_dict_list:
            content_dict['content_id'] = content_dict['folder_id']
            content_dict['album_id'] = album_id.value
            content_obj_list.append(self._to_album_content_obj(content_dict))

        data = {'album_id': album_id, 'content_obj_list': content_obj_list}
        return AlbumContentList.from_dict(data)

    def find(self, album_id: AlbumID, content_id: ContentID):
        sql = 'SELECT * FROM {}_album_content WHERE album_id=%s AND content_id=%s;'.format(
            self.db_prefix)
        parameter = [album_id.value, content_id.value]
        album_content_rel_list = self.datasource.get(sql, parameter, True)
        if len(album_content_rel_list) == 0:
            return None
        album_content_rel = album_content_rel_list[0]
        album_content_obj = self._rel_to_album_content_obj(album_content_rel)

        return album_content_obj

    def register(self, album_id: AlbumID, content_id: ContentID):
        sql = 'INSERT INTO {}_album_content(album_id,content_id,delete_status) VALUES(%s,%s,%s) ;'.format(
            self.db_prefix)
        parameter = [
            album_id.value, content_id.value, DeleteStatus.UNDELETED.name
        ]
        self.datasource.insert(sql, parameter, True)

        return True

    def delete(self, album_id: AlbumID, content_id: ContentID):
        try:
            sql = 'UPDATE {}_album_content SET delete_status=%s WHERE album_id=%s AND content_id=%s;'.format(
                self.db_prefix)
            parameter = [
                DeleteStatus.DELETED.name,
                album_id.value,
                content_id.value,
            ]
            self.datasource.update(sql, parameter, True)

        except:
            raise

        return True

    def _rel_to_album_content_obj(self, album_content_rel):
        content_id = ContentID(album_content_rel['content_id'])
        content_type = Content.check_content_type(content_id)
        if content_type == 'folder':
            content = self.folder_datasource.find(content_id)
        if content_type == 'album_category' or (content_type
                                                == 'common_category'):
            content = self.category_datasource.find(content_id)
        return AlbumContent(
            album_id=AlbumID(album_content_rel['album_id']),
            content=content,
            delete_status=DeleteStatus[album_content_rel['delete_status']])

    def _to_album_content_obj(self, album_content_dict):
        content_id = ContentID(album_content_dict['content_id'])
        content_type = Content.check_content_type(content_id)
        if content_type == 'folder':
            content = Folder.from_dict(album_content_dict)
        if content_type == 'album_category' or (content_type
                                                == 'common_category'):
            content = Category.from_dict(album_content_dict)
        return AlbumContent(
            album_id=AlbumID(album_content_dict['album_id']),
            content=content,
            delete_status=DeleteStatus[album_content_dict['delete_status']])