100 lines
4.3 KiB
Python
100 lines
4.3 KiB
Python
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_comments_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, 1)],
|
||
"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 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
|