Squashed 'utils_v2/' changes from ef9630d..271426c

271426c (20241010) Can now cache class methods by accessing a caching object from the class itself!
606b02a Merge commit 'b0e0760fc7bb6336debf621860d1286575a0b8cc'
3d2a723 (20241009) Work in progress.
58266e3 (20241009) 'last decorator' bug-fixed
53e7a39 (20241009) Work in progress.
dbfc17f (20241009) 'last decorator' bug-fixed
11875e6 (20241008) logging decorator and model improved.

git-subtree-dir: utils_v2
git-subtree-split: 271426c19bea8de5edec7ecb79ee04368c47b02f
This commit is contained in:
2024-10-10 11:44:01 +05:30
parent 8494a2c0c0
commit 0450b2a445
17 changed files with 218 additions and 257 deletions
+12
View File
@@ -30,9 +30,11 @@
# *****************************************************************************************************************
# For data-modelling:
from pydantic import BaseModel
from typing import Any, Optional, List
# My utils:
from utils_v2.api.codes import StatusCodes, HttpCodes
@@ -64,6 +66,11 @@ from utils_v2.api.codes import StatusCodes, HttpCodes
class ResponseModel(BaseModel):
"""
A model for how the response should be when developing API endpoints.
"""
# The fields that you want in your response:
status_code: StatusCodes
message: Optional[str | List] = None
data: Optional[Any] = None
@@ -74,6 +81,11 @@ class ResponseModel(BaseModel):
def for_quart(self):
"""
Call this when you are using either Flask or Quart as your framework.
:return: The output as expected by Flask and Quart.
"""
# Construct the basic structure:
response_dict = {
"status": 1 if self.status_code.value[0] else 0,