summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-01-24 13:58:03 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-01-24 13:58:03 +0700
commit93d049139c2be8a70d32145a89e8b6e34732d56d (patch)
tree86357713102fbfba446e6015b225ec3d2a46b4c0 /indoteknik_api/controllers/api_v1
parentda5f5134f56b2ccf1c1de16c3f7616ab3719f3ea (diff)
parent3f311b95265adf1902e650b12fba93cf81a7f72d (diff)
Merge branch 'release' into feature/rest-api
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/content.py31
-rw-r--r--indoteknik_api/controllers/api_v1/product.py10
2 files changed, 37 insertions, 4 deletions
diff --git a/indoteknik_api/controllers/api_v1/content.py b/indoteknik_api/controllers/api_v1/content.py
index 3d4e443a..32828244 100644
--- a/indoteknik_api/controllers/api_v1/content.py
+++ b/indoteknik_api/controllers/api_v1/content.py
@@ -6,6 +6,37 @@ from odoo.http import request
class WebsiteContent(controller.Controller):
prefix = '/api/v1/'
+ @http.route(prefix + 'banner', auth='public', methods=['GET', 'OPTIONS'])
+ def get_banner(self, **kw):
+ if not self.authenticate():
+ return self.response(code=401, description='Unauthorized')
+ base_url = request.env['ir.config_parameter'].get_param('web.base.url')
+
+ category_id = int(kw.get('category_id'), 0)
+ query = [
+ ('x_status_banner', '=', 'tayang'),
+ ]
+
+ if category_id > 0:
+ query = [
+ ('x_status_banner', '=', 'tayang'),
+ ('x_banner_category', '=', category_id),
+ ]
+
+ data = []
+ banners = request.env['x_banner.banner'].search(query)
+ for banner in banners:
+ data.append({
+ # 'image': base_url + 'api/image/x_banner.banner/image' + str(banner.id) if banner.x_banner_image else '',
+ 'banner_image': request.env['ir.attachment'].api_image('x_banner.banner', 'x_banner_image', banner.id),
+ 'category_id': banner.x_banner_category.id,
+ 'category_image': banner.x_banner_category.x_name,
+ 'name': banner.x_name,
+ 'url': banner.x_url_banner,
+ 'status': banner.x_status_banner,
+ })
+ return self.response(data)
+
@http.route(prefix + 'product_ads', auth='public', methods=['GET', 'OPTIONS'])
def get_product_ads(self, **kw):
if not self.authenticate():
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 23dcf48e..dc941f13 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -48,8 +48,9 @@ class Product(controller.Controller):
'manufacture_id': brand.id,
'sequence': brand.sequence if brand.sequence else count,
'name': brand.x_name,
- 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(
- brand.id) if brand.x_logo_manufacture else '',
+ # 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(
+ # brand.id) if brand.x_logo_manufacture else '',
+ 'image': request.env['ir.attachment'].api_image('x_manufactures', 'x_logo_manufacture', brand.id),
})
continue
@@ -74,8 +75,9 @@ class Product(controller.Controller):
'manufacture_id': brand.id,
'sequence': brand.sequence if brand.sequence else count,
'name': brand.x_name,
- 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(
- brand.id) if brand.x_logo_manufacture else '',
+ # 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(
+ # brand.id) if brand.x_logo_manufacture else '',
+ 'image': request.env['ir.attachment'].api_image('x_manufactures', 'x_logo_manufacture', brand.id),
'products_total': count_products,
'products': [request.env['product.template'].api_single_response(x) for x in products]
})