Skip to content
Snippets Groups Projects
Commit b041df03 authored by Luke O'mahony's avatar Luke O'mahony
Browse files

upd: added react friendly return

parent 4a37c80d
Branches
No related merge requests found
......@@ -7,6 +7,8 @@ import com.backend.glowhouse.model.response.UserSummary;
import com.backend.glowhouse.model.User;
import com.backend.glowhouse.repository.UserRepository;
import com.backend.glowhouse.security.UserPrincipal;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -17,16 +19,19 @@ import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api")
public class UserController {
ObjectMapper mapper = new ObjectMapper();
@Autowired
private UserRepository userRepository;
private static final Logger logger = LoggerFactory.getLogger(UserController.class);
@GetMapping("/user/me")
@GetMapping("/user/details")
@PreAuthorize("hasRole('USER')")
public UserSummary getCurrentUser(@AuthenticationPrincipal UserPrincipal currentUser) {
return new UserSummary(currentUser.getId(), currentUser.getUsername(), currentUser.getName());
public String getCurrentUserDetails(@AuthenticationPrincipal UserPrincipal currentUser) throws JsonProcessingException {
UserSummary userSummary = new UserSummary(currentUser.getId(), currentUser.getUsername(), currentUser.getName());
return mapper.writeValueAsString(userSummary);
}
@GetMapping("/user/checkUsernameAvailability")
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment