Add get account fake endpoint
parent
f506e3dfaa
commit
145ca339c9
|
@ -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')
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
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': fields.Nested({
|
||||
'username': fields.Str(required=True),
|
||||
|
@ -15,6 +14,17 @@ class AccountResource(Resource):
|
|||
}, 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
|
||||
|
|
Loading…
Reference in New Issue