summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/banner.py
blob: 1bd0fea620bee5d21f93691fa7095aad07c6f54a (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
38
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'])
    @controller.Controller.must_authorized()
    def get_banner(self, **kw):
        manufacture_id = kw.get('manufacture_id')
        type = kw.get('type')
        limit = int(kw.get('limit', 0))
        offset = int(kw.get('offset', 0))
        order = kw.get('order')
        if not order:
            order = 'write_date DESC'
        
        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, order=order)
        
        data = []
        for banner in banners:
            data.append({
                'name': banner.x_name,
                'url': banner.x_url_banner,
                'background_color': banner.background_color,
                'image': request.env['ir.attachment'].api_image('x_banner.banner', 'x_banner_image', banner.id),
            })
        
        return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')])