aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--umosapi/api.py16
-rw-r--r--umosapi/app_db/uobject.py20
2 files changed, 36 insertions, 0 deletions
diff --git a/umosapi/api.py b/umosapi/api.py
index 112960f..8a0945f 100644
--- a/umosapi/api.py
+++ b/umosapi/api.py
@@ -82,3 +82,19 @@ class Objects(Resource):
status = uobject.remove(_id)
return {"msg": status['msg']}, status['code']
+
+
+@api.route("/objects/<key>/<value>")
+class ObjectsEq(Resource):
+ @api.doc(params={
+ 'key': 'kill or total.kill',
+ 'value': '12',
+ })
+ def get(self, key, value):
+ """ Get uobjects matching key/value """
+ status = uobject.eq(key, value)
+
+ return {
+ "msg": status['msg'],
+ "datas": sanitize(status['datas'])
+ }, status['code']
diff --git a/umosapi/app_db/uobject.py b/umosapi/app_db/uobject.py
index 9830187..60094c7 100644
--- a/umosapi/app_db/uobject.py
+++ b/umosapi/app_db/uobject.py
@@ -65,3 +65,23 @@ class UObject(object):
mongo.db.uobjects.update_one({"_id": ObjectId(_id)}, {"$set": datas})
return {"msg": "UObject updated.", "code": 200}
return error
+
+ def eq(self, key, value):
+ db = MongoDB(self.app)
+ mongo = db.connection()
+
+ datas = list(mongo.db.uobjects.find(
+ {"datas.{}".format(key): {"$eq": value}}
+ ))
+ if datas:
+ return {
+ "msg": "UObjects found",
+ "datas": datas,
+ "code": 200
+ }
+ else:
+ return {
+ "msg": "UObjects not found",
+ "datas": datas,
+ "code": 404
+ }