Add get account fake endpoint
parent
f506e3dfaa
commit
145ca339c9
|
@ -32,10 +32,11 @@ class ProtectedResource(Resource):
|
||||||
|
|
||||||
|
|
||||||
def add_resources():
|
def add_resources():
|
||||||
from .resources.account import AccountResource
|
from .resources.account import AccountResource, AccountListResource
|
||||||
from .resources.token import TokenResource
|
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')
|
api.add_resource(TokenResource, '/v1/token')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,30 @@
|
||||||
from flask_restful import Resource, abort
|
from flask_restful import Resource, abort
|
||||||
|
from flask import g
|
||||||
from webargs import fields
|
from webargs import fields
|
||||||
from webargs.flaskparser import use_args
|
from webargs.flaskparser import use_args
|
||||||
from flasgger import swag_from
|
from flasgger import swag_from
|
||||||
import app.accounts as accounts
|
import app.accounts as accounts
|
||||||
from app.api import protected
|
from app.api import ProtectedResource, protected
|
||||||
|
|
||||||
|
user_args = {
|
||||||
class AccountResource(Resource):
|
|
||||||
user_args = {
|
|
||||||
'user': fields.Nested({
|
'user': fields.Nested({
|
||||||
'username': fields.Str(required=True),
|
'username': fields.Str(required=True),
|
||||||
'email': fields.Email(required=True),
|
'email': fields.Email(required=True),
|
||||||
'password': fields.Str(required=True)
|
'password': fields.Str(required=True)
|
||||||
}, required=True, location='json')
|
}, 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)
|
@use_args(user_args)
|
||||||
@swag_from('swagger/create_account_spec.yaml')
|
@swag_from('swagger/create_account_spec.yaml')
|
||||||
def post(self, args):
|
def post(self, args):
|
||||||
|
@ -30,6 +40,5 @@ class AccountResource(Resource):
|
||||||
abort(422, message='Account already exists', status='error')
|
abort(422, message='Account already exists', status='error')
|
||||||
|
|
||||||
@protected
|
@protected
|
||||||
@swag_from('swagger/get_account_spec.yaml')
|
|
||||||
def get(self):
|
def get(self):
|
||||||
return '', 200
|
return '', 200
|
||||||
|
|
Loading…
Reference in New Issue