summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-08-05 17:08:36 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-08-05 17:08:36 +0700
commit1d2769930ce4113c4620f82d1417e4221e0ab465 (patch)
tree867645970579b0753f23ec5148f28f20066b556d /indoteknik_api/controllers/api_v1
parent5ead14749a6be3453c71b0b053cc508facb5ab9d (diff)
<iman> update api category
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/category.py63
1 files changed, 38 insertions, 25 deletions
diff --git a/indoteknik_api/controllers/api_v1/category.py b/indoteknik_api/controllers/api_v1/category.py
index 09b8ff8c..7d66ad01 100644
--- a/indoteknik_api/controllers/api_v1/category.py
+++ b/indoteknik_api/controllers/api_v1/category.py
@@ -123,34 +123,47 @@ class Category(controller.Controller):
return self.response(response_data)
- @http.route(prefix + 'category/tree', auth='public', methods=['GET', 'OPTIONS'])
- @controller.Controller.must_authorized()
- def get_category_tree(self):
- parent_categories = request.env['product.public.category'].search_read([('parent_frontend_id', '=', False)], ['id', 'name'])
- data = []
- for parent_category in parent_categories:
- parent_data = {
- 'id': parent_category['id'],
- 'name': parent_category['name'],
- 'childs': []
- }
- child_1_categories = request.env['product.public.category'].search_read([('parent_frontend_id', '=', parent_category['id'])], ['id', 'name'])
- for child_1_category in child_1_categories:
- child_1_data = {
- 'id': child_1_category['id'],
- 'name': child_1_category['name'],
+ class CategoryManagement(controller.Controller):
+ prefix = '/api/v1/'
+
+ @http.route(prefix + 'category/tree', auth='public', methods=['GET', 'OPTIONS'], csrf=False)
+ @controller.Controller.must_authorized()
+ def get_category_tree(self):
+ parent_categories = request.env['product.public.category'].search_read([('parent_frontend_id', '=', False)],
+ ['id', 'name', 'image_1920'])
+ data = []
+ for parent_category in parent_categories:
+ category_data_ids = [parent_category['id']]
+ parent_data = {
+ 'id': parent_category['id'],
+ 'name': parent_category['name'],
+ 'image': request.env['ir.attachment'].sudo().api_image('product.public.category', 'image_1920',
+ parent_category['id']),
+ 'category_data_ids': category_data_ids,
'childs': []
}
- child_2_categories = request.env['product.public.category'].search_read([('parent_frontend_id', '=', child_1_category['id'])], ['id', 'name'])
- for child_2_category in child_2_categories:
- child_2_data = {
- 'id': child_2_category['id'],
- 'name': child_2_category['name'],
+ child_1_categories = request.env['product.public.category'].search_read(
+ [('parent_frontend_id', '=', parent_category['id'])], ['id', 'name'])
+ for child_1_category in child_1_categories:
+ child_1_data = {
+ 'id': child_1_category['id'],
+ 'name': child_1_category['name'],
+ 'childs': []
}
- child_1_data['childs'].append(child_2_data)
- parent_data['childs'].append(child_1_data)
- data.append(parent_data)
- return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')])
+ category_data_ids.append(child_1_category['id'])
+ child_2_categories = request.env['product.public.category'].search_read(
+ [('parent_frontend_id', '=', child_1_category['id'])], ['id', 'name'])
+ for child_2_category in child_2_categories:
+ child_2_data = {
+ 'id': child_2_category['id'],
+ 'name': child_2_category['name'],
+ }
+ child_1_data['childs'].append(child_2_data)
+ category_data_ids.append(child_2_category['id'])
+ parent_data['childs'].append(child_1_data)
+ parent_data['category_data_ids'] = category_data_ids
+ data.append(parent_data)
+ return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')])
@http.route(prefix + 'categories_homepage/ids', auth='public', methods=['GET', 'OPTIONS'])
@controller.Controller.must_authorized()