contact actions
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user