Skip to content

Commit

Permalink
2024年12月09日 继续完善定制页面接口
Browse files Browse the repository at this point in the history
  • Loading branch information
ss1917 committed Dec 9, 2024
1 parent dca579c commit 5d2fb7a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
35 changes: 32 additions & 3 deletions mg/handlers/sys_index_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from abc import ABC
from libs.base_handler import BaseHandler
from services.index_service import get_step_list, up_step, add_step, del_step, get_service_dict, get_service_list,\
add_service, up_service, del_service
add_service, up_service, del_service, opt_server_list_obj, get_service_categories


class IndexStepHandler(BaseHandler, ABC):
Expand All @@ -35,6 +35,27 @@ def delete(self, *args, **kwargs):
self.write(res)


class ServiceCategoriesHandler(BaseHandler, ABC):
def get(self, *args, **kwargs):
res = get_service_categories()
return self.write(res)

def post(self, *args, **kwargs):
data = json.loads(self.request.body.decode("utf-8"))
res = opt_server_list_obj.handle_add(data)
self.write(res)

def put(self, *args, **kwargs):
data = json.loads(self.request.body.decode("utf-8"))
res = opt_server_list_obj.handle_update(data)
self.write(res)

def delete(self, *args, **kwargs):
data = json.loads(self.request.body.decode("utf-8"))
res = opt_server_list_obj.handle_delete(data)
self.write(res)


class IndexServiceHandler(BaseHandler, ABC):
def get(self, *args, **kwargs):
res = get_service_list()
Expand Down Expand Up @@ -62,6 +83,12 @@ def get(self, *args, **kwargs):
return self.write(res)


class ServiceCategories(BaseHandler, ABC):
def get(self, *args, **kwargs):
res = get_service_categories()
return self.write(res)


class IndexService(BaseHandler, ABC):
def get(self, *args, **kwargs):
res = get_service_dict()
Expand All @@ -70,9 +97,11 @@ def get(self, *args, **kwargs):

index_step_urls = [
(r"/v4/ops-step-service/", IndexStepHandler, {"handle_name": "PAAS-基础功能-首页步骤管理", "method": ["ALL"]}),
(r"/v4/ops-service-categories/", ServiceCategoriesHandler, {"handle_name": "PAAS-基础功能-首页服务列表", "method": ["ALL"]}),
(r"/v4/ops-index-service/", IndexServiceHandler, {"handle_name": "PAAS-基础功能-首页服务管理", "method": ["ALL"]}),
(r"/v4/na/index-step/", IndexStep, {"handle_name": "PAAS-基础功能-首页步骤", "method": ["GET"]}),
(r"/v4/na/index-service/", IndexService, {"handle_name": "PAAS-基础功能-首页服务", "method": ["GET"]})
(r"/v4/na/index-step/", IndexStep, {"handle_name": "PAAS-基础功能-首页步骤", "method": ["GET"]}), # 免认证
(r"/v4/na/index-service-categories/", ServiceCategories, {"handle_name": "PAAS-基础功能-首页服务定制表", "method": ["GET"]}),
(r"/v4/na/index-service/", IndexService, {"handle_name": "PAAS-基础功能-首页服务", "method": ["GET"]}) # 免认证
]

if __name__ == "__main__":
Expand Down
9 changes: 9 additions & 0 deletions models/paas_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ class IndexStepModel(TimeBaseModel, Base):
faqs = Column(JSON, nullable=True) # FAQ 列表,存储为 JSON


class ServiceCategoriesModel(TimeBaseModel, Base):
__tablename__ = 'codo_index_service_list'

id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(100), nullable=False, index=True) # 分类名称
img = Column(String(100), nullable=False) # 图标名称对应前端保存的图片
description = Column(String(255), nullable=True) # 描述


class IndexServiceModel(TimeBaseModel, Base):
__tablename__ = 'codo_index_service'

Expand Down
18 changes: 14 additions & 4 deletions services/index_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
from sqlalchemy import or_
from websdk2.sqlalchemy_pagination import paginate
from websdk2.db_context import DBContextV2 as DBContext
from websdk2.model_utils import queryset_to_list

from websdk2.model_utils import queryset_to_list, CommonOptView
from libs.feature_pydantic_utils import sqlalchemy_to_pydantic, ValidationError, PydanticDel
from models.paas_model import IndexStepModel, IndexServiceModel
from models.paas_model import IndexStepModel, ServiceCategoriesModel, IndexServiceModel

PydanticFavorites = sqlalchemy_to_pydantic(IndexStepModel, exclude=['id']) # 排除自增ID
PydanticFavoritesUP = sqlalchemy_to_pydantic(IndexStepModel)

opt_server_list_obj = CommonOptView(ServiceCategoriesModel)


def get_step_list() -> dict:
with DBContext('r') as session:
Expand Down Expand Up @@ -140,7 +141,7 @@ def get_service_list(**params) -> dict:

# 分页查询
page = paginate(query, **params)
return dict(code=0, msg="创建成功", data=page.items, count=page.total)
return dict(code=0, msg="查询成功", data=page.items, count=page.total)


def add_service(data: dict):
Expand Down Expand Up @@ -183,3 +184,12 @@ def del_service(data: dict) -> dict:
return dict(code=-3, msg=f'删除失败, {str(err)}')

return dict(code=0, msg="删除成功")


def get_service_categories(**params) -> dict:
params.setdefault('page_size', 300)
with DBContext('r') as session:
query = session.query(ServiceCategoriesModel)
# 分页查询
page = paginate(query, **params)
return dict(code=0, msg="查询成功", data=page.items, count=page.total)

0 comments on commit 5d2fb7a

Please sign in to comment.