Commit 47cf58b9 authored by Cédric Bonhomme's avatar Cédric Bonhomme

Improved MongoDB query.

parent f9d565f6
......@@ -21,12 +21,10 @@ def what(epc=None):
Returns all EPCIS events involving the electronic product code (EPC)
given in parameter.
"""
result = models.EPCISEvent.objects()
epcis_events = [epcis_event.data for epcis_event in result if \
epc in epcis_event.data["ObjectEvent"]["epcList"].values()]
if len(epcis_events) == 0:
result = models.EPCISEvent.objects(data__ObjectEvent__epcList__epc=epc).only("data")
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)
@app.route('/where/<string:location>', methods=['GET'])
......@@ -34,13 +32,10 @@ def where(location=None):
"""
Return all EPCIS events at 'bizLocation'.
"""
result = models.EPCISEvent.objects()
epcis_events = [epcis_event.data for epcis_event in result if \
location in epcis_event.data["ObjectEvent"]["bizLocation"].values()] # or "readPoint" instead of "bizLocation"
if len(epcis_events) == 0:
result = models.EPCISEvent.objects(data__ObjectEvent__bizLocation__id=location).only("data")
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)
@app.errorhandler(404)
......
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