summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/banner.py
blob: 049051b0285826cf0f6c865b79a7f44011793544 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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', '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)