diff --git a/app/api/routes/routes.py b/app/api/routes/routes.py index e94315c..e2273ce 100644 --- a/app/api/routes/routes.py +++ b/app/api/routes/routes.py @@ -45,7 +45,6 @@ def serve_paths(filename): swagger_dir = os.path.join("swagger") return send_from_directory(swagger_dir, filename) -# EligibilityCheck Endpoint @api.route("/panel/Login", methods=["POST"]) @jwt_required() def merms_login(): @@ -74,7 +73,7 @@ def merms_register_complete(): response = RegisterService.process_request(data) return response -@api.route("/panel/Account", methods=["POST"]) +@api.route("/panel/account", methods=["POST"]) @jwt_required() def merms_account(): data = request.get_json() @@ -88,21 +87,21 @@ def merms_account_bar(): response = AccountService.process_bar_request(data) return response -@api.route("/panel/Account/actions", methods=["POST"]) +@api.route("/panel/account-actions", methods=["POST"]) @jwt_required() def merms_account_actions(): data = request.get_json() response = AccountService.process_request(data) return response -@api.route("/panel/Account/products/url", methods=["POST"]) +@api.route("/panel/account-productsurl", methods=["POST"]) @jwt_required() def merms_account_product_url(): data = request.get_json() - response = AccountService.process_request(data) + response = ProductsService.process_request(data) return response -@api.route("/panel/Products", methods=["POST"]) +@api.route("/panel/products", methods=["POST"]) @jwt_required() def merms_products(): data = request.get_json() @@ -110,75 +109,75 @@ def merms_products(): return response -# EligibilityCheck Endpoint -@api.route("/EligibilityCheck", methods=["POST"]) -@jwt_required() -def eligibility_check(): - data = request.get_json() - # logger.info(f"EligibilityCheck request received: {data}") - response = EligibilityCheckService.process_request(data) - return response +# # EligibilityCheck Endpoint +# @api.route("/EligibilityCheck", methods=["POST"]) +# @jwt_required() +# def eligibility_check(): +# data = request.get_json() +# # logger.info(f"EligibilityCheck request received: {data}") +# response = EligibilityCheckService.process_request(data) +# return response +# - -# SelectOffer Endpoint -@api.route("/SelectOffer", methods=["POST"]) -@jwt_required() -def select_offer(): - data = request.get_json() - # logger.info(f"SelectOffer request received: {data}") - response = SelectOfferService.process_request(data) - return response - - -# ProvideLoan Endpoint -@api.route("/ProvideLoan", methods=["POST"]) -@jwt_required() -def provide_loan(): - data = request.get_json() - # logger.info(f"ProvideLoan request received: {data}") - response = ProvideLoanService.process_request(data) - return response - - -# LoanStatus Endpoint -@api.route("/LoanStatus", methods=["POST"]) -@jwt_required() -def loan_status(): - data = request.get_json() - # logger.info(f"LoanStatus request received: {data}") - response = LoanStatusService.process_request(data) - return response - - -# Repayment Endpoint -@api.route("/Repayment", methods=["POST"]) -@jwt_required() -def repayment(): - data = request.get_json() - logger.error(f"HERE 0000a **** ") - # logger.info(f"Repayment request received: {data}") - response = RepaymentService.process_request(data) - return response - - -# CustomerConsent Endpoint -@api.route("/CustomerConsent", methods=["POST"]) -@jwt_required() -def customer_consent(): - data = request.get_json() - # logger.info(f"CustomerConsent request received: {data}") - response = CustomerConsentService.process_request(data) - return response - - -# NotificationCallback Endpoint -@api.route("/NotificationCallback", methods=["POST"]) -@jwt_required() -def notification_callback(): - data = request.get_json() - # logger.info(f"NotificationCallback request received: {data}") - response = NotificationCallbackService.process_request(data) - return response +# # SelectOffer Endpoint +# @api.route("/SelectOffer", methods=["POST"]) +# @jwt_required() +# def select_offer(): +# data = request.get_json() +# # logger.info(f"SelectOffer request received: {data}") +# response = SelectOfferService.process_request(data) +# return response +# +# +# # ProvideLoan Endpoint +# @api.route("/ProvideLoan", methods=["POST"]) +# @jwt_required() +# def provide_loan(): +# data = request.get_json() +# # logger.info(f"ProvideLoan request received: {data}") +# response = ProvideLoanService.process_request(data) +# return response +# +# +# # LoanStatus Endpoint +# @api.route("/LoanStatus", methods=["POST"]) +# @jwt_required() +# def loan_status(): +# data = request.get_json() +# # logger.info(f"LoanStatus request received: {data}") +# response = LoanStatusService.process_request(data) +# return response +# +# +# # Repayment Endpoint +# @api.route("/Repayment", methods=["POST"]) +# @jwt_required() +# def repayment(): +# data = request.get_json() +# logger.error(f"HERE 0000a **** ") +# # logger.info(f"Repayment request received: {data}") +# response = RepaymentService.process_request(data) +# return response +# +# +# # CustomerConsent Endpoint +# @api.route("/CustomerConsent", methods=["POST"]) +# @jwt_required() +# def customer_consent(): +# data = request.get_json() +# # logger.info(f"CustomerConsent request received: {data}") +# response = CustomerConsentService.process_request(data) +# return response +# +# +# # NotificationCallback Endpoint +# @api.route("/NotificationCallback", methods=["POST"]) +# @jwt_required() +# def notification_callback(): +# data = request.get_json() +# # logger.info(f"NotificationCallback request received: {data}") +# response = NotificationCallbackService.process_request(data) +# return response # Health Check Endpoint diff --git a/app/api/services/authorization.py b/app/api/services/authorization.py index 4374b9f..7b64e60 100644 --- a/app/api/services/authorization.py +++ b/app/api/services/authorization.py @@ -12,6 +12,7 @@ from flask_jwt_extended import ( get_jwt_identity, ) from app.config import Config +from datetime import timedelta USERNAME = Config.BASIC_AUTH_USERNAME PASSWORD = Config.BASIC_AUTH_PASSWORD @@ -46,7 +47,8 @@ class AuthorizationService(BaseService): ): return ResponseHelper.unauthorized(result_description="Invalid credentials") - access_token = create_access_token(identity=validated_data["username"]) + expires = timedelta(days=3) + access_token = create_access_token(identity=validated_data["username"], expires_delta=expires) refresh_token = create_refresh_token(identity=validated_data["username"]) # Simulated processing logic diff --git a/app/api/services/products.py b/app/api/services/products.py index 386995a..7719207 100644 --- a/app/api/services/products.py +++ b/app/api/services/products.py @@ -13,6 +13,7 @@ from app.api.helpers.response_helper import ResponseHelper from werkzeug.security import generate_password_hash, check_password_hash from app.api.schemas.register import RegisterSchema from app.api.schemas.products import ProductsSchema +from app.api.schemas.user import UserSchema import datetime import jwt @@ -35,25 +36,29 @@ class ProductsService(BaseService): """ try: - user_id = 1 # current_user["user"]["id"] - PRODUCT_LIST = f"""SELECT p.id,p.uid,p.product_id,p.name,p.description,p.status,p.banner, - mp.status AS prov_status, - (CASE WHEN mp.status =6 THEN 'Preparing' WHEN mp.status=7 THEN 'Active' ELSE 'Activate Now' END) AS status_text - FROM products p - LEFT JOIN members_products mp ON mp.product_id = p.product_id - AND mp.member_id ={user_id} - ORDER BY p.id ASC""" - print(PRODUCT_LIST) + with db.session.begin(): - validated_data = ProductsService.validate_data(data, ProductsSchema()) - # username = validated_data.get('username') - # password = validated_data.get('password') + validated_data = ProductsService.validate_data(data, UserSchema()) + token = validated_data.get('token') + uid = validated_data.get('uid') + user_id = 1 # current_user["user"]["id"] + PRODUCT_LIST = f"""SELECT p.id,p.uid,p.product_id,p.name,p.description,p.status,p.banner, + mp.status AS prov_status, + (CASE WHEN mp.status =6 THEN 'Preparing' WHEN mp.status=7 THEN 'Active' ELSE 'Activate Now' END) AS status_text + FROM products p + LEFT JOIN members_products mp ON mp.product_id = p.product_id + AND mp.member_id ={user_id} + ORDER BY p.id ASC""" + print(PRODUCT_LIST) + + data = db.engine.execute(PRODUCT_LIST) # Simulate processing response_data = { + "data": data.fetchall(), "member_id": 0, "uid": 0, } diff --git a/app/swagger/merms_swagger.json b/app/swagger/merms_swagger.json index ba99beb..ccf1112 100644 --- a/app/swagger/merms_swagger.json +++ b/app/swagger/merms_swagger.json @@ -85,6 +85,9 @@ "/panel/Account": { "$ref": "swagger/paths/Account.json" }, + "/panel/account-bar": { + "$ref": "swagger/paths/AccountBar.json" + }, "/panel/Products": { "$ref": "swagger/paths/Products.json" } diff --git a/app/swagger/paths/AccountBar.json b/app/swagger/paths/AccountBar.json new file mode 100644 index 0000000..99116b7 --- /dev/null +++ b/app/swagger/paths/AccountBar.json @@ -0,0 +1,57 @@ +{ + "post": { + "tags": [ + "AccountBar" + ], + "summary": "User Account Bar ", + "description": "User Bar Request", + "operationId": "accountbar", + "requestBody": { + "description": "Post JSON to conduct login request", + "content": { + "application/json": { + "schema": { + "$ref": "../schemas/UserRequest.json" + } + }, + "application/xml": { + "schema": { + "$ref": "../schemas/UserRequest.json" + } + }, + "application/x-www-form-urlencoded": { + "schema": { + "$ref": "../schemas/UserRequest.json" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/json": { + "schema": { + "$ref": "../schemas/AccountBarResponse.json" + } + }, + "application/xml": { + "schema": { + "$ref": "../schemas/AccountBarResponse.json" + } + } + } + }, + "400": { + "description": "Invalid request" + }, + "422": { + "description": "Validation exception" + }, + "500": { + "description": "Internal server error" + } + } + } +} \ No newline at end of file diff --git a/app/swagger/schemas/AccountBarResponse.json b/app/swagger/schemas/AccountBarResponse.json new file mode 100644 index 0000000..791ff59 --- /dev/null +++ b/app/swagger/schemas/AccountBarResponse.json @@ -0,0 +1,49 @@ +{ + "type": "object", + "properties": { + "member_id": { + "type": "string", + "example": "200" + }, + "uid": { + "type": "string", + "example": "8888-999998-9999" + }, + "username": { + "type": "string", + "example": "username" + }, + "account_name": { + "type": "string", + "example": "account_name" + }, + "firstname": { + "type": "string", + "example": "firstname" + }, + "lastname": { + "type": "string", + "example": "lastname" + }, + "room": { + "type": "string", + "example": "room" + }, + "token": { + "type": "string", + "example": "username" + }, + "resultDescription": { + "type": "string", + "example": "Successful" + }, + "resultCode": { + "type": "string", + "example": "00" + } + }, + "xml": { + "name": "AccountResponse" + } +} + diff --git a/docker-compose.yml b/docker-compose.yml index 9602da4..7689cc1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: env_file: - .env ports: - - "${APP_PORT:-14703}:5000" + - "${APP_PORT:-14700}:5000" environment: - FLASK_APP=${FLASK_APP} - FLASK_ENV=${FLASK_ENV}