mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 12:52:26 +00:00
- 将分页服务中方法名由get_page_obj统一替换为paginate - 注意相关controller均调整调用方式,保证统一接口调用 - 代码生成模块数据库模型统一替换为GenTableModel和GenTableColumnModel - 更改数据库类型及分页相关配置为settings.DATABASE_TYPE统一管理 - 重构代码生成模块查询参数,新增GenTableQueryParam和GenTableColumnQueryParam类支持更灵活查询 - 数据模型中Pydantic Schema类型统一调整为Schema后缀 - 优化异常处理,增加请求参数验证错误的友好提示映射 - 调整中间件及依赖以支持更严格的类型检查及更健壮的用户权限认证逻辑 - 微调日志打印格式,改进请求日志信息输出风格
65 lines
2.4 KiB
Python
65 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
from fastapi import Query
|
|
|
|
from app.core.validator import DateTimeStr
|
|
from app.common.request import PageResultSchema
|
|
from .schema import GenTableBaseSchema, GenTableColumnBaseSchema
|
|
|
|
|
|
class GenTableQueryParam(PageResultSchema, GenTableBaseSchema):
|
|
"""数据库表查询参数"""
|
|
|
|
def __init__(
|
|
self,
|
|
name: Optional[str] = Query(None, description="名称"),
|
|
status: Optional[bool] = Query(None, description="是否启用"),
|
|
creator: Optional[int] = Query(None, description="创建人"),
|
|
start_time: Optional[DateTimeStr] = Query(None, description="开始时间", example="2023-01-01 00:00:00"),
|
|
end_time: Optional[DateTimeStr] = Query(None, description="结束时间", example="2023-12-31 23:59:59"),
|
|
) -> None:
|
|
super().__init__()
|
|
|
|
# 模糊查询字段
|
|
self.name = ("like", name)
|
|
|
|
# 精确查询字段
|
|
self.creator_id = creator
|
|
self.status = status
|
|
|
|
# 时间范围查询
|
|
if start_time and end_time:
|
|
start_datetime = datetime.strptime(str(start_time), '%Y-%m-%d %H:%M:%S')
|
|
end_datetime = datetime.strptime(str(end_time), '%Y-%m-%d %H:%M:%S')
|
|
self.created_at = ("between", (start_datetime, end_datetime))
|
|
|
|
|
|
class GenTableColumnQueryParam(PageResultSchema, GenTableColumnBaseSchema):
|
|
"""数据库表字段查询参数"""
|
|
|
|
def __init__(
|
|
self,
|
|
name: Optional[str] = Query(None, description="名称"),
|
|
status: Optional[bool] = Query(None, description="是否启用"),
|
|
creator: Optional[int] = Query(None, description="创建人"),
|
|
start_time: Optional[DateTimeStr] = Query(None, description="开始时间", example="2023-01-01 00:00:00"),
|
|
end_time: Optional[DateTimeStr] = Query(None, description="结束时间", example="2023-12-31 23:59:59"),
|
|
) -> None:
|
|
super().__init__()
|
|
|
|
# 模糊查询字段
|
|
self.name = ("like", name)
|
|
|
|
# 精确查询字段
|
|
self.creator_id = creator
|
|
self.status = status
|
|
|
|
# 时间范围查询
|
|
if start_time and end_time:
|
|
start_datetime = datetime.strptime(str(start_time), '%Y-%m-%d %H:%M:%S')
|
|
end_datetime = datetime.strptime(str(end_time), '%Y-%m-%d %H:%M:%S')
|
|
self.created_at = ("between", (start_datetime, end_datetime))
|
|
|