Commit c491f760 authored by deepdey's avatar deepdey

chore: update response config

parent 8ddf56d5
SUCCESS_CODE: int = 200 SUCCESS_CODE: int = 201
VALIDATION_ERROR_CODE: int = 403 VALIDATION_ERROR_CODE: int = 400
EXCEPTION_CODE: int = 500 EXCEPTION_CODE: int = 500
UN_AUTHORIZED_CODE: int = 401 UN_AUTHORIZED_CODE: int = 401
\ No newline at end of file
...@@ -55,8 +55,6 @@ class Login(Resource): ...@@ -55,8 +55,6 @@ class Login(Resource):
if not bcrypt.check_password_hash(user_info.password, password): if not bcrypt.check_password_hash(user_info.password, password):
return prepare_api_response(401, 'Invalid password') return prepare_api_response(401, 'Invalid password')
# fetch user role info
api_key = self.generate_api_key() api_key = self.generate_api_key()
process_valid_loging(user_info, api_key) process_valid_loging(user_info, api_key)
......
...@@ -9,7 +9,7 @@ def prepare_swagger_response( ...@@ -9,7 +9,7 @@ def prepare_swagger_response(
data: any = None data: any = None
) -> dict: ) -> dict:
response: dict = { response: dict = {
'code': fields.Integer(default=code), 'status_code': fields.Integer(default=code),
'message': fields.String(default=message) 'message': fields.String(default=message)
} }
...@@ -27,7 +27,7 @@ def prepare_api_response( ...@@ -27,7 +27,7 @@ def prepare_api_response(
) -> dict: ) -> dict:
response: dict = { response: dict = {
'code': int(code), 'status_code': int(code),
'message': str(message) 'message': str(message)
} }
...@@ -35,6 +35,6 @@ def prepare_api_response( ...@@ -35,6 +35,6 @@ def prepare_api_response(
response['data'] = data response['data'] = data
if (error is not None): if (error is not None):
response['error'] = error response['errors'] = error
return response, code return response, code
from typing import Optional
import redis import redis
from app.app_config.config import REDIS_HOST, REDIS_PORT, REDIS_DATABASE from app.app_config.config import REDIS_HOST, REDIS_PORT, REDIS_DATABASE
...@@ -21,10 +22,13 @@ def get_value(key: str) -> str | None: ...@@ -21,10 +22,13 @@ def get_value(key: str) -> str | None:
return None return None
def set_value(key: str,value: str) -> bool: def set_value(key: str,value: str, expire_time: Optional[int] = None) -> bool:
try: try:
client = get_client(REDIS_HOST, REDIS_PORT, None) client = get_client(REDIS_HOST, REDIS_PORT, None)
client.set(key, value) if expire_time:
client.set(key, value, ex=expire_time)
else:
client.set(key, value)
return True return True
except Exception as e: except Exception as e:
print(e) print(e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment