From 007d5dc88b6e76321ad0d314d78767a24dc4f69c Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 27 Jul 2024 13:34:55 +0700 Subject: add api for lob home page based on id --- .../controllers/api_v1/category_management_lob.py | 50 ++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/category_management_lob.py b/indoteknik_api/controllers/api_v1/category_management_lob.py index e453e402..2931a4b5 100644 --- a/indoteknik_api/controllers/api_v1/category_management_lob.py +++ b/indoteknik_api/controllers/api_v1/category_management_lob.py @@ -8,7 +8,7 @@ class BrandHomepage(controller.Controller): @http.route(prefix + 'lob_homepage', auth='public', methods=['GET', 'OPTIONS'], csrf=False) @controller.Controller.must_authorized() - def get_brand_homepage(self, **kw): + def get_lob_homepage(self, **kw): base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url') query = [('status', '=', 'tayang')] @@ -19,14 +19,58 @@ class BrandHomepage(controller.Controller): category_ids = [ { 'id': cat.id, - 'name': cat.name + 'name': cat.name, + 'image': base_url + 'api/image/product.public.category/image/' + str(cat.id) if cat.image else '', } for cat in category.category_ids ] data.append({ 'id': category.id, 'sequence': category.sequence, 'industries': category.category_id.name if category.category_id else '', - 'image': base_url + '/api/image/website.categories.lob/image/' + str(category.id) if category.image else '', + 'image': base_url + 'api/image/website.categories.lob/image/' + str(category.id) if category.image else '', + 'category_ids': category_ids + }) + + return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')]) + + @http.route(prefix + 'lob_homepage', auth='public', methods=['GET', 'OPTIONS'], csrf=False) + @controller.Controller.must_authorized() + def get_lob_homepage_id(self, **kw): + base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url') + params = self.get_request_params(kw, { + 'lob_id': ['number', 'default:0'] + }) + + if not params['valid']: + return self.response(code=400, description=params) + + lob_id = params['value']['lob_id'] + if lob_id == 0: + lob_id = False + + # Modify search to include browsing based on the lob_id + if lob_id: + query = [('id', '=', lob_id), ('status', '=', 'tayang')] + else: + query = [('status', '=', 'tayang')] + + lob_records = request.env['website.categories.lob'].search(query) + + data = [] + for category in lob_records: + category_ids = [ + { + 'id': cat.id, + 'name': cat.name, + 'image': base_url + 'api/image/product.public.category/image/' + str(cat.id) if cat.image else '', + } for cat in category.category_ids + ] + data.append({ + 'id': category.id, + 'sequence': category.sequence, + 'industries': category.category_id.name if category.category_id else '', + 'image': base_url + 'api/image/website.categories.lob/image/' + str( + category.id) if category.image else '', 'category_ids': category_ids }) -- cgit v1.2.3 From 7f4895929e9b5221a83673b55e1609f7ffbc9699 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 29 Jul 2024 14:53:32 +0700 Subject: update get api lob category --- .../controllers/api_v1/category_management_lob.py | 61 ++++++++++++++-------- 1 file changed, 39 insertions(+), 22 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/category_management_lob.py b/indoteknik_api/controllers/api_v1/category_management_lob.py index 2931a4b5..7f1b389b 100644 --- a/indoteknik_api/controllers/api_v1/category_management_lob.py +++ b/indoteknik_api/controllers/api_v1/category_management_lob.py @@ -33,38 +33,54 @@ class BrandHomepage(controller.Controller): return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')]) - @http.route(prefix + 'lob_homepage', auth='public', methods=['GET', 'OPTIONS'], csrf=False) + @http.route(prefix + 'lob_homepage//category_id', auth='public', methods=['GET', 'OPTIONS'], csrf=False) @controller.Controller.must_authorized() - def get_lob_homepage_id(self, **kw): + def get_lob_homepage_id(self, id, **kw): base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url') - params = self.get_request_params(kw, { - 'lob_id': ['number', 'default:0'] - }) - - if not params['valid']: - return self.response(code=400, description=params) - lob_id = params['value']['lob_id'] - if lob_id == 0: - lob_id = False - - # Modify search to include browsing based on the lob_id - if lob_id: - query = [('id', '=', lob_id), ('status', '=', 'tayang')] - else: - query = [('status', '=', 'tayang')] + # Query for lob records + query = [('status', '=', 'tayang')] + if id: + query.append(('id', '=', id)) lob_records = request.env['website.categories.lob'].search(query) data = [] for category in lob_records: - category_ids = [ - { + category_ids = [] + child_ids = set() # Use a set to avoid duplicate IDs + + for cat in category.category_ids: + # Add category information to the list + category_ids.append({ 'id': cat.id, 'name': cat.name, 'image': base_url + 'api/image/product.public.category/image/' + str(cat.id) if cat.image else '', - } for cat in category.category_ids - ] + 'child_id': [] + }) + + # Find level 1 child categories with non-empty product_tmpl_ids + level_1_children = request.env['product.public.category'].search([ + ('parent_frontend_id', '=', cat.id), + ('product_tmpl_ids', '!=', False) + ]) + for child in level_1_children: + child_ids.add(child.id) + + # Find level 2 child categories with non-empty product_tmpl_ids + level_2_children = request.env['product.public.category'].search([ + ('parent_frontend_id', '=', child.id), + ('product_tmpl_ids', '!=', False) + ]) + for sub_child in level_2_children: + child_ids.add(sub_child.id) + + # Convert child_ids set to list and include the current category id + all_child_ids = list(child_ids) + for cat in category_ids: + cat['child_id'] = [cat['id']] + all_child_ids + + # Add lob record information data.append({ 'id': category.id, 'sequence': category.sequence, @@ -74,4 +90,5 @@ class BrandHomepage(controller.Controller): 'category_ids': category_ids }) - return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')]) \ No newline at end of file + # Response with formatted JSON + return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')]) -- cgit v1.2.3 From 5ead14749a6be3453c71b0b053cc508facb5ab9d Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 30 Jul 2024 17:09:49 +0700 Subject: update image --- indoteknik_api/controllers/api_v1/category_management_lob.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/category_management_lob.py b/indoteknik_api/controllers/api_v1/category_management_lob.py index 7f1b389b..0018edce 100644 --- a/indoteknik_api/controllers/api_v1/category_management_lob.py +++ b/indoteknik_api/controllers/api_v1/category_management_lob.py @@ -55,7 +55,7 @@ class BrandHomepage(controller.Controller): category_ids.append({ 'id': cat.id, 'name': cat.name, - 'image': base_url + 'api/image/product.public.category/image/' + str(cat.id) if cat.image else '', + 'image': base_url + 'web/image?model=x_banner.banner&id=' + str(cat.x_studio_field_7bVEO.id)+'&field=x_banner_image' if cat.image else '', 'child_id': [] }) @@ -85,8 +85,8 @@ class BrandHomepage(controller.Controller): 'id': category.id, 'sequence': category.sequence, 'industries': category.category_id.name if category.category_id else '', - 'image': base_url + 'api/image/website.categories.lob/image/' + str( - category.id) if category.image else '', + 'image': base_url + 'web/image?model=website.categories.lob' + str( + category.id) + '&field=image' if category.image else '', 'category_ids': category_ids }) -- cgit v1.2.3