summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/banner.py
blob: 362a2b58175d602282b5b257b3f8ee632f4c6976 (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
32
33
34
35
36
37
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')
        manufacture_id = kw.get('manufacture_id')
        type = kw.get('type')
        limit = int(kw.get('limit', 0))
        offset = int(kw.get('offset', 0))
        
        query = [('x_status_banner', '=', 'tayang')]
        if type:
            query += [('x_banner_category.x_studio_field_KKVl4', '=', type)]
        
        if manufacture_id:
            query += [('x_relasi_manufacture', '=', int(manufacture_id))]
        
        banners = request.env['x_banner.banner'].search(query, limit=limit, offset=offset)
        
        data = []
        for banner in banners:
            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)