Add explicit return codes.

This commit is contained in:
Alexis Lahouze 2016-01-12 23:07:51 +01:00
parent a1d34c5f4e
commit 2e194fe550
3 changed files with 12 additions and 12 deletions

View File

@ -100,7 +100,7 @@ class AccountResource(Resource):
**kwargs **kwargs
).filter( ).filter(
Account.id == id Account.id == id
).one() ).one(), 200
except NoResultFound: except NoResultFound:
return None, 404 return None, 404
@ -127,7 +127,7 @@ class AccountResource(Resource):
# Return account with solds. # Return account with solds.
return Account.query().filter( return Account.query().filter(
Account.id == id Account.id == id
).one() ).one(), 200
@requires_auth @requires_auth
@marshal_with_field(Object(resource_fields)) @marshal_with_field(Object(resource_fields))
@ -166,7 +166,7 @@ class CategoriesResource(Resource):
def get(self): def get(self):
kwargs = range_parser.parse_args() kwargs = range_parser.parse_args()
return Operation.get_categories_for_range(**kwargs).all() return Operation.get_categories_for_range(**kwargs).all(), 200
ohlc_resource_fields = { ohlc_resource_fields = {
@ -184,7 +184,7 @@ class SoldsResource(Resource):
def get(self): def get(self):
kwargs = range_parser.parse_args() kwargs = range_parser.parse_args()
return Operation.get_ohlc_per_day_for_range(**kwargs).all() return Operation.get_ohlc_per_day_for_range(**kwargs).all(), 200
api_api.add_resource(CategoriesResource, "/categories") api_api.add_resource(CategoriesResource, "/categories")

View File

@ -74,7 +74,7 @@ class OperationListResource(Resource):
end=kwargs['end'], end=kwargs['end'],
).filter( ).filter(
Operation.account_id == kwargs['account'] Operation.account_id == kwargs['account']
).all() ).all(), 200
@requires_auth @requires_auth
@marshal_with_field(Object(resource_fields)) @marshal_with_field(Object(resource_fields))
@ -85,7 +85,7 @@ class OperationListResource(Resource):
db.session.add(operation) db.session.add(operation)
return operation return operation, 201
class OperationResource(Resource): class OperationResource(Resource):
@ -100,7 +100,7 @@ class OperationResource(Resource):
if not operation: if not operation:
return None, 404 return None, 404
return operation return operation, 200
@requires_auth @requires_auth
@marshal_with_field(Object(resource_fields)) @marshal_with_field(Object(resource_fields))
@ -121,7 +121,7 @@ class OperationResource(Resource):
db.session.merge(operation) db.session.merge(operation)
return operation return operation, 200
@requires_auth @requires_auth
@marshal_with_field(Object(resource_fields)) @marshal_with_field(Object(resource_fields))
@ -133,7 +133,7 @@ class OperationResource(Resource):
db.session.delete(operation) db.session.delete(operation)
return operation return None, 204
api_api.add_resource(OperationListResource, "/operations") api_api.add_resource(OperationListResource, "/operations")

View File

@ -69,7 +69,7 @@ class ScheduledOperationListResource(Resource):
return ScheduledOperation.query().filter( return ScheduledOperation.query().filter(
ScheduledOperation.account_id == kwargs.account ScheduledOperation.account_id == kwargs.account
).all() ).all(), 200
@marshal_with_field(Object(resource_fields)) @marshal_with_field(Object(resource_fields))
def post(self): def post(self):
@ -98,7 +98,7 @@ class ScheduledOperationResource(Resource):
try: try:
return ScheduledOperation.query().filter( return ScheduledOperation.query().filter(
ScheduledOperation.id == id ScheduledOperation.id == id
).one() ).one(), 200
except NoResultFound: except NoResultFound:
return None, 404 return None, 404
@ -129,7 +129,7 @@ class ScheduledOperationResource(Resource):
db.session.flush() db.session.flush()
return scheduled_operation return scheduled_operation, 200
@marshal_with_field(Object(resource_fields)) @marshal_with_field(Object(resource_fields))
def delete(self, id): def delete(self, id):