From 68ef14447445bb6ba9ef73da5d83108395f93eff Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Mon, 15 Jun 2015 13:06:32 +0200 Subject: [PATCH] Add view to get categories with their expenses and revenues. --- accountant/api/views/entries.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/accountant/api/views/entries.py b/accountant/api/views/entries.py index 0bdff97..a5d0062 100644 --- a/accountant/api/views/entries.py +++ b/accountant/api/views/entries.py @@ -130,5 +130,22 @@ class EntryResource(Resource): return entry +category_resource_fields = { + 'category': fields.String, + 'expenses': fields.Float, + 'revenues': fields.Float +} + + +class CategoriesResource(Resource): + @session_aware + @marshal_with_field(fields.List(Object(category_resource_fields))) + def get(self, session): + kwargs = range_parser.parse_args() + + return Operation.get_categories_for_range(session, **kwargs) + + api_api.add_resource(EntryListResource, "/entries") api_api.add_resource(EntryResource, "/entries/") +api_api.add_resource(CategoriesResource, "/categories")