diff --git a/app/api/routes/routes.py b/app/api/routes/routes.py index 9bb5981..be6fd48 100644 --- a/app/api/routes/routes.py +++ b/app/api/routes/routes.py @@ -13,6 +13,7 @@ from app.api.services import ( NotificationCallbackService, AuthorizationService, MyProductsService, + ContactService, ) from app.utils.logger import logger from app.api.middlewares import enforce_json, require_auth @@ -116,6 +117,14 @@ def myproduct_url(): response = ProductsService.product_url_request(data) return response +# +@api.route("/panel/contacts", methods=["POST"]) +def merms_contacts(): + data = request.get_json() + logger.info(f"Route ContactService URL Data ==>>>> {data}") + response = ContactService.process_request(data) + return response + @api.route("/panel/account/products", methods=["POST"]) diff --git a/app/api/services/__init__.py b/app/api/services/__init__.py index ebb76b5..4aee5f3 100644 --- a/app/api/services/__init__.py +++ b/app/api/services/__init__.py @@ -11,4 +11,5 @@ from app.api.services.login import LoginService from app.api.services.register import RegisterService from app.api.services.products import ProductsService from app.api.services.account import AccountService -from app.api.services.myproduct import MyProductsService \ No newline at end of file +from app.api.services.myproduct import MyProductsService +from app.api.services.contacts import ContactService \ No newline at end of file diff --git a/app/api/services/contacts.py b/app/api/services/contacts.py new file mode 100644 index 0000000..7294739 --- /dev/null +++ b/app/api/services/contacts.py @@ -0,0 +1,95 @@ +from flask import session, jsonify +from app.models.loan import Loan +from app.utils.logger import logger +from app.api.services.base_service import BaseService +# from app.api.schemas.eligibility_check import EligibilityCheckSchema +from marshmallow import ValidationError +from app.api.enums import TransactionType +from app.api.integrations import SimbrellaIntegration +from app.extensions import db +from app.models import MembersProducts, Products, Members + +from app.api.services.offer_analysis import OfferAnalysis +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 +import random +from app.config import Config + + +class ContactService(BaseService): + + @staticmethod + def process_request(data): + try: + with db.session.begin(): + logger.info(f"Incoming ContactService data ==>>>> {data}") + validated_data = ContactService.validate_data(data, UserSchema()) + token = validated_data.get('token') + uid = validated_data.get('uid') + + cat_list = ['A000002', 'A000004', 'A000001', 'A000003'] + # SUPPORTED_CATEGORY = "SELECT name AS title,product_id from products WHERE product_id IN ('A000002','A000004','A000001','A000003')" + # with connection: + # with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor: + # cursor.execute(SUPPORTED_CATEGORY) + # select_Res = cursor.fetchall() + # + # print(select_Res) + # contacts_category = json.dumps([dict(ix) for ix in select_Res]) + # print(contacts_category) + # array_cat = json.loads(contacts_category) + + dList = [] + sample_range = random.randint(20, 60) + for x in range(sample_range): + calDate = datetime.datetime.utcnow() + datetime.timedelta(minutes=180 * random.randint(1, 20)) + new_l = { + "uid": "425611f2-c692-4404-b93d-76ca7a5ce7" + str(x), + "title": "Calendar Random Item on " + str(x), + "category": cat_list[random.randint(0, 3)], + "added": calDate, + "sender": "Firstname Lastname" + str(random.randint(1, 4)), + "message": dummy_message() + } + dList.append(new_l) + + response_data = { + "last_update": datetime.datetime.utcnow(), + "category": cat_list, + "contacts": dList + } + + return ResponseHelper.success(data=response_data) + + except ValidationError as err: + + logger.error(f"Validation Error: {getattr(err, 'messages', str(err))}") + db.session.rollback() + return ResponseHelper.unprocessable_entity(result_description="Validation exception") + + except ValueError as err: + logger.error(f"{getattr(err, 'messages', str(err))}") + db.session.rollback() + return ResponseHelper.error(result_description=str(err)) + + except Exception as e: + logger.error(f"An error occurred: {str(e)}", exc_info=True) + db.session.rollback() + return ResponseHelper.internal_server_error() + +def dummy_message(): + dmm = "Dmummy Message" + str(random.randint(100, 400)) + mss = f""" + {dmm}I truly believe Augustine’s words are true and if you look at history you know it is true. There are many people in the world with amazing talents who realize only a small percentage of their potential. We all know people who live this truth. + + We also know those epic stories, those modern-day legends surrounding the early failures of such supremely successful folks as Michael Jordan and Bill Gates. We can look a bit further back in time to Albert Einstein or even further back to Abraham Lincoln. What made each of these people so successful? Motivation. + + We know this in our gut, but what can we do about it? How can we motivate ourselves? One of the most difficult aspects of achieving success is staying motivated over the long haul. + """ + return mss \ No newline at end of file