Comments modules

This commit is contained in:
CHIEFSOFT\ameye
2025-09-08 16:28:33 -04:00
parent 2b494ffe3c
commit ef53fcf03e
3 changed files with 103 additions and 3 deletions
+3 -2
View File
@@ -15,6 +15,7 @@ from app.api.services import (
OfficeCustomerService,
GenerativesService
)
from app.api.services.comments import CommentsService
from app.utils.logger import logger
from app.api.middlewares import enforce_json, require_auth
import os
@@ -206,8 +207,8 @@ def merms_contacts():
@api.route("/panel/comments", methods=["POST"])
def merms_site_comments():
data = request.get_json()
# logger.info(f"Route ContactService URL Data ==>>>> {data}")
response = ContactService.process_request(data)
# logger.info(f"Route CommentsService URL Data ==>>>> {data}")
response = CommentsService.process_comments_request(data)
return response
+1 -1
View File
@@ -10,7 +10,7 @@ from app.api.services.web_contents import WebContentsService
from app.api.services.subscriptions import SubscriptionsService
from app.api.services.common_data import CommonDataService
from app.api.services.genaratives import GenerativesService
from app.api.services.comments import CommentsService
# OFFICE
from app.api.services.office_customer import OfficeCustomerService
+99
View File
@@ -0,0 +1,99 @@
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 CommentsService(BaseService):
@staticmethod
def process_comments_request(data):
try:
with db.session.begin():
logger.info(f"Incoming ContactService data ==>>>> {data}")
validated_data = CommentsService.validate_data(data, UserSchema())
token = validated_data.get('token')
uid = validated_data.get('uid')
member_data = Members.get_member_by_uid(uid)
member_id = member_data.id
contacts_product_list = Products.get_contact_supported_product_list(member_id)
category_data = []
for t in contacts_product_list:
category_data.append({
'cid': t.product_id,
'category_uid': t.uid,
'description': t.name,
})
cat_list = [ 'A000004', 'A000003']
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": "Random Site Comments 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(),
"member_id": member_id,
"category": category_data,
"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