From 65929f7a9c00639a7b1c360ebc9870b221aa5339 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 18 Jan 2023 08:22:29 +0700 Subject: remove useless code, add last seen products, add compile product in user activity log --- indoteknik_api/controllers/api_v1/customer.py | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'indoteknik_api/controllers/api_v1/customer.py') 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(): -- cgit v1.2.3