Files
FastapiAdmin/backend/app/core/base_params.py
T
zhangtao e32bc0660e refactor(字段命名): 统一将created_at和updated_at重命名为created_time和updated_time
重构字段命名以保持一致性,将时间相关字段从created_at/updated_at统一改为created_time/updated_time
同时调整相关查询参数、服务层映射和模板文件中的字段命名
优化权限过滤逻辑,提取为独立的Permission类
2025-11-24 01:53:01 +08:00

43 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
from typing import Optional
from fastapi import Query
class PaginationQueryParam:
"""分页查询参数基类"""
def __init__(
self,
page_no: Optional[int] = Query(default=None, description="当前页码", ge=1),
page_size: Optional[int] = Query(default=None, description="每页数量", ge=1, le=100),
order_by: Optional[str] = Query(default=None, description="排序字段,格式:field1,asc;field2,desc"),
) -> None:
"""
初始化分页查询参数。
参数:
- page_no (int | None): 当前页码,默认 None。
- page_size (int | None): 每页数量,默认 None,最大 100。
- order_by (str | None): 排序字段,格式 'field,asc;field2,desc'。
返回:
- None
"""
self.page_no = page_no
self.page_size = page_size
# 将字符串格式的order_by转换为服务层需要的List[Dict[str, str]]格式
if order_by:
try:
self.order_by = []
for item in order_by.split(';'):
if item.strip():
field, direction = item.split(',', 1)
self.order_by.append({field.strip(): direction.strip().lower()})
except ValueError:
# 如果解析失败,使用默认排序
self.order_by = [{'updated_time': 'desc'}]
else:
self.order_by = [{'updated_time': 'desc'}]