mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 13:05:18 +00:00
style: 统一代码风格和格式 docs: 完善函数和方法的文档字符串 refactor(base_model): 移除冗余的表名和表参数生成方法 refactor(constant): 更新返回码注释格式 refactor(router_class): 添加路由处理器的详细文档 refactor(database): 完善数据库连接函数的文档 refactor(security): 添加认证类和方法的详细文档 refactor(validator): 更新验证器函数的文档格式 refactor(serialize): 优化序列化工具类的文档 refactor(response): 完善响应类的文档字符串 refactor(dependencies): 添加依赖函数的详细文档 refactor(initialize): 完善初始化脚本的文档 refactor(plugin): 添加生命周期和中间件注册的文档 refactor(service): 完善服务层方法的文档 refactor(controller): 添加控制器方法的详细文档 refactor(crud): 完善CRUD操作的文档字符串 refactor(schema): 简化模型类并移除冗余字段 refactor(param): 更新查询参数类的注释格式 refactor(template): 优化代码生成模板的格式 refactor(console): 添加控制台输出功能的实现 refactor(util): 完善工具函数的文档字符串
141 lines
5.0 KiB
Python
141 lines
5.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from fastapi import APIRouter, Body, Depends, Path
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from app.common.response import SuccessResponse
|
|
from app.common.request import PaginationService
|
|
from app.core.base_params import PaginationQueryParam
|
|
from app.core.dependencies import AuthPermission
|
|
from app.core.router_class import OperationLogRoute
|
|
from app.core.base_schema import BatchSetAvailable
|
|
from app.core.logger import logger
|
|
from app.api.v1.module_system.auth.schema import AuthSchema
|
|
from .param import ApplicationQueryParam
|
|
from .service import ApplicationService
|
|
from .schema import (
|
|
ApplicationCreateSchema,
|
|
ApplicationUpdateSchema
|
|
)
|
|
|
|
|
|
MyAppRouter = APIRouter(route_class=OperationLogRoute, prefix="/myapp", tags=["应用管理"])
|
|
|
|
@MyAppRouter.get("/detail/{id}", summary="获取应用详情", description="获取应用详情")
|
|
async def get_obj_detail_controller(
|
|
id: int = Path(..., description="应用ID"),
|
|
auth: AuthSchema = Depends(AuthPermission(["app:myapp:query"]))
|
|
) -> JSONResponse:
|
|
"""
|
|
获取应用详情
|
|
|
|
参数:
|
|
- id (int): 应用ID
|
|
- auth (AuthSchema): 认证信息模型
|
|
|
|
返回:
|
|
- JSONResponse: 包含应用详情的JSON响应
|
|
"""
|
|
result_dict = await ApplicationService.detail_service(id=id, auth=auth)
|
|
logger.info(f"获取应用详情成功 {id}")
|
|
return SuccessResponse(data=result_dict, msg="获取应用详情成功")
|
|
|
|
@MyAppRouter.get("/list", summary="查询应用列表", description="查询应用列表")
|
|
async def get_obj_list_controller(
|
|
page: PaginationQueryParam = Depends(),
|
|
search: ApplicationQueryParam = Depends(),
|
|
auth: AuthSchema = Depends(AuthPermission(["app:myapp:query"]))
|
|
) -> JSONResponse:
|
|
"""
|
|
查询应用列表
|
|
|
|
参数:
|
|
- page (PaginationQueryParam): 分页参数模型
|
|
- search (ApplicationQueryParam): 查询参数模型
|
|
- auth (AuthSchema): 认证信息模型
|
|
|
|
返回:
|
|
- JSONResponse: 包含应用列表的JSON响应
|
|
"""
|
|
result_dict_list = await ApplicationService.list_service(auth=auth, search=search, order_by=page.order_by)
|
|
result_dict = await PaginationService.paginate(data_list=result_dict_list, page_no=page.page_no, page_size=page.page_size)
|
|
logger.info(f"查询应用列表成功")
|
|
return SuccessResponse(data=result_dict, msg="查询应用列表成功")
|
|
|
|
@MyAppRouter.post("/create", summary="创建应用", description="创建应用")
|
|
async def create_obj_controller(
|
|
data: ApplicationCreateSchema,
|
|
auth: AuthSchema = Depends(AuthPermission(["app:myapp:create"]))
|
|
) -> JSONResponse:
|
|
"""
|
|
创建应用
|
|
|
|
参数:
|
|
- data (ApplicationCreateSchema): 应用创建模型
|
|
- auth (AuthSchema): 认证信息模型
|
|
|
|
返回:
|
|
- JSONResponse: 包含创建应用详情的JSON响应
|
|
"""
|
|
result_dict = await ApplicationService.create_service(auth=auth, data=data)
|
|
logger.info(f"创建应用成功: {result_dict}")
|
|
return SuccessResponse(data=result_dict, msg="创建应用成功")
|
|
|
|
@MyAppRouter.put("/update/{id}", summary="修改应用", description="修改应用")
|
|
async def update_obj_controller(
|
|
data: ApplicationUpdateSchema,
|
|
id: int = Path(..., description="应用ID"),
|
|
auth: AuthSchema = Depends(AuthPermission(["app:myapp:update"]))
|
|
) -> JSONResponse:
|
|
"""
|
|
修改应用
|
|
|
|
参数:
|
|
- data (ApplicationUpdateSchema): 应用更新模型
|
|
- id (int): 应用ID
|
|
- auth (AuthSchema): 认证信息模型
|
|
|
|
返回:
|
|
- JSONResponse: 包含修改应用详情的JSON响应
|
|
"""
|
|
result_dict = await ApplicationService.update_service(auth=auth, id=id, data=data)
|
|
logger.info(f"修改应用成功: {result_dict}")
|
|
return SuccessResponse(data=result_dict, msg="修改应用成功")
|
|
|
|
@MyAppRouter.delete("/delete", summary="删除应用", description="删除应用")
|
|
async def delete_obj_controller(
|
|
ids: list[int] = Body(..., description="ID列表"),
|
|
auth: AuthSchema = Depends(AuthPermission(["app:myapp:delete"]))
|
|
) -> JSONResponse:
|
|
"""
|
|
删除应用
|
|
|
|
参数:
|
|
- ids (list[int]): 应用ID列表
|
|
- auth (AuthSchema): 认证信息模型
|
|
|
|
返回:
|
|
- JSONResponse: 包含删除应用详情的JSON响应
|
|
"""
|
|
await ApplicationService.delete_service(auth=auth, ids=ids)
|
|
logger.info(f"删除应用成功: {ids}")
|
|
return SuccessResponse(msg="删除应用成功")
|
|
|
|
@MyAppRouter.patch("/available/setting", summary="批量修改应用状态", description="批量修改应用状态")
|
|
async def batch_set_available_obj_controller(
|
|
data: BatchSetAvailable,
|
|
auth: AuthSchema = Depends(AuthPermission(["app:myapp:patch"]))
|
|
) -> JSONResponse:
|
|
"""
|
|
批量修改应用状态
|
|
|
|
参数:
|
|
- data (BatchSetAvailable): 批量修改应用状态模型
|
|
- auth (AuthSchema): 认证信息模型
|
|
|
|
返回:
|
|
- JSONResponse: 批量修改应用状态成功
|
|
"""
|
|
await ApplicationService.set_available_service(auth=auth, data=data)
|
|
logger.info(f"批量修改应用状态成功: {data.ids}")
|
|
return SuccessResponse(msg="批量修改应用状态成功") |