From 2e194fe55077262f8807da0a92cb46ed01f6a303 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Tue, 12 Jan 2016 23:07:51 +0100 Subject: [PATCH] Add explicit return codes. --- accountant/api/views/accounts.py | 8 ++++---- accountant/api/views/operations.py | 10 +++++----- accountant/api/views/scheduled_operations.py | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/accountant/api/views/accounts.py b/accountant/api/views/accounts.py index 1eebb9c..c805f99 100644 --- a/accountant/api/views/accounts.py +++ b/accountant/api/views/accounts.py @@ -100,7 +100,7 @@ class AccountResource(Resource): **kwargs ).filter( Account.id == id - ).one() + ).one(), 200 except NoResultFound: return None, 404 @@ -127,7 +127,7 @@ class AccountResource(Resource): # Return account with solds. return Account.query().filter( Account.id == id - ).one() + ).one(), 200 @requires_auth @marshal_with_field(Object(resource_fields)) @@ -166,7 +166,7 @@ class CategoriesResource(Resource): def get(self): 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 = { @@ -184,7 +184,7 @@ class SoldsResource(Resource): def get(self): 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") diff --git a/accountant/api/views/operations.py b/accountant/api/views/operations.py index 196a22e..36cea7d 100644 --- a/accountant/api/views/operations.py +++ b/accountant/api/views/operations.py @@ -74,7 +74,7 @@ class OperationListResource(Resource): end=kwargs['end'], ).filter( Operation.account_id == kwargs['account'] - ).all() + ).all(), 200 @requires_auth @marshal_with_field(Object(resource_fields)) @@ -85,7 +85,7 @@ class OperationListResource(Resource): db.session.add(operation) - return operation + return operation, 201 class OperationResource(Resource): @@ -100,7 +100,7 @@ class OperationResource(Resource): if not operation: return None, 404 - return operation + return operation, 200 @requires_auth @marshal_with_field(Object(resource_fields)) @@ -121,7 +121,7 @@ class OperationResource(Resource): db.session.merge(operation) - return operation + return operation, 200 @requires_auth @marshal_with_field(Object(resource_fields)) @@ -133,7 +133,7 @@ class OperationResource(Resource): db.session.delete(operation) - return operation + return None, 204 api_api.add_resource(OperationListResource, "/operations") diff --git a/accountant/api/views/scheduled_operations.py b/accountant/api/views/scheduled_operations.py index 8b487ba..1f6ff77 100644 --- a/accountant/api/views/scheduled_operations.py +++ b/accountant/api/views/scheduled_operations.py @@ -69,7 +69,7 @@ class ScheduledOperationListResource(Resource): return ScheduledOperation.query().filter( ScheduledOperation.account_id == kwargs.account - ).all() + ).all(), 200 @marshal_with_field(Object(resource_fields)) def post(self): @@ -98,7 +98,7 @@ class ScheduledOperationResource(Resource): try: return ScheduledOperation.query().filter( ScheduledOperation.id == id - ).one() + ).one(), 200 except NoResultFound: return None, 404 @@ -129,7 +129,7 @@ class ScheduledOperationResource(Resource): db.session.flush() - return scheduled_operation + return scheduled_operation, 200 @marshal_with_field(Object(resource_fields)) def delete(self, id):