I am trying to download $ scope.projects specific to registered users. REST side api
@RequestMapping(value = "/users/{id}/projects", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<Project>> getAllProjects(@PathVariable("id") String id,
HttpServletResponse response)
throws URISyntaxException {
log.debug("REST request to get User : {}", id);
User user = userRepository.findOneByLogin(id);
if (user == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
List<Project> page = projectRepository.findByUserIsCurrentUser();
return new ResponseEntity<List<Project>>(page,
HttpStatus.OK);
}
Checked this with a swagger client.
angular.module('tfmappApp')
.factory('UserProject', function ($resource) {
return $resource('api/users/:id/projects', {}, {
'query': {method: 'GET', isArray: true, params: { id: '@login'}},
'get': {
method: 'GET',
transformResponse: function (data) {
data = angular.fromJson(data);
return data;
}
}
});
});
angular.module('tfmappApp')
.controller('ProjectController', function ($scope, Principal, Project, User, UserProject, ParseLinks) {
$scope.projects = [];
$scope.page = 1;
Principal.identity().then(function(account) {
$scope.account = account;
$scope.isAuthenticated = Principal.isAuthenticated;
});
$scope.loadAll = function() {
$scope.projects = UserProject.query({id: $scope.account.login});
};
$scope.loadPage = function(page) {
$scope.page = page;
$scope.loadAll();
};
$scope.loadAll();});
The main service is Jhipster. The code below does not work, or I'm missing something.
Principal.identity().then(function(account) {
$scope.account = account;
$scope.isAuthenticated = Principal.isAuthenticated;
});
How can I get the current user?
What is the correct way to get an account or principal or user who is currently registered?
I am using HTTP session authentication with Jhipster.
source
share