Commit bca40558 authored by deepdey's avatar deepdey

feat: add api to sync web-api with redis

parent 176c2cc3
...@@ -9,3 +9,10 @@ class RoleTypeEnum(Enum): ...@@ -9,3 +9,10 @@ class RoleTypeEnum(Enum):
PROJECT_ADMIN = 'PROJECT_ADMIN' PROJECT_ADMIN = 'PROJECT_ADMIN'
PROJECT_STAFF = 'PROJECT_STAFF' PROJECT_STAFF = 'PROJECT_STAFF'
PROJECT_USER = 'PROJECT_USER' PROJECT_USER = 'PROJECT_USER'
class EndpointTagEnum(Enum):
P = 'P'
V = 'V'
SU = 'SU'
PV = 'PV'
RA = 'RA'
\ No newline at end of file
...@@ -106,3 +106,21 @@ class GetWebApi(Resource): ...@@ -106,3 +106,21 @@ class GetWebApi(Resource):
except Exception as e: except Exception as e:
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
return prepare_api_response(EXCEPTION_CODE, str(e)) 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 orm as ORM
from app import db 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: def get_web_api_by_endpoint(endpoint: str) -> ORM.Api | None:
return ORM.Api.query.filter_by(endpoint=endpoint).first() return ORM.Api.query.filter_by(endpoint=endpoint).first()
...@@ -63,3 +65,13 @@ def update_web_api(web_api_info: dict) -> bool: ...@@ -63,3 +65,13 @@ def update_web_api(web_api_info: dict) -> bool:
def get_web_api_list() -> list: def get_web_api_list() -> list:
web_api_list = ORM.Api.query.all() web_api_list = ORM.Api.query.all()
return web_api_list 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
...@@ -45,3 +45,12 @@ def get_web_api_list_response() -> any: ...@@ -45,3 +45,12 @@ def get_web_api_list_response() -> any:
model_name='getWebApiList Response', model_name='getWebApiList Response',
data=fields.List(fields.Nested(WEB_API_MODE)) 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