Commit bca40558 authored by deepdey's avatar deepdey

feat: add api to sync web-api with redis

parent 176c2cc3
......@@ -8,4 +8,11 @@ class RoleTypeEnum(Enum):
SUPER_ADMIN = 'SUPER_ADMIN'
PROJECT_ADMIN = 'PROJECT_ADMIN'
PROJECT_STAFF = 'PROJECT_STAFF'
PROJECT_USER = 'PROJECT_USER'
\ No newline at end of file
PROJECT_USER = 'PROJECT_USER'
class EndpointTagEnum(Enum):
P = 'P'
V = 'V'
SU = 'SU'
PV = 'PV'
RA = 'RA'
\ No newline at end of file
......@@ -103,6 +103,24 @@ class GetWebApi(Resource):
data=[web_api.to_dict() for web_api in web_api_list]
)
except Exception as e:
logger.error(traceback.format_exc())
return prepare_api_response(EXCEPTION_CODE, str(e))
@ns.route('/sync-redis', methods=['GET'])
class SyncRedisWebApi(Resource):
@ns.doc(security=SECURITY)
@ns.response(*sync_web_api_response())
@sanitized()
def get(self):
try:
synced: bool = sync_web_api()
return prepare_api_response(SUCCESS_CODE, SUCCESS_MESSAGE)
except Exception as e:
logger.error(traceback.format_exc())
return prepare_api_response(EXCEPTION_CODE, str(e))
\ No newline at end of file
from app import orm as ORM
from app import db
from app.app_config.constant import EndpointTagEnum
from app.utils import redis
def get_web_api_by_endpoint(endpoint: str) -> ORM.Api | None:
return ORM.Api.query.filter_by(endpoint=endpoint).first()
......@@ -62,4 +64,14 @@ def update_web_api(web_api_info: dict) -> bool:
def get_web_api_list() -> list:
web_api_list = ORM.Api.query.all()
return web_api_list
\ No newline at end of file
return web_api_list
def sync_web_api() -> bool:
web_api_list = ORM.Api.query.all()
for web_api in web_api_list:
if web_api.tag == EndpointTagEnum.RA.value:
redis.set_value(web_api.endpoint, web_api.id)
else:
redis.set_value(web_api.endpoint, web_api.tag)
return True
\ No newline at end of file
......@@ -44,4 +44,13 @@ def get_web_api_list_response() -> any:
message=GET_SUCCESS_MESSAGE,
model_name='getWebApiList Response',
data=fields.List(fields.Nested(WEB_API_MODE))
)
def sync_web_api_response() -> any:
return prepare_swagger_response(
code=SUCCESS_CODE,
message=SUCCESS_MESSAGE,
model_name='syncWebApi Response'
)
\ No newline at end of file
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