GUAC-1126 Add caching of GET requests in REST API services.

This commit is contained in:
James Muehlner
2015-04-08 22:35:18 -07:00
parent 5eb4ab99c6
commit 91b0d72a60
6 changed files with 165 additions and 24 deletions

View File

@@ -26,13 +26,14 @@
angular.module('rest').factory('userService', ['$injector',
function userService($injector) {
// Required services
var $http = $injector.get('$http');
var authenticationService = $injector.get('authenticationService');
var cacheService = $injector.get('cacheService');
// Get required types
var UserPasswordUpdate = $injector.get("UserPasswordUpdate");
// Get required services
var $http = $injector.get("$http");
var authenticationService = $injector.get("authenticationService");
var service = {};
/**
@@ -63,6 +64,7 @@ angular.module('rest').factory('userService', ['$injector',
// Retrieve users
return $http({
cache : cacheService.users,
method : 'GET',
url : 'api/users',
params : httpParameters
@@ -90,6 +92,7 @@ angular.module('rest').factory('userService', ['$injector',
// Retrieve user
return $http({
cache : cacheService.users,
method : 'GET',
url : 'api/users/' + encodeURIComponent(username),
params : httpParameters
@@ -115,13 +118,19 @@ angular.module('rest').factory('userService', ['$injector',
token : authenticationService.getCurrentToken()
};
// Retrieve user
// Delete user
return $http({
method : 'DELETE',
url : 'api/users/' + encodeURIComponent(user.username),
params : httpParameters
})
// Clear the cache
.success(function userDeleted(){
cacheService.users.removeAll();
});
};
/**
@@ -142,12 +151,17 @@ angular.module('rest').factory('userService', ['$injector',
token : authenticationService.getCurrentToken()
};
// Retrieve user
// Create user
return $http({
method : 'POST',
url : 'api/users',
params : httpParameters,
data : user
})
// Clear the cache
.success(function userCreated(){
cacheService.users.removeAll();
});
};
@@ -170,12 +184,17 @@ angular.module('rest').factory('userService', ['$injector',
token : authenticationService.getCurrentToken()
};
// Retrieve user
// Update user
return $http({
method : 'PUT',
url : 'api/users/' + encodeURIComponent(user.username),
params : httpParameters,
data : user
})
// Clear the cache
.success(function userUpdated(){
cacheService.users.removeAll();
});
};
@@ -205,7 +224,7 @@ angular.module('rest').factory('userService', ['$injector',
token : authenticationService.getCurrentToken()
};
// Retrieve user
// Update user password
return $http({
method : 'PUT',
url : 'api/users/' + encodeURIComponent(username) + '/password',
@@ -214,6 +233,11 @@ angular.module('rest').factory('userService', ['$injector',
oldPassword : oldPassword,
newPassword : newPassword
})
})
// Clear the cache
.success(function passwordChanged(){
cacheService.users.removeAll();
});
};