summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/content.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-01-24 11:29:43 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-01-24 11:29:43 +0700
commit8f11d3322d4a549549e58820ced9169f2b344d69 (patch)
tree5ada91057a1fcb89dd2c894ebccd32efc2807394 /indoteknik_api/controllers/api_v1/content.py
parent9b026c1ce5683b42dfdd15da74cf6da0ef7bf9d5 (diff)
add rest get banner
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():