aboutsummaryrefslogtreecommitdiff
path: root/umosapi/app_db/uobject.py
diff options
context:
space:
mode:
Diffstat (limited to 'umosapi/app_db/uobject.py')
-rw-r--r--umosapi/app_db/uobject.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/umosapi/app_db/uobject.py b/umosapi/app_db/uobject.py
index 175ac52..3d29bf6 100644
--- a/umosapi/app_db/uobject.py
+++ b/umosapi/app_db/uobject.py
@@ -12,20 +12,25 @@ class UObject(object):
mongo = db.connection()
return list(mongo.db.objects.find({}))
- def register(self, name):
+ def register(self, name, datas):
db = MongoDB(self.app)
mongo = db.connection()
error = {}
if not name:
error = {'msg': 'Object name is required.', 'code': 400}
+ elif type(datas) != dict:
+ error = {
+ "msg": "Object datas type is not dict (JSON).",
+ "code": 400
+ }
elif len(list(mongo.db.objects.find({"name": name}))) > 0:
error = {
'msg': 'Object {} is already registered.'.format(name),
'code': 409
}
if not error:
- mongo.db.objects.insert({"name": name})
+ mongo.db.objects.insert({"name": name, "datas": datas})
return {'msg': 'Object {} added.'.format(name), 'code': 201}
return error