You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
52 lines
1.3 KiB
from typing import Any, Optional
|
|
|
|
from fastapi.responses import JSONResponse
|
|
|
|
|
|
class Success(JSONResponse):
|
|
def __init__(
|
|
self,
|
|
code: int = 200,
|
|
msg: Optional[str] = "OK",
|
|
data: Optional[Any] = None,
|
|
**kwargs,
|
|
):
|
|
content = {"code": code, "msg": msg, "data": data}
|
|
content.update(kwargs)
|
|
super().__init__(content=content, status_code=code)
|
|
|
|
|
|
class Fail(JSONResponse):
|
|
def __init__(
|
|
self,
|
|
code: int = 400,
|
|
msg: Optional[str] = None,
|
|
data: Optional[Any] = None,
|
|
**kwargs,
|
|
):
|
|
content = {"code": code, "msg": msg, "data": data}
|
|
content.update(kwargs)
|
|
super().__init__(content=content, status_code=code)
|
|
|
|
|
|
class SuccessExtra(JSONResponse):
|
|
def __init__(
|
|
self,
|
|
code: int = 200,
|
|
msg: Optional[str] = None,
|
|
data: Optional[Any] = None,
|
|
total: int = 0,
|
|
page: int = 1,
|
|
page_size: int = 20,
|
|
**kwargs,
|
|
):
|
|
content = {
|
|
"code": code,
|
|
"msg": msg,
|
|
"data": data,
|
|
"total": total,
|
|
"page": page,
|
|
"page_size": page_size,
|
|
}
|
|
content.update(kwargs)
|
|
super().__init__(content=content, status_code=code)
|
|
|