summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/customer.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-01-18 08:22:29 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-01-18 08:22:29 +0700
commit65929f7a9c00639a7b1c360ebc9870b221aa5339 (patch)
tree04fe40072cda5622f30192073fae3de93c2f694d /indoteknik_api/controllers/api_v1/customer.py
parent78b151a7e90e84dfa3898b75cf4440c714ba9305 (diff)
remove useless code, add last seen products, add compile product in user activity log
Diffstat (limited to 'indoteknik_api/controllers/api_v1/customer.py')
-rw-r--r--indoteknik_api/controllers/api_v1/customer.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/indoteknik_api/controllers/api_v1/customer.py b/indoteknik_api/controllers/api_v1/customer.py
index f6d6d40d..57120751 100644
--- a/indoteknik_api/controllers/api_v1/customer.py
+++ b/indoteknik_api/controllers/api_v1/customer.py
@@ -7,6 +7,44 @@ import ast
class CustomerReview(controller.Controller):
prefix = '/api/v1/'
+ @http.route(prefix + 'last_seen_products', auth='public', methods=['GET', 'OPTIONS'])
+ def get_last_seen_products(self, **kw):
+ if not self.authenticate():
+ return self.response(code=401, description='Unauthorized')
+
+ email = str(kw.get('email', ''))
+ if not email:
+ return self.response(code=401, description='Unauthorized')
+
+ activity_logs = request.env['user.activity.log'].search([
+ ('url', 'ilike', 'https://indoteknik.co%/shop/product/%'),
+ ('email', '=', email),
+ ], order='create_date desc', limit=5)
+
+ data = []
+ templates = []
+ for activity_log in activity_logs:
+ strip_index = i = 0
+ for c in activity_log.url:
+ if c == '-':
+ strip_index = i
+ i += 1
+ template_id = activity_log.url[strip_index + 1:len(activity_log.url)]
+ if '#' in template_id:
+ continue
+ if any(ch.isalpha() for ch in template_id):
+ continue
+ template = request.env['product.template'].search([('id', '=', template_id)])
+ templates.append(template)
+
+ data.append({
+ 'email': email,
+ 'products': [request.env['product.template'].api_single_response(x) for x in templates]
+ })
+ return self.response(data)
+
+
+
@http.route(prefix + 'customer_review', auth='public', methods=['GET', 'OPTIONS'])
def get_customer_review(self, **kw):
if not self.authenticate():