aboutsummaryrefslogtreecommitdiff
path: root/umosapi/api.py
diff options
context:
space:
mode:
Diffstat (limited to 'umosapi/api.py')
-rw-r--r--umosapi/api.py42
1 files changed, 23 insertions, 19 deletions
diff --git a/umosapi/api.py b/umosapi/api.py
index 9729735..effd610 100644
--- a/umosapi/api.py
+++ b/umosapi/api.py
@@ -24,7 +24,7 @@ api = Api(
Unity Mongo Save Api is a simple API for save Unity
object in Mongo database. The terme uobject means Unity Object.
""",
- version=0.1
+ version=0.3
)
uobject = UObject(app)
@@ -60,61 +60,65 @@ uobject_model = api.model('UObject', {
})
-@api.route('/objects')
+@api.route('/<collections>')
class ObjectsList(Resource):
+ @api.doc(params={'collections': 'players'})
@api.response(404, 'No UObjects in collection.')
@api.marshal_list_with(uobject_model, mask=None)
- def get(self):
+ def get(self, collections):
""" Get uobjects list """
- return sanitize(uobject.all())
+ return sanitize(uobject.all(collections))
@api.expect(uobject_model)
+ @api.doc(params={'collections': 'players'})
@api.marshal_with(uobject_model, code=201, mask=None)
- def post(self):
+ def post(self, collections):
""" Register new uobject """
args = request.get_json(force=True)
- return uobject.register(args.get('datas')), 201
+ return uobject.register(collections, args.get('datas')), 201
-@api.route("/objects/<_id>")
+@api.route("/<collections>/<_id>")
class Objects(Resource):
@api.expect(uobject_model)
- @api.doc(params={'_id': '5d25a0f9e396fac104529444'})
+ @api.doc(params={'collections': 'players', '_id': '5d25a0f9e396fac104529444'})
@api.response(200, 'UObjects updated.')
@api.response(404, 'UObjects does not exist.')
@api.marshal_with(uobject_model, mask=None)
- def patch(self, _id):
+ def patch(self, collections, _id):
""" Edit an uobject. """
args = request.get_json(force=True)
- return uobject.update(_id, args.get('datas')),
+ return uobject.update(collections, _id, args.get('datas')),
- @api.doc(params={'_id': '5d244cc13f3d46cb739912ae'})
+ @api.doc(params={'collections': 'players', '_id': '5d244cc13f3d46cb739912ae'})
@api.response(200, 'UObjects deleted.')
@api.response(400, 'Something strange append, check msg value\
in response.')
@api.response(404, 'UObjects does not exist.')
@api.marshal_with(uobject_model, mask=None)
- def delete(self, _id):
+ def delete(self, collections, _id):
""" Remove an uobject """
- return uobject.remove(_id)
+ return uobject.remove(collections, _id)
-@api.route("/objects/<key>/<value>")
+@api.route("/<collections>/<key>/<value>")
class ObjectsEq(Resource):
@api.doc(params={
+ 'collections': 'players',
'key': 'kill or total.kill',
'value': '12',
})
@api.response(404, 'No UObjects in collection.')
@api.marshal_list_with(uobject_model, mask=None)
- def get(self, key, value):
+ def get(self, collections, key, value):
""" Get uobjects matching key/value """
- return sanitize(uobject.eq(key, value))
+ return sanitize(uobject.eq(collections, key, value))
-@api.route("/objects/reset")
+@api.route("/<collections>/reset")
class ObjectsClean(Resource):
- def get(self):
+ @api.doc(params={'collections': 'players'})
+ def get(self, collections):
""" Reset collection """
- uobject.reset()
+ uobject.reset(collections)
return "done"