diff --git a/backend/src/main/java/com/group1/cuisines/controllers/UserController.java b/backend/src/main/java/com/group1/cuisines/controllers/UserController.java index 2b6dba8d..ddd3fd71 100644 --- a/backend/src/main/java/com/group1/cuisines/controllers/UserController.java +++ b/backend/src/main/java/com/group1/cuisines/controllers/UserController.java @@ -45,20 +45,16 @@ public ResponseEntity getUserById(@PathVariable Integer userId, Authenticatio @GetMapping("/me") public ResponseEntity getUserDetails(@AuthenticationPrincipal UserDetails userDetails) { - if (userDetails instanceof com.group1.cuisines.entities.User) { - User user = (User) userDetails; - Map userInfo = new HashMap<>(); - userInfo.put("username", user.getUsername()); - userInfo.put("email", user.getEmail()); - userInfo.put("bio", user.getBio()); - userInfo.put("country", user.getCountry()); - - return ResponseEntity.ok(userInfo); + if (userDetails != null) { + User user = userRepository.findByUsername(userDetails.getUsername()).orElse(null); + if (user != null) { + UserProfileDto userProfile = userService.getUserProfileById(user.getId(), userDetails.getUsername()); + return ResponseEntity.ok(new SuccessResponse<>(200,userProfile, "User profile fetched successfully")); + } } - return ResponseEntity.status(HttpStatus.FORBIDDEN).body("User not authenticated"); - } + @DeleteMapping("/{userId}/unfollow") public ResponseEntity unfollowUser(@PathVariable Integer userId) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication();