Beispiel #1
0
def common_category(common_category_id):
    user = flask_login.current_user
    author_id = AuthorID(user.user_id.value)
    if request.method == 'GET':
        common_category_query_service = CommonCategoryQueryService()
        common_category_obj = common_category_query_service.find(
            CategoryID(common_category_id))
        if common_category_obj is None:
            txt = 'common_category do not exist'
            return txt.encode("UTF-8")

        common_category_dict = common_category_obj.to_dict()
        json_txt = json.dumps(common_category_dict, indent=4)
        return json_txt.encode("UTF-8")

    if request.method == 'PUT':
        post_data = request.json

        common_category_query_service = CommonCategoryQueryService()
        org_common_category = common_category_query_service.find(
            CategoryID(common_category_id))
        if org_common_category is None:
            txt = 'common_category do not exist'
            return txt.encode("UTF-8")

        new_common_category = org_common_category.modify(post_data)

        common_category_command_service = CommonCategoryCommandService()
        updated_common_category = common_category_command_service.update(
            org_common_category, new_common_category)

        common_category_dict = updated_common_category.to_dict()
        json_txt = json.dumps(common_category_dict, indent=4)
        return json_txt.encode("UTF-8")

    if request.method == 'DELETE':
        post_data = request.json

        common_category_query_service = CommonCategoryQueryService()
        org_common_category = common_category_query_service.find(
            CategoryID(common_category_id))

        common_category_command_service = CommonCategoryCommandService()
        try:
            deleted_common_category = common_category_command_service.delete(
                org_common_category)
        except:
            msg = 'common_category[' + org_common_category.common_category_id.value + '] delete is failuer'
            return msg.encode("UTF-8")

        json_txt = json.dumps(deleted_common_category, indent=4)
        return json_txt.encode("UTF-8")
Beispiel #2
0
def album_category(album_id, album_category_id):
    user = flask_login.current_user
    author_id = AuthorID(user.user_id.value)
    album_id = AlbumID(album_id)
    if request.method == 'GET':
        album_category_query_service = AlbumCategoryQueryService()
        album_category_obj = album_category_query_service.find(
            CategoryID(album_category_id))
        if album_category_obj is None:
            txt = 'album_category do not exist'
            return txt.encode("UTF-8")

        album_category_dict = album_category_obj.to_dict()
        json_txt = json.dumps(album_category_dict, indent=4)
        return json_txt.encode("UTF-8")

    if request.method == 'PUT':
        post_data = request.json

        album_category_query_service = AlbumCategoryQueryService()
        org_album_category = album_category_query_service.find(
            CategoryID(album_category_id))
        if org_album_category is None:
            txt = 'album_category do not exist'
            return txt.encode("UTF-8")

        new_album_category = org_album_category.modify(post_data)

        album_category_command_service = AlbumCategoryCommandService()
        result = album_category_command_service.update(org_album_category,
                                                       new_album_category)
        if result is True:
            album_category_dict = new_album_category.to_dict()
            json_txt = json.dumps(album_category_dict, indent=4)
            return json_txt.encode("UTF-8")

    if request.method == 'DELETE':
        post_data = request.json

        album_category_query_service = AlbumCategoryQueryService()
        org_album_category = album_category_query_service.find(
            CategoryID(album_category_id))

        album_category_command_service = AlbumCategoryCommandService()
        try:
            album_category_command_service.delete(album_id, org_album_category)
        except:
            msg = 'album_category[' + org_album_category.category_id.value + '] delete is failuer'
            return msg.encode("UTF-8")

        json_txt = json.dumps(org_album_category.to_dict(), indent=4)
        return json_txt.encode("UTF-8")
Beispiel #3
0
 def _to_category_obj(dict_data):
     return CommonCategory(
         category_id=CategoryID(dict_data["category_id"]),
         category_type=CategoryType[dict_data["category_type"]],
         info=InfoFactory.create(dict_data['info']),
         share=ShareFactory.create(dict_data['share']),
     )
