aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-07-08 16:45:04 +0200
committerneodarz <neodarz@neodarz.net>2019-07-08 16:45:04 +0200
commit97858b6edfaaee44077761663d2ade3b84e6d3d7 (patch)
tree856e57082927ca720c445f17a5bec77511475aad
parentbcde164af6aeccc13ee77c0b5e505399994095d3 (diff)
downloadumosapi-97858b6edfaaee44077761663d2ade3b84e6d3d7.tar.xz
umosapi-97858b6edfaaee44077761663d2ade3b84e6d3d7.zip
Add datas field of uobject schema
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