Skip to content

Commit

Permalink
feat(backend): detailed my profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
atakanyasar committed May 15, 2024
1 parent bf91f52 commit a66d1d8
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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();
Expand Down

0 comments on commit a66d1d8

Please sign in to comment.