diff --git a/src/main/java/com/codiary/backend/domain/member/controller/MemberController.java b/src/main/java/com/codiary/backend/domain/member/controller/MemberController.java index 74b1f058..9b7f3d4c 100644 --- a/src/main/java/com/codiary/backend/domain/member/controller/MemberController.java +++ b/src/main/java/com/codiary/backend/domain/member/controller/MemberController.java @@ -35,38 +35,33 @@ public class MemberController { @PatchMapping(path = "/profile-image", consumes = "multipart/form-data") @Operation(summary = "프로필 사진 설정") - public ApiResponse updateProfileImage(@ModelAttribute MemberRequestDTO.MemberProfileImageRequestDTO request) { - Member member = memberCommandService.getRequester(); - - return memberCommandService.updateProfileImage(member, request); + public ApiResponse updateProfileImage(@AuthenticationPrincipal CustomMemberDetails memberDetails, @ModelAttribute MemberRequestDTO.MemberProfileImageRequestDTO request) { + return memberCommandService.updateProfileImage(memberDetails.getId(), request); } @DeleteMapping("/profile-image") @Operation(summary = "프로필 사진 삭제") - public ApiResponse deleteProfileImage() { - Member member = memberCommandService.getRequester(); - return memberCommandService.deleteProfileImage(member); + public ApiResponse deleteProfileImage(@AuthenticationPrincipal CustomMemberDetails memberDetails) { + return memberCommandService.deleteProfileImage(memberDetails.getId()); } - @GetMapping("/{memberId}/profile-image") + @GetMapping("/{member_id}/profile-image") @Operation(summary = "사용자 프로필 사진 조회") - public ApiResponse getProfileImage(@PathVariable Long memberId) { + public ApiResponse getProfileImage(@PathVariable("member_id") Long memberId) { return memberQueryService.getProfileImage(memberId); } @GetMapping("/profile/{member_id}") @Operation(summary = "사용자 프로필 기본 정보 조회", description = "마이페이지 사용자 정보 조회 기능") - public ApiResponse getUserProfile(@PathVariable(value = "member_id") Long memberId){ - Member member = memberCommandService.getRequester(); - Member user = memberQueryService.getUserProfile(memberId); - return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, MemberConverter.toSimpleMemberResponseDto(member, user)); + public ApiResponse getUserProfile(@AuthenticationPrincipal CustomMemberDetails memberDetails, @PathVariable(value = "member_id") Long memberId){ + Member user = memberQueryService.getUserProfile(memberDetails.getId()); + return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, MemberConverter.toSimpleMemberResponseDto(user, user)); } @PutMapping("/info") @Operation(summary = "사용자 정보 수정", description = "마이페이지 사용자 정보 수정 기능") - public ApiResponse updateUserInfo(@Valid @RequestBody MemberRequestDTO.MemberInfoDTO request){ - Member member = memberCommandService.getRequester(); - Member updatedMember = memberCommandService.updateMemberInfo(member, request); + public ApiResponse updateUserInfo(@AuthenticationPrincipal CustomMemberDetails memberDetails, @Valid @RequestBody MemberRequestDTO.MemberInfoDTO request){ + Member updatedMember = memberCommandService.updateMemberInfo(memberDetails.getId(), request); return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, MemberConverter.toMemberInfoResponseDto(updatedMember)); } @@ -80,9 +75,8 @@ public ApiResponse getUserInfo(@AuthenticationP @PatchMapping("/techstack/{techstack_name}") @Operation(summary = "사용자 기술스택 추가", description = "마이페이지 사용자 기술스택 추가 기능") - public ApiResponse addTechStack(@PathVariable(value = "techstack_name") TechStack techStackName){ - Member member = memberCommandService.getRequester(); - Member updatedMember = memberCommandService.addTechStack(member.getMemberId(),techStackName); + public ApiResponse addTechStack(@AuthenticationPrincipal CustomMemberDetails memberDetails, @PathVariable(value = "techstack_name") TechStack techStackName){ + Member updatedMember = memberCommandService.addTechStack(memberDetails.getId(), techStackName); return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, MemberConverter.toMemberTechStackResponseDto(updatedMember)); } diff --git a/src/main/java/com/codiary/backend/domain/member/repository/MemberRepositoryImpl.java b/src/main/java/com/codiary/backend/domain/member/repository/MemberRepositoryImpl.java index e2743c08..71d325f7 100644 --- a/src/main/java/com/codiary/backend/domain/member/repository/MemberRepositoryImpl.java +++ b/src/main/java/com/codiary/backend/domain/member/repository/MemberRepositoryImpl.java @@ -88,7 +88,8 @@ public Optional findByIdWithFollowers(Long id) { private void fetchMemberProjects(Long userId, Member fetchedMember) { List projects = queryFactory - .selectFrom(project) + .select(project) + .from(member) .leftJoin(member.projectList, project) .where(member.memberId.eq(userId) .and(project.deletedAt.isNull())) diff --git a/src/main/java/com/codiary/backend/domain/member/service/MemberCommandService.java b/src/main/java/com/codiary/backend/domain/member/service/MemberCommandService.java index 07e286e9..e6839b0b 100644 --- a/src/main/java/com/codiary/backend/domain/member/service/MemberCommandService.java +++ b/src/main/java/com/codiary/backend/domain/member/service/MemberCommandService.java @@ -45,7 +45,9 @@ public Member getRequester() { } @Transactional - public ApiResponse updateProfileImage(Member member, MemberRequestDTO.MemberProfileImageRequestDTO request) { + public ApiResponse updateProfileImage(Long memberId, MemberRequestDTO.MemberProfileImageRequestDTO request) { + Member member = memberRepository.findById(memberId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND)); + if (member.getImage() != null) { s3Manager.deleteFile(member.getImage().getImageUrl()); memberImageRepository.delete(member.getImage()); @@ -67,7 +69,8 @@ public ApiResponse updateProfileImage(Member m } @Transactional - public ApiResponse deleteProfileImage(Member member) { + public ApiResponse deleteProfileImage(Long memberId) { + Member member = memberRepository.findById(memberId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND)); if (member.getImage() != null) { s3Manager.deleteFile(member.getImage().getImageUrl()); memberImageRepository.delete(member.getImage()); @@ -78,7 +81,8 @@ public ApiResponse deleteProfileImage(Member member) { } @Transactional - public Member updateMemberInfo(Member member, MemberRequestDTO.MemberInfoDTO request){ + public Member updateMemberInfo(Long memberId, MemberRequestDTO.MemberInfoDTO request){ + Member member = memberRepository.findById(memberId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND)); member.updateInfo(request); return memberRepository.save(member); }