Beispiel #4
0
def category_get(category_id):
    user = flask_login.current_user
    if request.method == 'GET':
        category_id = CategoryID(category_id)
        category_query_service = CategoryQueryService()
        category = category_query_service.find(category_id)
        if category is None:
            txt = 'category do not exist'
            return txt.encode("UTF-8")

        category_dict = category.to_dict()
        json_txt = json.dumps(category_dict, indent=4)
        return json_txt.encode("UTF-8")
Beispiel #5
0
def category_folder_index(category_id):
    user = flask_login.current_user
    author_id = AuthorID(user.user_id.value)
    if request.method == 'GET':
        category_id = CategoryID(category_id)
        category_query_service = CategoryQueryService()
        folder_list = category_query_service.find_linked_folder(category_id)
        if folder_list is None:
            txt = 'folder do not exist'
            return txt.encode("UTF-8")

        folder_list_dict = folder_list.to_dict()
        json_txt = json.dumps(folder_list_dict, indent=4)
        return json_txt.encode("UTF-8")
Beispiel #6
0
def folder(album_id, content_id, folder_id):
    album_id = AlbumID(album_id)
    content_id = CategoryID(content_id)
    folder_id = FolderID(folder_id)
    if request.method == 'GET':
        folder_query_service = FolderQueryService()
        folder_obj = folder_query_service.find(folder_id)
        if folder_obj is None:
            txt = 'folder do not exist'
            return txt.encode("UTF-8")

        folder_dict = folder_obj.to_dict()
        json_txt = json.dumps(folder_dict, indent=4)
        return json_txt.encode("UTF-8")
Beispiel #7
0
def category_folder_index(album_id, content_id):
    album_id = AlbumID(album_id)
    content_id = CategoryID(content_id)
    if request.method == 'GET':
        album_content_query_service = AlbumContentQueryService()
        album_content = album_content_query_service.find_linked_content(
            album_id, content_id)
        if album_content is None:
            txt = 'content do not exist'
            return txt.encode("UTF-8")

        content_list_dict = album_content.to_dict()
        json_txt = json.dumps(content_list_dict, indent=4)
        return json_txt.encode("UTF-8")
Beispiel #8
0
def category(category_id, folder_id):
    user = flask_login.current_user
    author_id = AuthorID(user.user_id.value)
    category_id = CategoryID(category_id)
    folder_id = FolderID(folder_id)
    # カテゴリーにフォルダを紐付けることが出来る
    # /category/_id - POST {folder_id: folder-aaaaaaaaaaaaa}
    if request.method == 'POST':
        folder_query_service = FolderQueryService()
        folder = folder_query_service.find(folder_id)
        category_query_service = CategoryQueryService()
        category = category_query_service.find(category_id)
        category_command_service = CategoryCommandService()
        result = category_command_service.link_folder(category, folder)
        if result is False:
            txt = 'This folder can not link'
            return txt.encode("UTF-8")

        txt = 'create folder link'
        return txt.encode("UTF-8")

    # カテゴリーとフォルダの紐付けを外すことが出来る
    # /category/_id - DELETE {folder_id: folder-aaaaaaaaaaaaa}
    if request.method == 'DELETE':
        folder_query_service = FolderQueryService()
        folder = folder_query_service.find(folder_id)
        category_query_service = CategoryQueryService()
        category = category_query_service.find(category_id)
        category_command_service = CategoryCommandService()
        result = category_command_service.unlink_folder(category, folder)
        if result is False:
            txt = 'This folder can not unlink'
            return txt.encode("UTF-8")

        txt = 'delete folder link'
        return txt.encode("UTF-8")
Beispiel #9
0
 def _to_category_obj(dict_data):
     return AlbumCategory(
         category_id=CategoryID(dict_data["category_id"]),
         category_type=CategoryType[dict_data["category_type"]],
         info=InfoFactory.create(dict_data['info']),
     )