mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-05-11 09:59:50 +08:00
Initial commit
This commit is contained in:
16
api/response.py
Normal file
16
api/response.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
|
||||
def success(data: Any = None, msg: str = "ok", code: int = 0):
|
||||
"""标准成功响应包装。"""
|
||||
return {"code": code, "msg": msg, "data": data}
|
||||
|
||||
|
||||
def page(items: list[Any], total: int, page: int, page_size: int):
|
||||
"""统一分页数据结构。"""
|
||||
pages = (total + page_size - 1) // page_size if page_size else 0
|
||||
return {"items": items, "total": total, "page": page, "page_size": page_size, "pages": pages}
|
||||
|
||||
|
||||
def error(msg: str, code: int = 1, data: Optional[Any] = None):
|
||||
return {"code": code, "msg": msg, "data": data}
|
||||
Reference in New Issue
Block a user