contact actions

This commit is contained in:
CHIEFSOFT\ameye
2026-05-14 20:00:22 -04:00
parent 25a44dd7a5
commit 570061caef
2 changed files with 48 additions and 13 deletions
+29 -13
View File
@@ -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(),
+19
View File
@@ -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):