Initial FastAPI admin auth scaffold
This commit is contained in:
1
app/lib/response/__init__.py
Normal file
1
app/lib/response/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Response helpers."""
|
||||
6
app/lib/response/admin_return.py
Normal file
6
app/lib/response/admin_return.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from app.lib.response.common_return import CommonReturn
|
||||
|
||||
|
||||
class AdminReturn(CommonReturn):
|
||||
def after_success(self, response: dict) -> dict:
|
||||
return response
|
||||
34
app/lib/response/common_return.py
Normal file
34
app/lib/response/common_return.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from app.constants.result_code import ResultCode
|
||||
|
||||
|
||||
class CommonReturn:
|
||||
def success(
|
||||
self,
|
||||
message: str = "success",
|
||||
data: dict | list | None = None,
|
||||
code: int | ResultCode = ResultCode.SUCCESS,
|
||||
) -> dict:
|
||||
return self.after_success(
|
||||
{
|
||||
"code": int(code),
|
||||
"message": message,
|
||||
"data": data if data is not None else {},
|
||||
}
|
||||
)
|
||||
|
||||
def error(
|
||||
self,
|
||||
message: str = "failed",
|
||||
code: int | ResultCode = ResultCode.ERROR,
|
||||
data: dict | None = None,
|
||||
) -> dict:
|
||||
return self.after_success(
|
||||
{
|
||||
"code": int(code),
|
||||
"message": message,
|
||||
"data": data or {},
|
||||
}
|
||||
)
|
||||
|
||||
def after_success(self, response: dict) -> dict:
|
||||
raise NotImplementedError
|
||||
Reference in New Issue
Block a user