From 7aeb4e8d93b29d72640148b1a39854d4959ca16e Mon Sep 17 00:00:00 2001 From: Halis Bal Date: Sun, 26 Nov 2023 16:41:52 +0300 Subject: [PATCH] get endpoint for the profile updated for searching by the user id --- .../com/app/gamereview/controller/ProfileController.java | 4 ++-- .../java/com/app/gamereview/service/ProfileService.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/backend/src/main/java/com/app/gamereview/controller/ProfileController.java b/app/backend/src/main/java/com/app/gamereview/controller/ProfileController.java index 18328f70..058336ef 100644 --- a/app/backend/src/main/java/com/app/gamereview/controller/ProfileController.java +++ b/app/backend/src/main/java/com/app/gamereview/controller/ProfileController.java @@ -41,12 +41,12 @@ public ResponseEntity> getReviews(@RequestHea } @PostMapping("/get") - public ResponseEntity getProfile(@RequestParam String id, @RequestHeader(name = HttpHeaders.AUTHORIZATION, required = false) String Authorization) { + public ResponseEntity getProfile(@RequestParam String userId, @RequestHeader(name = HttpHeaders.AUTHORIZATION, required = false) String Authorization) { String email; if (JwtUtil.validateToken(Authorization)) email = JwtUtil.extractSubject(Authorization); else email = ""; - ProfilePageResponseDto profile = profileService.getProfile(id, email); + ProfilePageResponseDto profile = profileService.getProfile(userId, email); return ResponseEntity.ok(profile); } diff --git a/app/backend/src/main/java/com/app/gamereview/service/ProfileService.java b/app/backend/src/main/java/com/app/gamereview/service/ProfileService.java index 31792300..683f8c62 100644 --- a/app/backend/src/main/java/com/app/gamereview/service/ProfileService.java +++ b/app/backend/src/main/java/com/app/gamereview/service/ProfileService.java @@ -205,11 +205,11 @@ public Profile removeGameFromProfile(String id, ProfileUpdateGameRequestDto requ return profileRepository.save(editedProfile); } - public ProfilePageResponseDto getProfile(String id, String email) { - Optional optionalProfile = profileRepository.findById(id); + public ProfilePageResponseDto getProfile(String userId, String email) { + Optional optionalProfile = profileRepository.findByUserIdAndIsDeletedFalse(userId); if (optionalProfile.isEmpty() || optionalProfile.get().getIsDeleted()) { - throw new ResourceNotFoundException("The profile with the given id is not found."); + throw new ResourceNotFoundException("The profile for the given user id is not found."); } Profile profile = optionalProfile.get();