Add get logged in user route
parent
8dc317396e
commit
b81f9ea543
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue