Rename resource_fields in model. Rename resource classes.
This commit is contained in:
parent
6ee46c9136
commit
cc6f7e2a36
@ -32,7 +32,7 @@ from ..fields import Object
|
||||
from .users import requires_auth
|
||||
|
||||
|
||||
resource_fields = {
|
||||
account_model = {
|
||||
'id': fields.Integer(default=None),
|
||||
'name': fields.String,
|
||||
'authorized_overdraft': fields.Float,
|
||||
@ -58,7 +58,7 @@ date_parser.add_argument('end',
|
||||
|
||||
class AccountListResource(Resource):
|
||||
@requires_auth
|
||||
@marshal_with_field(fields.List(Object(resource_fields)))
|
||||
@marshal_with_field(fields.List(Object(account_model)))
|
||||
def get(self):
|
||||
"""
|
||||
Returns accounts with their balances.
|
||||
@ -66,7 +66,7 @@ class AccountListResource(Resource):
|
||||
return Account.query().all(), 200
|
||||
|
||||
@requires_auth
|
||||
@marshal_with_field(Object(resource_fields))
|
||||
@marshal_with_field(Object(account_model))
|
||||
def post(self):
|
||||
"""
|
||||
Create a new account.
|
||||
@ -88,7 +88,7 @@ class AccountListResource(Resource):
|
||||
|
||||
class AccountResource(Resource):
|
||||
@requires_auth
|
||||
@marshal_with_field(Object(resource_fields))
|
||||
@marshal_with_field(Object(account_model))
|
||||
def get(self, id):
|
||||
"""
|
||||
Get account.
|
||||
@ -105,7 +105,7 @@ class AccountResource(Resource):
|
||||
return None, 404
|
||||
|
||||
@requires_auth
|
||||
@marshal_with_field(Object(resource_fields))
|
||||
@marshal_with_field(Object(account_model))
|
||||
def post(self, id):
|
||||
data = parser.parse_args()
|
||||
|
||||
@ -130,7 +130,7 @@ class AccountResource(Resource):
|
||||
).one(), 200
|
||||
|
||||
@requires_auth
|
||||
@marshal_with_field(Object(resource_fields))
|
||||
@marshal_with_field(Object(account_model))
|
||||
def delete(self, id):
|
||||
# Need to get the object to update it.
|
||||
account = db.session.query(Account).get(id)
|
||||
@ -153,23 +153,23 @@ range_parser.add_argument('begin', type=lambda a: dateutil.parser.parse(a))
|
||||
range_parser.add_argument('end', type=lambda a: dateutil.parser.parse(a))
|
||||
|
||||
|
||||
category_resource_fields = {
|
||||
category_model = {
|
||||
'category': fields.String,
|
||||
'expenses': fields.Float,
|
||||
'revenues': fields.Float
|
||||
}
|
||||
|
||||
|
||||
class CategoriesResource(Resource):
|
||||
class CategoryResource(Resource):
|
||||
@requires_auth
|
||||
@marshal_with_field(fields.List(Object(category_resource_fields)))
|
||||
@marshal_with_field(fields.List(Object(category_model)))
|
||||
def get(self):
|
||||
data = range_parser.parse_args()
|
||||
|
||||
return Operation.get_categories_for_range(**data).all(), 200
|
||||
|
||||
|
||||
ohlc_resource_fields = {
|
||||
ohlc_model = {
|
||||
'operation_date': fields.DateTime(dt_format='iso8601'),
|
||||
'open': fields.Float,
|
||||
'high': fields.Float,
|
||||
@ -178,14 +178,13 @@ ohlc_resource_fields = {
|
||||
}
|
||||
|
||||
|
||||
class SoldsResource(Resource):
|
||||
class OHLCResource(Resource):
|
||||
@requires_auth
|
||||
@marshal_with_field(fields.List(Object(ohlc_resource_fields)))
|
||||
def get(self):
|
||||
data = range_parser.parse_args()
|
||||
|
||||
return Operation.get_ohlc_per_day_for_range(**data).all(), 200
|
||||
|
||||
|
||||
api.add_resource(CategoriesResource, "/categories")
|
||||
api.add_resource(SoldsResource, "/solds")
|
||||
api.add_resource(CategoryResource, "/categories")
|
||||
api.add_resource(OHLCResource, "/solds")
|
||||
|
Loading…
Reference in New Issue
Block a user