Skip to content

Commit

Permalink
Feat: get catalog by group
Browse files Browse the repository at this point in the history
Signed-off-by: harlee-x <[email protected]>
  • Loading branch information
harlee-x committed Aug 2, 2024
1 parent c637b2c commit c87b225
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
31 changes: 25 additions & 6 deletions kdp_catalog_manager/api/api_v1/endpoints/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
NOT_FOUND_README_HTML
from kdp_catalog_manager.config.base_config import DEFAULT_LANG, SUPPORT_LANG
from kdp_catalog_manager.domain.model.catalog import CatalogList, \
CatalogDataOut, CatalogCategory, Catalogglobal
CatalogDataOut, CatalogCategory, Catalogglobal, CatalogGroup
from kdp_catalog_manager.domain.service.catalog import CatalogController
from kdp_catalog_manager.exceptions.exception import KdpCatalogManagerError, \
FileNotExistsError, LangNotSupport
Expand Down Expand Up @@ -131,12 +131,10 @@ def read_catalog_category(
response_model=Catalogglobal,
summary="获取全局应用目录列表",
description="获取全局应用目录列表")
def read_catalog_global(
accept_language: Annotated[str, Header(description="请求语言类型")] = DEFAULT_LANG
):
def read_catalog_global():
"""获取全局catalog"""
try:
data = CatalogController(lang=accept_language).get_catalog_global()
data = CatalogController().get_catalog_global()
rtn = FormatReturn().format_return_json(
data, msg="get global catalogs data success")
except KdpCatalogManagerError as error:
Expand All @@ -147,4 +145,25 @@ def read_catalog_global(
)
rtn = FormatReturn().format_return_json(
{}, status=1, msg=error.error_cname, error_info=error_info)
return rtn
return rtn


@router.get("/catalogs/group/info",
response_model=CatalogGroup,
summary="获取应用目录分组信息",
description="获取应用目录分组信息")
def read_catalog_group():
"""获取全局catalog"""
try:
data = CatalogController().get_catalog_group()
rtn = FormatReturn().format_return_json(
data, msg="get catalog group data success")
except KdpCatalogManagerError as error:
error_info = FormatReturn().format_error_info(
error.error_name,
error.error_details,
error_msg=error.error_cname
)
rtn = FormatReturn().format_return_json(
{}, status=1, msg=error.error_cname, error_info=error_info)
return rtn
3 changes: 3 additions & 0 deletions kdp_catalog_manager/domain/format/format_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ def get_global(self):

def get_image(self):
return DictUtils().get_items(self.raw, ["image"], "")

def get_group(self):
return DictUtils().get_items(self.raw, ["group"], "BigDataComponent")
4 changes: 4 additions & 0 deletions kdp_catalog_manager/domain/model/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ class CatalogCategory(Response):

class Catalogglobal(Response):
data: List


class CatalogGroup(Response):
data: List
39 changes: 39 additions & 0 deletions kdp_catalog_manager/domain/service/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, catalog=None, lang=DEFAULT_LANG):
self.lang = lang

def get_catalogs_info(self):
"""get catalog info"""
catalogs_info = {}
catalogs_data = cache_instance.get(CATALOG_KEY)
if not isinstance(catalogs_data, dict):
Expand All @@ -37,6 +38,7 @@ def get_catalogs_info(self):
return catalogs_info

def get_catalogs(self):
"""get catalogs data"""
catalogs = []
catalogs_info = self.get_catalogs_info()
if not catalogs_info:
Expand All @@ -46,11 +48,13 @@ def get_catalogs(self):
return catalogs

def get_catalog(self):
"""get catalog data"""
catalogs_info = self.get_catalogs_info()
catalog_data = DictUtils().get_items(catalogs_info, [self.catalog], {})
return catalog_data

def get_catalog_readme(self):
"""get catalog readme"""
if self.catalog is None:
raise APIRequestedInvalidParamsError("catalog is None")
catalog_file = os.path.join(
Expand All @@ -63,6 +67,7 @@ def get_catalog_readme(self):
return FileUtils().read_file(catalog_file)

def get_catalog_category(self):
"""get catalog by category"""
catalog_info = {}
catalogs_data = cache_instance.get(CATALOG_KEY)
if not isinstance(catalogs_data, dict):
Expand Down Expand Up @@ -95,10 +100,44 @@ def get_catalog_category(self):
return catalog_categorys

def get_catalog_global(self):
"""get global catalog"""
catalog_global_list = []
catalogs_info = self.get_catalogs_info()
for catalog, catalog_info in catalogs_info.items():
global_catalog = catalog_info.get('global')
if global_catalog:
catalog_global_list.append(catalog)
return catalog_global_list

def get_catalog_group(self):
"""get catalog by broup"""
catalog_info = {}
catalogs_data = cache_instance.get(CATALOG_KEY)
if not isinstance(catalogs_data, dict):
raise DataTypeError(f"data type is {type(catalogs_data)}")
for catalog, catalog_metadata_info in catalogs_data.items():
catalog_format_obj = FormatCatalog(catalog_metadata_info)
catalog_metadata_name = catalog_format_obj.get_name()
catalog_group = catalog_format_obj.get_group()
catalog_image = catalog_format_obj.get_image()
if catalog_group not in catalog_info:
catalog_info[catalog_group] = [{
"name": catalog,
"metadataName": catalog_metadata_name,
"image": catalog_image
}]
continue
if catalog_group in catalog_info:
catalog_info[catalog_group].append({
"name": catalog,
"metadataName": catalog_metadata_name,
"image": catalog_image
})

catalog_group = []
for category, catalog_metadata_info in catalog_info.items():
catalog_group.append({
"group": category,
"sub": catalog_metadata_info
})
return catalog_group

0 comments on commit c87b225

Please sign in to comment.