Commit 0b518654 authored by Cédric Bonhomme's avatar Cédric Bonhomme

Filter by epc urn.

parent 97a7e550
......@@ -15,14 +15,21 @@ class EPCISEventAPI(Resource):
def __init__(self):
super(EPCISEventAPI, self).__init__()
def get(self):
def get(self, epc=None):
"""
Return the 10 last EPCIS event.
"""
result = models.EPCISEvent.objects[:10]
if result.count == 0:
return jsonify(result="no epcis event")
epcis_events = [epcis_event.data for epcis_event in result]
if epc != None:
result = models.EPCISEvent.objects()
epcis_events = [epcis_event.data for epcis_event in result if \
epc in epcis_event.data["ObjectEvent"]["epcList"].values()]
else:
result = models.EPCISEvent.objects[:10]
if result.count == 0:
return jsonify(result="no epcis event")
epcis_events = [epcis_event.data for epcis_event in result]
return jsonify(result="ok", epcis_events=epcis_events)
def put(self):
......@@ -43,4 +50,5 @@ class EPCISEventAPI(Resource):
"""
pass
api.add_resource(EPCISEventAPI, '/epcis.json/', endpoint = 'epcis')
\ No newline at end of file
api.add_resource(EPCISEventAPI, '/epcis.json/', endpoint = 'epcis')
api.add_resource(EPCISEventAPI, '/epcis.json/<string:epc>', endpoint = 'epcisId')
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment