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', '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') 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)