Add get logged in user route

master
esensar 2018-09-15 14:36:11 +02:00
parent 8dc317396e
commit b81f9ea543
3 changed files with 41 additions and 2 deletions

View File

@ -13,7 +13,7 @@ public class StorageProperties {
private String location;
public String getLocation() {
return location;
return "/Users/ensar.sarajcic/Steleks";
}
public void setLocation(String location) {

View File

@ -27,7 +27,6 @@ public class AuthenticationController {
private TokenStore tokenStore;
@Autowired
public AuthenticationController(UsersJpaRepository usersJpaRepository, PasswordEncoder passwordEncoder, TokenStore tokenStore) {
this.usersJpaRepository = usersJpaRepository;
this.passwordEncoder = passwordEncoder;

View File

@ -0,0 +1,40 @@
package ba.steleks.controller;
import ba.steleks.model.User;
import ba.steleks.repository.UsersJpaRepository;
import ba.steleks.util.ProxyHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
@RestController
public class UserController {
private UsersJpaRepository usersJpaRepository;
@Autowired
public UserController(UsersJpaRepository usersJpaRepository) {
this.usersJpaRepository = usersJpaRepository;
}
@RequestMapping(path = "/users/current", method = RequestMethod.GET)
public ResponseEntity<?> getCurrentUser(@RequestHeader(ProxyHeaders.USER_ID) String userIdString) {
long userId = Long.parseLong(userIdString);
User user = usersJpaRepository.findOne(userId);
if (user != null) {
System.out.println("Found user with id: " + userId);
return ResponseEntity
.ok()
.body(user);
} else {
System.out.println("Found no user with id: " + userId);
return ResponseEntity
.status(HttpStatus.NOT_FOUND)
.build();
}
}
}