added contactas endpoint

This commit is contained in:
CHIEFSOFT\ameye
2025-07-05 08:21:43 -04:00
parent 4d77abb25e
commit 19d1364e40
3 changed files with 106 additions and 1 deletions
+9
View File
@@ -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"])
+2 -1
View File
@@ -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
from app.api.services.myproduct import MyProductsService
from app.api.services.contacts import ContactService
+95
View File
@@ -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 Augustines 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