diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2023-01-09 10:12:20 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2023-01-09 10:12:20 +0000 |
| commit | 9eeee43ec3cb57d02a2dcddf03768a2a8f3ea3d8 (patch) | |
| tree | e57fd41c83766b49eb49f871f809ed79add5b5bc /indoteknik_api/controllers/api_v1/city.py | |
| parent | 8a70abf6f05e9ffc6e74ec2e80f61db72f6f0401 (diff) | |
| parent | b1329f940ae66b60185fa097012393b0d51b9e5f (diff) | |
Merged in staging (pull request #16)
Staging
Diffstat (limited to 'indoteknik_api/controllers/api_v1/city.py')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/city.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/indoteknik_api/controllers/api_v1/city.py b/indoteknik_api/controllers/api_v1/city.py new file mode 100644 index 00000000..773cd483 --- /dev/null +++ b/indoteknik_api/controllers/api_v1/city.py @@ -0,0 +1,26 @@ +from .. import controller +from odoo import http +from odoo.http import request + +class City(controller.Controller): + prefix = '/api/v1/' + + @http.route(prefix + 'city', auth='public', methods=['GET', 'OPTIONS']) + def get_city(self, **kw): + if not self.authenticate(): + return self.response(code=401, description='Unauthorized') + + parameters = [] + + name = kw.get('name') + if name: + name = '%' + name.replace(' ', '%') + '%' + parameters.append(('name', 'ilike', name)) + + cities = request.env['vit.kota'].search(parameters) + data = [] + for city in cities: + data.append({ 'id': city.id, 'name': city.name }) + + return self.response(data) + |
