diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-07-27 13:34:55 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-07-27 13:34:55 +0700 |
| commit | 007d5dc88b6e76321ad0d314d78767a24dc4f69c (patch) | |
| tree | 01469ee011e6ae2bde68c2991de18203cb34b7f4 /indoteknik_api/controllers/api_v1 | |
| parent | a7057cc2fd5bd800d7b75f101aec9b67cdbe0053 (diff) | |
<iman> add api for lob home page based on id
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/category_management_lob.py | 50 |
1 files changed, 47 insertions, 3 deletions
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 }) |
