aboutsummaryrefslogtreecommitdiff
path: root/src/lb_app/api.py
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2018-06-16 17:52:31 +0200
committerneodarz <neodarz@neodarz.net>2018-06-16 17:52:31 +0200
commit5bcc1ed9df4e7a6b8086cac3f25a466aee3bebcd (patch)
treef4e72ed3712a148a28a0c11323f1796f7499a336 /src/lb_app/api.py
parentcf29b5d4324b03d826615cfbb7f7345c54da1762 (diff)
downloadliberationCenter-5bcc1ed9df4e7a6b8086cac3f25a466aee3bebcd.tar.xz
liberationCenter-5bcc1ed9df4e7a6b8086cac3f25a466aee3bebcd.zip
Add first structure of the application
Diffstat (limited to 'src/lb_app/api.py')
-rw-r--r--src/lb_app/api.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/lb_app/api.py b/src/lb_app/api.py
new file mode 100644
index 0000000..6dfe2e8
--- /dev/null
+++ b/src/lb_app/api.py
@@ -0,0 +1,43 @@
+from flask import (Flask, Blueprint, g, redirect, request, session, jsonify, url_for)
+from flask_restplus import Resource, Api, fields
+
+from bson.json_util import dumps
+from json import loads
+
+from .app_db.user import User
+
+app = Flask(__name__, instance_relative_config=True)
+
+bp = Blueprint('api', __name__, url_prefix='/api')
+
+env = app.config['DEBUG']
+
+if env is not False:
+ env = '/doc'
+
+api = Api(bp, doc=env)
+
+user = User(app)
+
+user_model = api.model('User', {
+ 'username': fields.String(required=True, description='Username of account', example='Jean')
+})
+
+@api.route('/users', endpoint='users')
+class Users(Resource):
+ def get(self):
+ """ Get user list """
+ return loads(dumps(user.all()))
+
+
+@api.route('/user/register')
+class Register(Resource):
+ @api.expect(user_model)
+ def post(self):
+ """ Register new user """
+ args = request.get_json(force=True)
+ status = user.register(args.get('username'))
+
+ if status is None:
+ return loads('{"msg": "done"}'), 201
+ return loads('{"msg": "'+status+'"}'), 200