summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/content.py
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/content.py
parentda5f5134f56b2ccf1c1de16c3f7616ab3719f3ea (diff)
parent3f311b95265adf1902e650b12fba93cf81a7f72d (diff)
Merge branch 'release' into feature/rest-api
Diffstat (limited to 'indoteknik_api/controllers/api_v1/content.py')
-rw-r--r--indoteknik_api/controllers/api_v1/content.py31
1 files changed, 31 insertions, 0 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():