This commit is contained in:
CHIEFSOFT\ameye
2025-07-07 19:17:14 -04:00
parent 4d7f78dc75
commit 92c8c02d29
2 changed files with 84 additions and 0 deletions
+8
View File
@@ -150,6 +150,14 @@ def myproduct_subscription():
response = MyProductsService.process_subscription(data)
return response
#/panel/myproduct/provision
@api.route("/panel/myproduct/provision", methods=["POST"])
def myproduct_provision():
data = request.get_json()
logger.info(f"Route MyProduct Data ==>>>> {data}")
response = MyProductsService.process_provision(data)
return response
# /panel/account/calendar
@api.route("/panel/account/calendar", methods=["POST"])
+76
View File
@@ -16,6 +16,82 @@ from app.config import Config
class MyProductsService(BaseService):
@staticmethod
def process_provision(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')
member_data = Members.get_member_by_uid(uid)
member_id = member_data.id
product_id = validated_data.get('product_id')
product_data = Products.get_product_by_product_id(product_id)
if not product_data:
return {
"message": "Please provide product_id",
"data": None,
"error": "Bad request"
}, 400
logger.info(f"GET HERE ******************************** : {data}", exc_info=True)
subscription = MembersProducts.get_member_product_by_product_member_id(member_id, product_id)
# if not subscription:
# logger.error(f"Ready to add data to tables")
# response_data = {
# "subscription": mumberSub,
# "member_id": member_id,
# "error": "already_subscribed",
# "uid": uid
# }
# return ResponseHelper.success(data=response_data)
# internal_url = str(random.randint(10000, 99999)) + ".devprov.mermsemr.com"
#INSERT_NEW_PRODUCT = "INSERT INTO members_products (member_id ,product_id,status,internal_url) VALUES (%s, %s, %s, %s)"
# val_insert = (member_id, product_id,6,internal_url)
# status = 6
# subscription = MembersProducts.create_subscription(member_id ,product_id,status,internal_url)
# response_data = {
# "subscription_uid": subscription.uid,
# "subscription_id": subscription.id,
# "internal_url": subscription.internal_url,
# "member_id": member_id,
# "uid": uid
# }
provision_activities=[]
response_data = {
"subscription_uid": subscription.uid,
"subscription_id": subscription.id,
"last_update": datetime.datetime.utcnow(),
"percent_completed": random.randint(10, 99),
"activities": provision_activities
}
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()
@staticmethod
def process_subscription(data):
try: