summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-11-01 14:17:27 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-11-01 14:17:27 +0700
commit196d8939a3f1118fe0e635dd261d19f887c4be2d (patch)
tree43663249f9c99d86516c2489b523c0209095a25b /indoteknik_api/controllers/api_v1
parentb2ac5d8be2d426dd968cbc9244377ecf3040800b (diff)
Banner Rest API & similar product method rest api
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/__init__.py1
-rw-r--r--indoteknik_api/controllers/api_v1/banner.py31
-rw-r--r--indoteknik_api/controllers/api_v1/product.py2
3 files changed, 33 insertions, 1 deletions
diff --git a/indoteknik_api/controllers/api_v1/__init__.py b/indoteknik_api/controllers/api_v1/__init__.py
index 275313ff..c8280c9a 100644
--- a/indoteknik_api/controllers/api_v1/__init__.py
+++ b/indoteknik_api/controllers/api_v1/__init__.py
@@ -1,3 +1,4 @@
+from . import banner
from . import blog
from . import category
from . import flash_sale
diff --git a/indoteknik_api/controllers/api_v1/banner.py b/indoteknik_api/controllers/api_v1/banner.py
new file mode 100644
index 00000000..60f9be85
--- /dev/null
+++ b/indoteknik_api/controllers/api_v1/banner.py
@@ -0,0 +1,31 @@
+from .. import controller
+from odoo import http
+from odoo.http import request
+
+
+class Banner(controller.Controller):
+ prefix = '/api/v1/'
+
+ @http.route(prefix + 'banner', auth='public', methods=['GET'])
+ 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')
+ type = kw.get('type')
+ if not type:
+ return self.response(code=400, description='type is required')
+
+ data = []
+ banner_category = request.env['x_banner.category'].search([('x_studio_field_KKVl4', '=', type)], limit=1)
+
+ if banner_category:
+ for banner in banner_category.banner_ids:
+ if banner.x_status_banner == 'tayang':
+ data.append({
+ 'name': banner.x_name,
+ 'url': banner.x_url_banner,
+ 'image': base_url + 'api/image/x_banner.banner/x_banner_image/' + str(banner.id) if banner.x_banner_image else '',
+ })
+
+ return self.response(data) \ No newline at end of file
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 15f75d98..26a7f1ec 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -84,7 +84,7 @@ class Product(controller.Controller):
return self.response(data)
- @http.route(prefix + 'product/<id>/similar', auth='public', methods=['GET'], cors="*")
+ @http.route(prefix + 'product/<id>/similar', auth='public', methods=['GET', 'OPTIONS'])
def get_product_similar_by_id(self, **kw):
if not self.authenticate():
return self.response(code=401, description='Unauthorized')