Skip to content

Commit

Permalink
Merge pull request #113 from INRIM/t_12691
Browse files Browse the repository at this point in the history
[ADD] added tag get,post,put rest api
  • Loading branch information
Marcoapu authored Oct 22, 2024
2 parents eca1291 + d62d9ee commit 1f61477
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
27 changes: 26 additions & 1 deletion inrim_anagrafiche/models/ca_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,29 @@ def _compute_revoked(self):
record.revoked = False
if record.ca_proprieta_tag_ids:
if self.env.ref('inrim_anagrafiche.proprieta_tag_revocato') in record.ca_proprieta_tag_ids:
record.revoked = True
record.revoked = True

def rest_boby_hint(self):
return {
"name": "Temporaneo",
"tag_code": "E0010150AD255C11",
}

def rest_get_record(self):
vals = {
'id': self.id,
'name': self.name,
'tag_code': self.tag_code,
'ca_proprieta_tag_ids': self.f_m2m(self.ca_proprieta_tag_ids),
'in_use': self.in_use,
'temp': self.temp,
'revoked': self.revoked,
}
return vals

def rest_eval_body(self, body):
body, msg = super().rest_eval_body(
body, [
'name', 'tag_code'
])
return body, msg
32 changes: 30 additions & 2 deletions inrim_controllo_accessi_api/controllers/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,40 @@

from .api_controller_inrim import InrimApiController, BadRequest

class InrimApiTag(InrimApiController):

@http.route('/api/tag', auth="none", type='http', methods=['GET'],
csrf=False)
def api_get_ca_tag(self, **params):
self.check_token('ca.tag', 'read')
return self.handle_response(
*self.model.rest_get(params), is_list=True)

@http.route('/api/tag', auth="none", type='http', methods=['POST'],
csrf=False)
def api_post_ca_tag(self):
self.check_token('ca.tag', 'create')
data = self.check_and_decode_body()
try:
return self.handle_response(*self.model.rest_post(data))
except Exception as e:
raise BadRequest(str(e))

@http.route('/api/tag', auth="none", type='http', methods=['PUT'],
csrf=False)
def api_put_ca_tag(self):
self.check_token('ca.tag', 'write')
data = self.check_and_decode_body()
try:
return self.handle_response(*self.model.rest_put(data))
except Exception as e:
raise BadRequest(str(e))

class InrimApiProprietaTag(InrimApiController):

@http.route('/api/proprieta_tag', auth="none", type='http', methods=['GET'],
csrf=False)
def api_get_ca_proprieta_tag(self, **params):
model = 'ca.proprieta_tag'
self.check_token(model, 'read')
self.check_token('ca.proprieta_tag', 'read')
return self.handle_response(
*self.model.rest_get(params), is_list=True)

0 comments on commit 1f61477

Please sign in to comment.