refactor: 优化API路由和响应模型 feat(admin): 添加App用户管理接口 feat(sms): 实现阿里云短信服务集成 feat(email): 添加SMTP邮件发送功能 feat(upload): 支持文件上传接口 feat(rate-limiter): 实现手机号限流器 fix: 修复计算步骤入库问题 docs: 更新API文档和测试计划 chore: 更新依赖和配置
70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
from fastapi import APIRouter, Query
|
|
from tortoise.expressions import Q
|
|
|
|
from app.controllers.api import api_controller
|
|
from app.schemas import Success, SuccessExtra
|
|
from app.schemas.base import BasicResponse, PageResponse, MessageOut
|
|
from app.schemas.apis import BaseApi
|
|
from app.schemas.apis import *
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/list", summary="查看API列表", response_model=PageResponse[BaseApi])
|
|
async def list_api(
|
|
page: int = Query(1, description="页码"),
|
|
page_size: int = Query(10, description="每页数量"),
|
|
path: str = Query(None, description="API路径"),
|
|
summary: str = Query(None, description="API简介"),
|
|
tags: str = Query(None, description="API模块"),
|
|
):
|
|
q = Q()
|
|
if path:
|
|
q &= Q(path__contains=path)
|
|
if summary:
|
|
q &= Q(summary__contains=summary)
|
|
if tags:
|
|
q &= Q(tags__contains=tags)
|
|
total, api_objs = await api_controller.list(page=page, page_size=page_size, search=q, order=["tags", "id"])
|
|
data = [await obj.to_dict() for obj in api_objs]
|
|
return SuccessExtra(data=data, total=total, page=page, page_size=page_size)
|
|
|
|
|
|
@router.get("/get", summary="查看Api", response_model=BasicResponse[BaseApi])
|
|
async def get_api(
|
|
id: int = Query(..., description="Api"),
|
|
):
|
|
api_obj = await api_controller.get(id=id)
|
|
data = await api_obj.to_dict()
|
|
return Success(data=data)
|
|
|
|
|
|
@router.post("/create", summary="创建Api", response_model=BasicResponse[MessageOut])
|
|
async def create_api(
|
|
api_in: ApiCreate,
|
|
):
|
|
await api_controller.create(obj_in=api_in)
|
|
return Success(msg="Created Successfully")
|
|
|
|
|
|
@router.post("/update", summary="更新Api", response_model=BasicResponse[MessageOut])
|
|
async def update_api(
|
|
api_in: ApiUpdate,
|
|
):
|
|
await api_controller.update(id=api_in.id, obj_in=api_in)
|
|
return Success(msg="Update Successfully")
|
|
|
|
|
|
@router.delete("/delete", summary="删除Api", response_model=BasicResponse[MessageOut])
|
|
async def delete_api(
|
|
api_id: int = Query(..., description="ApiID"),
|
|
):
|
|
await api_controller.remove(id=api_id)
|
|
return Success(msg="Deleted Success")
|
|
|
|
|
|
@router.post("/refresh", summary="刷新API列表", response_model=BasicResponse[MessageOut])
|
|
async def refresh_api():
|
|
await api_controller.refresh_api()
|
|
return Success(msg="OK")
|