From a66d1d83371a504b4dc7c89704520ffc670089b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atakan=20Ya=C5=9Far?= Date: Wed, 15 May 2024 14:34:26 +0300 Subject: [PATCH] feat(backend): detailed my profile page --- .../cuisines/controllers/UserController.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) 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();