From 570061caefba9712629e6573eed3c6555e3d2f77 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Thu, 14 May 2026 20:00:22 -0400 Subject: [PATCH] contact actions --- app/api/services/contacts.py | 42 +++++++++++++++++++++++---------- app/models/products_contacts.py | 19 +++++++++++++++ 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/app/api/services/contacts.py b/app/api/services/contacts.py index ce41d67..81ecb87 100644 --- a/app/api/services/contacts.py +++ b/app/api/services/contacts.py @@ -15,7 +15,7 @@ class ContactService(BaseService): @staticmethod def process_request(data): try: - with db.session.begin(): + with (db.session.begin()): logger.info(f"Incoming ContactService data ==>>>> {data}") validated_data = ContactService.validate_data(data, UserSchema()) token = validated_data.get('token') @@ -33,20 +33,36 @@ class ContactService(BaseService): }) cat_list = ['A000002', 'A000004', 'A000001', 'A000003'] + page = 1 + limit = 20 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": "Contact Random Item on " + str(x), - "category": cat_list[random.randint(0, 3)], - "added": calDate, - "sender": "Firstname Lastname" + str(random.randint(1, 4)), - "message": ContactService.dummy_message() - } - dList.append(new_l) + contatsData = ProductsContacts.get_all_contacts(member_id, page=1, limit=20) + if contatsData: + for t in contatsData: + new_l = { + "uid": str(t.uid), + "title": t.title, + "category": t.product_id, + "added": t.added, + "sender": t.sender, + "message": t.message, + } + dList.append(new_l) + + + # 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": "Contact Random Item on " + str(x), + # "category": cat_list[random.randint(0, 3)], + # "added": calDate, + # "sender": "Firstname Lastname" + str(random.randint(1, 4)), + # "message": ContactService.dummy_message() + # } + # dList.append(new_l) response_data = { "last_update": datetime.datetime.utcnow(), diff --git a/app/models/products_contacts.py b/app/models/products_contacts.py index ebe01f3..87b959f 100644 --- a/app/models/products_contacts.py +++ b/app/models/products_contacts.py @@ -63,6 +63,25 @@ class ProductsContacts(db.Model): raise ValueError(f"Database integrity error: {err}") return product_contact_data + @classmethod + def get_all_contacts(cls,member_id, page=1, limit=20): + + query = cls.query + logger.info(f"Get all customer back") + + query = query.filter(cls.member_id == member_id) + + # Order by created_at descending (newest first) + query = query.order_by(cls.added.desc()) + + # Get total count before pagination + total_count = query.count() + + # Apply pagination + offset = (page - 1) * limit + query = query.limit(limit).offset(offset) + + return query.all(), total_count def to_dict(self):