summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-11-18 14:02:44 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-11-18 14:02:44 +0700
commitca18c1e40971df1cf796ec5862688d8e1873e76e (patch)
tree4feff4c32768255f967023caae2b2d725bf62bf1
parent3636010794b53f97ee50fdcd24f4059f717a6624 (diff)
Manufacture detail rest api
-rw-r--r--indoteknik_api/controllers/api_v1/manufacture.py12
-rw-r--r--indoteknik_api/models/x_manufactures.py11
2 files changed, 22 insertions, 1 deletions
diff --git a/indoteknik_api/controllers/api_v1/manufacture.py b/indoteknik_api/controllers/api_v1/manufacture.py
index 7d113b86..5b9d57b2 100644
--- a/indoteknik_api/controllers/api_v1/manufacture.py
+++ b/indoteknik_api/controllers/api_v1/manufacture.py
@@ -31,6 +31,18 @@ class Manufacture(controller.Controller):
return self.response(data)
+ @http.route(prefix + 'manufacture/<id>', auth='public', methods=['GET', 'OPTIONS'])
+ def get_manufacture(self, **kw):
+ if not self.authenticate():
+ return self.response(code=401, description='Unauthorized')
+
+ id = kw.get('id')
+ manufacture = request.env['x_manufactures'].search([('id', '=', id)], limit=1)
+ data = {}
+ if manufacture:
+ data = request.env['x_manufactures'].api_single_response(manufacture, with_detail=True)
+ return self.response(data)
+
@http.route(prefix + 'manufacture/page/<page>', auth='public', methods=['GET'])
def get_manufacture_by_page(self, **kw):
if not self.authenticate():
diff --git a/indoteknik_api/models/x_manufactures.py b/indoteknik_api/models/x_manufactures.py
index 6755ac66..29f99063 100644
--- a/indoteknik_api/models/x_manufactures.py
+++ b/indoteknik_api/models/x_manufactures.py
@@ -9,6 +9,15 @@ class Manufactures(models.Model):
data = {
'id': manufacture.id,
'logo': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(manufacture.id) if manufacture.x_logo_manufacture else '',
- 'name': manufacture.x_name,
+ 'name': manufacture.x_name
}
+ if with_detail:
+ data_with_detail = {
+ 'banners': [
+ base_url + 'api/image/x_banner.banner/x_banner_image/' + str(x.id)
+ for x in manufacture.x_manufactures_banners
+ if x.x_status_banner == 'tayang' and x.x_banner_image
+ ]
+ }
+ data.update(data_with_detail)
return data \ No newline at end of file