Files
MermsCoreFlask/app/api/services/myproduct.py
T
CHIEFSOFT\ameye 5ba7b5b2ce New data
2025-07-05 21:25:47 -04:00

108 lines
5.5 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, ProductsDetails
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.myproduct import MyProductSchema
import datetime
import jwt
import random
from app.config import Config
class MyProductsService(BaseService):
@staticmethod
def process_request(data):
try:
with db.session.begin():
logger.info(f"Incoming MyProduct data ==>>>> {data}")
validated_data = MyProductsService.validate_data(data, MyProductSchema())
token = validated_data.get('token')
uid = validated_data.get('uid')
product_id = validated_data.get('product_id')
'''
Table "public.products"
Column | Type | Collation | Nullable | Default
-------------+-----------------------------+-----------+----------+--------------------------------------
id | integer | | not null | nextval('products_id_seq'::regclass)
uid | uuid | | | uuid_generate_v4()
product_id | character varying(25) | | not null |
name | character varying(100) | | not null |
description | character varying(250) | | not null |
status | integer | | | 0
added | timestamp without time zone | | | now()
updated | timestamp without time zone | | | now()
banner | character varying(100) | | |
Indexes:
"products_id_key" UNIQUE CONSTRAINT, btree (id)
"products_name_key" UNIQUE CONSTRAINT, btree (name)
"products_product_id_key" UNIQUE CONSTRAINT, btree (product_id)
Referenced by:
TABLE "members_products" CONSTRAINT "members_products_product_id_fkey" FOREIGN KEY (product_id) REFERENCES products(product_id)
merms_panel=#
"Product Description - Commitment is something that comes from understanding that everything has its price and then having the willingness to pay that price. This is important because nobody wants to put significant effort into something, only to find out after the fact that the price was too high.The price is something not necessarily defined as financial. It could be time, effort, sacrifice, money or perhaps, something else.",
'''
product_data = Products.get_product_by_product_id(product_id)
product_description = ProductsDetails.get_product_desctiption_by_product_id('A000002')
# "banner": "banner.jpg",
myproduct_data = {
"myproudct": {
"banner": product_data.banner,
"description": product_description,
"internal_url": "",
"price_text": "90 days free and 3.95/Month",
"product_id": product_data.product_id,
"product_name": product_data.name,
"product_subscription_uid": "",
"product_uid": product_data.uid,
"promotion_text": "Start Free Today !",
"status": 1,
"subscription_text": "Start with your goals in mind and then work possible.ith yand Goals. If the plan doesn\u2019t support the vision then change it!",
"title": "Your personal professional web presence"
}
}
# Simulate processing
response_data = {
"myproduct": myproduct_data,
"member_id": 1,
"uid": uid,
}
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()