aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--umosapi/api.py13
-rw-r--r--umosapi/app_db/uobject.py9
2 files changed, 19 insertions, 3 deletions
diff --git a/umosapi/api.py b/umosapi/api.py
index 0b48079..ef83c18 100644
--- a/umosapi/api.py
+++ b/umosapi/api.py
@@ -28,11 +28,22 @@ api = Api(
uobject = UObject(app)
+
+class fieldsDict(fields.Raw):
+ __schema_type__ = ["Dict"]
+ __schema_example__ = {"key": "token"}
+
+
user_model = api.model('UObject', {
'name': fields.String(
required=True,
description='Name of the uobject',
example='Player'
+ ),
+ 'datas': fieldsDict(
+ required=False,
+ description='Datas of the uobject in JSON format',
+ example={"key": "token"}
)
})
@@ -53,7 +64,7 @@ class Register(Resource):
def post(self):
""" Register new uobject """
args = request.get_json(force=True)
- status = uobject.register(args.get('name'))
+ status = uobject.register(args.get('name'), args.get('datas'))
return loads('{"msg": "'+status['msg']+'"}'), status['code']
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