Add get account fake endpoint

master
esensar 2018-05-08 10:52:36 +02:00
parent f506e3dfaa
commit 145ca339c9
2 changed files with 22 additions and 12 deletions

View File

@ -32,10 +32,11 @@ class ProtectedResource(Resource):
def add_resources():
from .resources.account import AccountResource
from .resources.account import AccountResource, AccountListResource
from .resources.token import TokenResource
api.add_resource(AccountResource, '/v1/accounts')
api.add_resource(AccountResource, '/v1/accounts/<int:account_id>')
api.add_resource(AccountListResource, '/v1/accounts')
api.add_resource(TokenResource, '/v1/token')

View File

@ -1,20 +1,30 @@
from flask_restful import Resource, abort
from flask import g
from webargs import fields
from webargs.flaskparser import use_args
from flasgger import swag_from
import app.accounts as accounts
from app.api import protected
from app.api import ProtectedResource, protected
class AccountResource(Resource):
user_args = {
user_args = {
'user': fields.Nested({
'username': fields.Str(required=True),
'email': fields.Email(required=True),
'password': fields.Str(required=True)
}, required=True, location='json')
}
}
class AccountResource(ProtectedResource):
@swag_from('swagger/get_account_spec.yaml')
def get(self, account_id):
if g.current_account.id == account_id:
return g.current_account, 200
abort(403, message='You can only get your own account', status='error')
class AccountListResource(Resource):
@use_args(user_args)
@swag_from('swagger/create_account_spec.yaml')
def post(self, args):
@ -30,6 +40,5 @@ class AccountResource(Resource):
abort(422, message='Account already exists', status='error')
@protected
@swag_from('swagger/get_account_spec.yaml')
def get(self):
return '', 200