diff --git a/accountant/api/views/accounts.py b/accountant/api/views/accounts.py index 66556a9..1aa8dd0 100644 --- a/accountant/api/views/accounts.py +++ b/accountant/api/views/accounts.py @@ -143,8 +143,8 @@ class AccountResource(Resource): return None, 204 -api.add_resource(AccountListResource, '/accounts') -api.add_resource(AccountResource, '/accounts/') +api.add_resource(AccountListResource, '/account') +api.add_resource(AccountResource, '/account/') range_parser = reqparse.RequestParser() @@ -163,10 +163,10 @@ category_model = { class CategoryResource(Resource): @requires_auth @marshal_with_field(fields.List(Object(category_model))) - def get(self): + def get(self, id): data = range_parser.parse_args() - return Operation.get_categories_for_range(**data).all(), 200 + return Operation.get_categories_for_range(id, **data).all() ohlc_model = { @@ -181,11 +181,11 @@ ohlc_model = { class OHLCResource(Resource): @requires_auth @marshal_with_field(fields.List(Object(ohlc_model))) - def get(self): + def get(self, id): data = range_parser.parse_args() - return Operation.get_ohlc_per_day_for_range(**data).all(), 200 + return Operation.get_ohlc_per_day_for_range(id, **data).all() -api.add_resource(CategoryResource, "/categories") -api.add_resource(OHLCResource, "/solds") +api.add_resource(CategoryResource, "/account//categories") +api.add_resource(OHLCResource, "/account//solds") diff --git a/accountant/api/views/operations.py b/accountant/api/views/operations.py index f8e0026..4182bd9 100644 --- a/accountant/api/views/operations.py +++ b/accountant/api/views/operations.py @@ -136,5 +136,5 @@ class OperationResource(Resource): return None, 204 -api.add_resource(OperationListResource, "/operations") -api.add_resource(OperationResource, "/operations/") +api.add_resource(OperationListResource, "/operation") +api.add_resource(OperationResource, "/operation/") diff --git a/accountant/api/views/scheduled_operations.py b/accountant/api/views/scheduled_operations.py index 21895df..0108bf0 100644 --- a/accountant/api/views/scheduled_operations.py +++ b/accountant/api/views/scheduled_operations.py @@ -168,6 +168,6 @@ class ScheduledOperationResource(Resource): return None, 204 -api.add_resource(ScheduledOperationListResource, "/scheduled_operations") +api.add_resource(ScheduledOperationListResource, "/scheduled_operation") api.add_resource(ScheduledOperationResource, - "/scheduled_operations/") + "/scheduled_operation/") diff --git a/accountant/api/views/users.py b/accountant/api/views/users.py index f044926..187d73b 100644 --- a/accountant/api/views/users.py +++ b/accountant/api/views/users.py @@ -126,4 +126,4 @@ class LoginResource(Resource): return g.user -api.add_resource(LoginResource, "/users/login") +api.add_resource(LoginResource, "/user/login") diff --git a/accountant/frontend/static/js/accounts.js b/accountant/frontend/static/js/accounts.js index e0691b9..066885d 100644 --- a/accountant/frontend/static/js/accounts.js +++ b/accountant/frontend/static/js/accounts.js @@ -20,7 +20,7 @@ accountantApp .factory("Account", ["$resource", function($resource) { return $resource( - "/api/accounts/:id", { + "/api/account/:id", { id: "@id" } ); diff --git a/accountant/frontend/static/js/app.js b/accountant/frontend/static/js/app.js index 3d303e7..e50d87f 100644 --- a/accountant/frontend/static/js/app.js +++ b/accountant/frontend/static/js/app.js @@ -123,7 +123,7 @@ var accountantApp = angular.module("accountantApp", [ var email = $('#email').val(); var password = $('#password').val(); $http.post( - "/api/users/login", + "/api/user/login", { "email": email, "password": password diff --git a/accountant/frontend/static/js/operations.js b/accountant/frontend/static/js/operations.js index 7c7da8d..f0a31be 100644 --- a/accountant/frontend/static/js/operations.js +++ b/accountant/frontend/static/js/operations.js @@ -19,19 +19,37 @@ accountantApp .factory("Operation", [ "$resource", function($resource) { return $resource( - "/api/operations/:id", { + "/api/operation/:id", { id: "@id" } ); }]) +.factory("OHLC", [ "$resource", "$routeParams", + function($resource, $routeParams) { + return $resource( + "/api/account/:account_id/ohlc", { + account_id: $routeParams.accountId + } + ); +}]) + +.factory("Category", [ "$resource", "$routeParams", + function($resource, $routeParams) { + return $resource( + "/api/account/:account_id/category", { + account_id: $routeParams.accountId + } + ); +}]) + /* * Controller for category chart. */ .controller( "CategoryChartController", [ - "$rootScope", "$scope", "$http", "$routeParams", - function($rootScope, $scope, $http, $routeParams) { + "$rootScope", "$scope", "$http", "$routeParams", "Category", + function($rootScope, $scope, $http, $routeParams, Category) { var colors = Highcharts.getOptions().colors; $scope.revenueColor = colors[2]; @@ -101,13 +119,10 @@ accountantApp $scope.load = function(begin, end) { $scope.config.loading = true; - $http.get("/api/categories", { - params: { - account: $routeParams.accountId, + Category.query({ begin: begin.format('YYYY-MM-DD'), end: end.format('YYYY-MM-DD') - } - }).success(function(data) { + }, function(data) { var expenses = [], revenues = []; var expenseColor = $scope.brightenColor($scope.expenseColor); @@ -138,7 +153,7 @@ accountantApp * Get account status. */ $scope.getAccountStatus = function(begin, end) { - $http.get("/api/accounts/" + $routeParams.accountId, { + $http.get("/api/account/" + $routeParams.accountId, { params: { begin: begin.format('YYYY-MM-DD'), end: end.format('YYYY-MM-DD') @@ -176,8 +191,8 @@ accountantApp */ .controller( "SoldChartController", [ - "$rootScope", "$scope", "$http", "$routeParams", - function($rootScope, $scope, $http, $routeParams) { + "$rootScope", "$scope", "$http", "OHLC", + function($rootScope, $scope, $http, OHLC) { // Configure chart for operations. $scope.config = { options: { @@ -271,11 +286,7 @@ accountantApp $scope.loadSolds = function() { $scope.config.loading = true; - $http.get("/api/solds", { - params: { - account: $routeParams.accountId, - } - }).success(function(data) { + OHLC.query({}, function(data) { $scope.config.series[0].data = []; angular.forEach(data, function(operation) { diff --git a/accountant/frontend/static/js/scheduler.js b/accountant/frontend/static/js/scheduler.js index 97d712b..2f18cc5 100644 --- a/accountant/frontend/static/js/scheduler.js +++ b/accountant/frontend/static/js/scheduler.js @@ -18,7 +18,7 @@ accountantApp .factory("ScheduledOperation", ["$resource", function($resource) { return $resource( - "/api/scheduled_operations/:id", { + "/api/scheduled_operation/:id", { id: "@id" } );