aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-07-10 11:03:39 +0200
committerneodarz <neodarz@neodarz.net>2019-07-10 11:03:39 +0200
commit2ec8ef353eeaf133f87177cca2dae828454ba83b (patch)
tree0751e944bf1e7acba79181c72f041021914efe53
parent7d9bd3fc7ad0bdbebbd7a27db24c6dbf9df9e5d8 (diff)
downloadumosapi-2ec8ef353eeaf133f87177cca2dae828454ba83b.tar.xz
umosapi-2ec8ef353eeaf133f87177cca2dae828454ba83b.zip
Add search equal function
-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
+ }