diff --git a/.gitignore b/.gitignore index b5a33fa0..f9d5d2fd 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,6 @@ logs *.DS_Store /src/main/generated .*-database + +### 멀티모듈 임시 주석 ### +walwal-* diff --git a/src/main/java/com/depromeet/stonebed/domain/auth/application/AuthService.java b/src/main/java/com/depromeet/stonebed/domain/auth/application/AuthService.java index ec2e7987..5361c98f 100644 --- a/src/main/java/com/depromeet/stonebed/domain/auth/application/AuthService.java +++ b/src/main/java/com/depromeet/stonebed/domain/auth/application/AuthService.java @@ -55,8 +55,7 @@ public SocialClientResponse authenticateFromProvider(OAuthProvider provider, Str public AuthTokenResponse socialLogin( OAuthProvider oAuthProvider, String oauthId, String email) { Optional memberOptional = - memberRepository.findByOauthInfoOauthProviderAndOauthInfoOauthId( - oAuthProvider.getValue(), oauthId); + memberRepository.findByMemberOauthInfo(oAuthProvider.getValue(), email); return memberOptional .map( @@ -67,7 +66,8 @@ public AuthTokenResponse socialLogin( ? getTemporaryLoginResponse(member) : getLoginResponse(member); member.updateLastLoginAt(); - updateMemberStatus(member); + member.updateOauthId(oauthId); + updateMemberNormalStatus(member); return AuthTokenResponse.of( tokenPair, member.getRole() == MemberRole.TEMPORARY); }) @@ -132,6 +132,7 @@ public void withdraw() { validateMemberStatusDelete(member.getStatus()); member.updateMemberRole(MemberRole.TEMPORARY); member.updateProfile(Profile.createProfile("", "")); + member.updateOauthId(""); memberRepository.flush(); withdrawMemberRelationByMemberId(member.getId()); @@ -156,7 +157,7 @@ private Member registerMember(Member member, CreateMemberRequest request) { return member; } - private void updateMemberStatus(Member member) { + private void updateMemberNormalStatus(Member member) { if (member.getStatus() == MemberStatus.DELETED) { member.updateStatus(MemberStatus.NORMAL); } diff --git a/src/main/java/com/depromeet/stonebed/domain/auth/application/kakao/KakaoClient.java b/src/main/java/com/depromeet/stonebed/domain/auth/application/kakao/KakaoClient.java index 0734a876..56e09737 100644 --- a/src/main/java/com/depromeet/stonebed/domain/auth/application/kakao/KakaoClient.java +++ b/src/main/java/com/depromeet/stonebed/domain/auth/application/kakao/KakaoClient.java @@ -26,7 +26,7 @@ public SocialClientResponse authenticateFromKakao(String token) { (request, response) -> { if (!response.getStatusCode().is2xxSuccessful()) { throw new CustomException( - ErrorCode.APPLE_TOKEN_CLIENT_FAILED); + ErrorCode.KAKAO_TOKEN_CLIENT_FAILED); } return Objects.requireNonNull( response.bodyTo(KakaoAuthResponse.class)); diff --git a/src/main/java/com/depromeet/stonebed/domain/member/api/MemberController.java b/src/main/java/com/depromeet/stonebed/domain/member/api/MemberController.java index e73f5c5d..2abf384f 100644 --- a/src/main/java/com/depromeet/stonebed/domain/member/api/MemberController.java +++ b/src/main/java/com/depromeet/stonebed/domain/member/api/MemberController.java @@ -10,6 +10,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -26,8 +27,14 @@ public class MemberController { @Operation(summary = "내 정보 조회", description = "내 정보를 조회하는 API입니다.") @GetMapping("/me") - public MemberInfoResponse memberInfo() { - return memberService.findMemberInfo(); + public MemberInfoResponse memberMyInfo() { + return memberService.findMemberMyInfo(); + } + + @Operation(summary = "회원 정보 조회", description = "회원 정보를 조회하는 API입니다.") + @GetMapping("/{memberId}") + public MemberInfoResponse memberInfo(@PathVariable("memberId") Long memberId) { + return memberService.findMemberInfo(memberId); } @Operation(summary = "회원 프로필 변경", description = "회원 프로필을 변경합니다.") diff --git a/src/main/java/com/depromeet/stonebed/domain/member/application/MemberService.java b/src/main/java/com/depromeet/stonebed/domain/member/application/MemberService.java index b2d05a78..b008e4f2 100644 --- a/src/main/java/com/depromeet/stonebed/domain/member/application/MemberService.java +++ b/src/main/java/com/depromeet/stonebed/domain/member/application/MemberService.java @@ -18,11 +18,17 @@ public class MemberService { private final MemberUtil memberUtil; @Transactional(readOnly = true) - public MemberInfoResponse findMemberInfo() { + public MemberInfoResponse findMemberMyInfo() { Member currentMember = memberUtil.getCurrentMember(); return MemberInfoResponse.from(currentMember); } + @Transactional(readOnly = true) + public MemberInfoResponse findMemberInfo(Long memberId) { + Member member = memberUtil.getMemberByMemberId(memberId); + return MemberInfoResponse.from(member); + } + @Transactional(readOnly = true) public void checkNickname(NicknameCheckRequest request) { memberUtil.checkNickname(request); diff --git a/src/main/java/com/depromeet/stonebed/domain/member/dao/MemberRepository.java b/src/main/java/com/depromeet/stonebed/domain/member/dao/MemberRepository.java index b30050ca..e20ca0d0 100644 --- a/src/main/java/com/depromeet/stonebed/domain/member/dao/MemberRepository.java +++ b/src/main/java/com/depromeet/stonebed/domain/member/dao/MemberRepository.java @@ -3,8 +3,16 @@ import com.depromeet.stonebed.domain.member.domain.Member; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface MemberRepository extends JpaRepository, MemberRepositoryCustom { - Optional findByOauthInfoOauthProviderAndOauthInfoOauthId( - String oauthProvider, String oauthId); + + @Query( + "SELECT m FROM Member m WHERE m.oauthInfo.oauthProvider = :provider AND m.oauthInfo.oauthEmail = :email") + Optional findByMemberOauthInfo( + @Param("provider") String oauthProvider, @Param("email") String email); + + Optional findByOauthInfoOauthProviderAndOauthInfoOauthEmail( + String oauthProvider, String email); } diff --git a/src/main/java/com/depromeet/stonebed/domain/member/domain/Member.java b/src/main/java/com/depromeet/stonebed/domain/member/domain/Member.java index a6611c17..ab417b0e 100644 --- a/src/main/java/com/depromeet/stonebed/domain/member/domain/Member.java +++ b/src/main/java/com/depromeet/stonebed/domain/member/domain/Member.java @@ -23,13 +23,11 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.SQLDelete; -import org.hibernate.annotations.SQLRestriction; @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @SQLDelete(sql = "UPDATE member SET status = 'DELETED' WHERE member_id = ?") -@SQLRestriction("status != 'DELETED'") public class Member extends BaseTimeEntity { @Id @@ -121,4 +119,8 @@ public void updateMemberRole(MemberRole memberRole) { public void updateStatus(MemberStatus status) { this.status = status; } + + public void updateOauthId(String oauthId) { + this.oauthInfo.oauthId = oauthId; + } } diff --git a/src/main/java/com/depromeet/stonebed/domain/member/domain/OauthInfo.java b/src/main/java/com/depromeet/stonebed/domain/member/domain/OauthInfo.java index e0666410..ed5d1883 100644 --- a/src/main/java/com/depromeet/stonebed/domain/member/domain/OauthInfo.java +++ b/src/main/java/com/depromeet/stonebed/domain/member/domain/OauthInfo.java @@ -14,7 +14,7 @@ public class OauthInfo { @Schema(description = "소셜 ID", example = "123487892") - private String oauthId; + public String oauthId; @Schema(description = "소셜 제공자", example = "APPLE") private String oauthProvider; diff --git a/src/test/java/com/depromeet/stonebed/domain/auth/application/AuthServiceTest.java b/src/test/java/com/depromeet/stonebed/domain/auth/application/AuthServiceTest.java index c92f2213..66ec85c0 100644 --- a/src/test/java/com/depromeet/stonebed/domain/auth/application/AuthServiceTest.java +++ b/src/test/java/com/depromeet/stonebed/domain/auth/application/AuthServiceTest.java @@ -57,8 +57,7 @@ void setUp() { // given OAuthProvider provider = OAuthProvider.KAKAO; - when(memberRepository.findByOauthInfoOauthProviderAndOauthInfoOauthId( - provider.getValue(), oauthId)) + when(memberRepository.findByMemberOauthInfo(provider.getValue(), email)) .thenReturn(Optional.of(member)); when(jwtTokenService.generateTokenPair(member.getId(), MemberRole.USER)) .thenReturn(new TokenPairResponse("accessToken", "refreshToken")); @@ -75,8 +74,7 @@ void setUp() { // given OAuthProvider provider = OAuthProvider.APPLE; - when(memberRepository.findByOauthInfoOauthProviderAndOauthInfoOauthId( - provider.getValue(), oauthId)) + when(memberRepository.findByMemberOauthInfo(provider.getValue(), email)) .thenReturn(Optional.of(member)); when(jwtTokenService.generateTokenPair(member.getId(), MemberRole.USER)) .thenReturn(new TokenPairResponse("accessToken", "refreshToken")); @@ -95,8 +93,7 @@ void setUp() { TokenPairResponse temporaryTokenPair = new TokenPairResponse("accessToken", "refreshToken"); Member newMember = Member.createOAuthMember(provider, oauthId, email); - when(memberRepository.findByOauthInfoOauthProviderAndOauthInfoOauthId( - provider.getValue(), oauthId)) + when(memberRepository.findByMemberOauthInfo(provider.getValue(), email)) .thenReturn(Optional.empty()); when(memberRepository.save(any(Member.class))).thenReturn(newMember); when(jwtTokenService.generateTemporaryTokenPair(any(Member.class))) diff --git a/src/test/java/com/depromeet/stonebed/domain/member/application/MemberServiceTest.java b/src/test/java/com/depromeet/stonebed/domain/member/application/MemberServiceTest.java index 4253250f..7f4e8899 100644 --- a/src/test/java/com/depromeet/stonebed/domain/member/application/MemberServiceTest.java +++ b/src/test/java/com/depromeet/stonebed/domain/member/application/MemberServiceTest.java @@ -32,7 +32,7 @@ class MemberServiceTest extends FixtureMonkeySetUp { when(memberUtil.getCurrentMember()).thenReturn(member); // when - MemberInfoResponse result = memberService.findMemberInfo(); + MemberInfoResponse result = memberService.findMemberMyInfo(); // then assertNotNull(result);