Move some resources from operations to account.
This commit is contained in:
parent
ba665923f6
commit
7d9b94bc80
@ -25,6 +25,7 @@ from accountant import db
|
|||||||
from .. import api_api
|
from .. import api_api
|
||||||
|
|
||||||
from ..models.accounts import Account
|
from ..models.accounts import Account
|
||||||
|
from ..models.operations import Operation
|
||||||
|
|
||||||
from ..fields import Object
|
from ..fields import Object
|
||||||
|
|
||||||
@ -150,3 +151,47 @@ class AccountResource(Resource):
|
|||||||
|
|
||||||
api_api.add_resource(AccountListResource, '/accounts')
|
api_api.add_resource(AccountListResource, '/accounts')
|
||||||
api_api.add_resource(AccountResource, '/accounts/<int:account_id>')
|
api_api.add_resource(AccountResource, '/accounts/<int:account_id>')
|
||||||
|
|
||||||
|
|
||||||
|
range_parser = reqparse.RequestParser()
|
||||||
|
range_parser.add_argument('account', type=int)
|
||||||
|
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': fields.String,
|
||||||
|
'expenses': fields.Float,
|
||||||
|
'revenues': fields.Float
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class CategoriesResource(Resource):
|
||||||
|
@requires_auth
|
||||||
|
@marshal_with_field(fields.List(Object(category_resource_fields)))
|
||||||
|
def get(self):
|
||||||
|
kwargs = range_parser.parse_args()
|
||||||
|
|
||||||
|
return Operation.get_categories_for_range(**kwargs).all()
|
||||||
|
|
||||||
|
|
||||||
|
ohlc_resource_fields = {
|
||||||
|
'operation_date': fields.DateTime(dt_format='iso8601'),
|
||||||
|
'open': fields.Float,
|
||||||
|
'high': fields.Float,
|
||||||
|
'low': fields.Float,
|
||||||
|
'close': fields.Float
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class SoldsResource(Resource):
|
||||||
|
@requires_auth
|
||||||
|
@marshal_with_field(fields.List(Object(ohlc_resource_fields)))
|
||||||
|
def get(self):
|
||||||
|
kwargs = range_parser.parse_args()
|
||||||
|
|
||||||
|
return Operation.get_ohlc_per_day_for_range(**kwargs).all()
|
||||||
|
|
||||||
|
|
||||||
|
api_api.add_resource(CategoriesResource, "/categories")
|
||||||
|
api_api.add_resource(SoldsResource, "/solds")
|
||||||
|
@ -136,41 +136,5 @@ class OperationResource(Resource):
|
|||||||
return operation
|
return operation
|
||||||
|
|
||||||
|
|
||||||
category_resource_fields = {
|
|
||||||
'category': fields.String,
|
|
||||||
'expenses': fields.Float,
|
|
||||||
'revenues': fields.Float
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class CategoriesResource(Resource):
|
|
||||||
@requires_auth
|
|
||||||
@marshal_with_field(fields.List(Object(category_resource_fields)))
|
|
||||||
def get(self):
|
|
||||||
kwargs = range_parser.parse_args()
|
|
||||||
|
|
||||||
return Operation.get_categories_for_range(**kwargs).all()
|
|
||||||
|
|
||||||
|
|
||||||
ohlc_resource_fields = {
|
|
||||||
'operation_date': fields.DateTime(dt_format='iso8601'),
|
|
||||||
'open': fields.Float,
|
|
||||||
'high': fields.Float,
|
|
||||||
'low': fields.Float,
|
|
||||||
'close': fields.Float
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class SoldsResource(Resource):
|
|
||||||
@requires_auth
|
|
||||||
@marshal_with_field(fields.List(Object(ohlc_resource_fields)))
|
|
||||||
def get(self):
|
|
||||||
kwargs = range_parser.parse_args()
|
|
||||||
|
|
||||||
return Operation.get_ohlc_per_day_for_range(**kwargs).all()
|
|
||||||
|
|
||||||
|
|
||||||
api_api.add_resource(OperationListResource, "/operations")
|
api_api.add_resource(OperationListResource, "/operations")
|
||||||
api_api.add_resource(OperationResource, "/operations/<int:operation_id>")
|
api_api.add_resource(OperationResource, "/operations/<int:operation_id>")
|
||||||
api_api.add_resource(CategoriesResource, "/categories")
|
|
||||||
api_api.add_resource(SoldsResource, "/solds")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user