From 1739b8a06c3963769ccda7bed6040da611702c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sun, 29 Dec 2024 22:50:52 +0900 Subject: [PATCH 01/61] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/auth/oauth/handler/CustomOAuthSuccessHandler.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java b/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java index 98dab7682..97f27f961 100644 --- a/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java +++ b/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java @@ -4,8 +4,7 @@ import com.somemore.global.auth.jwt.domain.EncodedToken; import com.somemore.global.auth.jwt.domain.UserRole; import com.somemore.global.auth.jwt.usecase.GenerateTokensOnLoginUseCase; -import com.somemore.global.auth.oauth.OAuthProvider; -import com.somemore.global.auth.oauth.naver.service.query.ProcessNaverOAuthUserService; +import com.somemore.global.auth.oauth.processor.OAuthUserProcessor; import com.somemore.global.auth.redirect.RedirectUseCase; import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase; import jakarta.servlet.http.HttpServletRequest; From 0aa1becadf3c78dd93f20388c551d8a8a15b53bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sun, 29 Dec 2024 22:54:50 +0900 Subject: [PATCH 02/61] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../somemore/global/auth/oauth/{ => domain}/OAuthProvider.java | 2 +- .../community/repository/CommunityBoardRepositoryTest.java | 2 +- .../community/repository/CommunityCommentRepositoryTest.java | 2 +- .../community/service/board/CommunityBoardQueryServiceTest.java | 2 +- .../service/comment/CommunityCommentQueryServiceTest.java | 2 +- .../domains/note/repository/NoteRepositoryImplTest.java | 2 +- .../com/somemore/domains/note/service/NoteQueryServiceTest.java | 2 +- .../domains/note/service/SendNoteToVolunteerServiceTest.java | 2 +- .../domains/review/repository/ReviewRepositoryImplTest.java | 2 +- .../somemore/domains/review/service/ReviewQueryServiceTest.java | 2 +- .../com/somemore/domains/volunteer/domain/VolunteerTest.java | 2 +- .../domains/volunteer/repository/VolunteerRepositoryTest.java | 2 +- .../domains/volunteer/service/RegisterVolunteerServiceTest.java | 2 +- .../volunteer/service/UpdateVolunteerLockServiceTest.java | 2 +- .../volunteer/service/UpdateVolunteerProfileServiceTest.java | 2 +- .../domains/volunteer/service/VolunteerQueryServiceTest.java | 2 +- .../service/SettleVolunteerApplyFacadeServiceTest.java | 2 +- .../service/VolunteerApplyQueryFacadeServiceTest.java | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) rename src/main/java/com/somemore/global/auth/oauth/{ => domain}/OAuthProvider.java (92%) diff --git a/src/main/java/com/somemore/global/auth/oauth/OAuthProvider.java b/src/main/java/com/somemore/global/auth/oauth/domain/OAuthProvider.java similarity index 92% rename from src/main/java/com/somemore/global/auth/oauth/OAuthProvider.java rename to src/main/java/com/somemore/global/auth/oauth/domain/OAuthProvider.java index f457de669..215927cd5 100644 --- a/src/main/java/com/somemore/global/auth/oauth/OAuthProvider.java +++ b/src/main/java/com/somemore/global/auth/oauth/domain/OAuthProvider.java @@ -1,4 +1,4 @@ -package com.somemore.global.auth.oauth; +package com.somemore.global.auth.oauth.domain; import lombok.Getter; diff --git a/src/test/java/com/somemore/domains/community/repository/CommunityBoardRepositoryTest.java b/src/test/java/com/somemore/domains/community/repository/CommunityBoardRepositoryTest.java index ceebf2424..ca635bcb0 100644 --- a/src/test/java/com/somemore/domains/community/repository/CommunityBoardRepositoryTest.java +++ b/src/test/java/com/somemore/domains/community/repository/CommunityBoardRepositoryTest.java @@ -5,7 +5,7 @@ import com.somemore.domains.community.repository.mapper.CommunityBoardView; import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.repository.VolunteerRepository; -import com.somemore.global.auth.oauth.OAuthProvider; +import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; diff --git a/src/test/java/com/somemore/domains/community/repository/CommunityCommentRepositoryTest.java b/src/test/java/com/somemore/domains/community/repository/CommunityCommentRepositoryTest.java index 7225fa53b..ca36b22a9 100644 --- a/src/test/java/com/somemore/domains/community/repository/CommunityCommentRepositoryTest.java +++ b/src/test/java/com/somemore/domains/community/repository/CommunityCommentRepositoryTest.java @@ -7,7 +7,7 @@ import com.somemore.domains.community.repository.mapper.CommunityCommentView; import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.repository.VolunteerRepository; -import com.somemore.global.auth.oauth.OAuthProvider; +import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; diff --git a/src/test/java/com/somemore/domains/community/service/board/CommunityBoardQueryServiceTest.java b/src/test/java/com/somemore/domains/community/service/board/CommunityBoardQueryServiceTest.java index d594862b1..07e1f6363 100644 --- a/src/test/java/com/somemore/domains/community/service/board/CommunityBoardQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/community/service/board/CommunityBoardQueryServiceTest.java @@ -9,7 +9,7 @@ import com.somemore.domains.community.usecase.board.DeleteCommunityBoardUseCase; import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.repository.VolunteerRepository; -import com.somemore.global.auth.oauth.OAuthProvider; +import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.global.exception.BadRequestException; import com.somemore.global.exception.ExceptionMessage; import com.somemore.support.IntegrationTestSupport; diff --git a/src/test/java/com/somemore/domains/community/service/comment/CommunityCommentQueryServiceTest.java b/src/test/java/com/somemore/domains/community/service/comment/CommunityCommentQueryServiceTest.java index 2b18bf8e0..8d58d371d 100644 --- a/src/test/java/com/somemore/domains/community/service/comment/CommunityCommentQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/community/service/comment/CommunityCommentQueryServiceTest.java @@ -8,7 +8,7 @@ import com.somemore.domains.community.usecase.comment.DeleteCommunityCommentUseCase; import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.repository.VolunteerRepository; -import com.somemore.global.auth.oauth.OAuthProvider; +import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; diff --git a/src/test/java/com/somemore/domains/note/repository/NoteRepositoryImplTest.java b/src/test/java/com/somemore/domains/note/repository/NoteRepositoryImplTest.java index bc6a7547f..64bd9cb50 100644 --- a/src/test/java/com/somemore/domains/note/repository/NoteRepositoryImplTest.java +++ b/src/test/java/com/somemore/domains/note/repository/NoteRepositoryImplTest.java @@ -21,7 +21,7 @@ import java.util.Optional; import java.util.UUID; -import static com.somemore.global.auth.oauth.OAuthProvider.NAVER; +import static com.somemore.global.auth.oauth.domain.OAuthProvider.NAVER; import static org.assertj.core.api.Assertions.assertThat; @Transactional diff --git a/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java b/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java index e38ddd42b..e1cbb26a6 100644 --- a/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java @@ -22,7 +22,7 @@ import java.util.UUID; -import static com.somemore.global.auth.oauth.OAuthProvider.NAVER; +import static com.somemore.global.auth.oauth.domain.OAuthProvider.NAVER; import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_NOTE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/src/test/java/com/somemore/domains/note/service/SendNoteToVolunteerServiceTest.java b/src/test/java/com/somemore/domains/note/service/SendNoteToVolunteerServiceTest.java index 4e114e733..514e4d6c6 100644 --- a/src/test/java/com/somemore/domains/note/service/SendNoteToVolunteerServiceTest.java +++ b/src/test/java/com/somemore/domains/note/service/SendNoteToVolunteerServiceTest.java @@ -13,7 +13,7 @@ import java.util.UUID; -import static com.somemore.global.auth.oauth.OAuthProvider.NAVER; +import static com.somemore.global.auth.oauth.domain.OAuthProvider.NAVER; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/src/test/java/com/somemore/domains/review/repository/ReviewRepositoryImplTest.java b/src/test/java/com/somemore/domains/review/repository/ReviewRepositoryImplTest.java index f1464b454..2882fc1d1 100644 --- a/src/test/java/com/somemore/domains/review/repository/ReviewRepositoryImplTest.java +++ b/src/test/java/com/somemore/domains/review/repository/ReviewRepositoryImplTest.java @@ -27,7 +27,7 @@ import static com.somemore.domains.recruitboard.domain.VolunteerCategory.*; import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED; -import static com.somemore.global.auth.oauth.OAuthProvider.NAVER; +import static com.somemore.global.auth.oauth.domain.OAuthProvider.NAVER; import static com.somemore.support.fixture.CenterFixture.createCenter; import static com.somemore.support.fixture.RecruitBoardFixture.createCompletedRecruitBoard; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/test/java/com/somemore/domains/review/service/ReviewQueryServiceTest.java b/src/test/java/com/somemore/domains/review/service/ReviewQueryServiceTest.java index a0c4e39ab..b63212956 100644 --- a/src/test/java/com/somemore/domains/review/service/ReviewQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/review/service/ReviewQueryServiceTest.java @@ -30,7 +30,7 @@ import static com.somemore.domains.recruitboard.domain.VolunteerCategory.*; import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED; -import static com.somemore.global.auth.oauth.OAuthProvider.NAVER; +import static com.somemore.global.auth.oauth.domain.OAuthProvider.NAVER; import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_REVIEW; import static com.somemore.support.fixture.CenterFixture.createCenter; import static com.somemore.support.fixture.RecruitBoardFixture.createCompletedRecruitBoard; diff --git a/src/test/java/com/somemore/domains/volunteer/domain/VolunteerTest.java b/src/test/java/com/somemore/domains/volunteer/domain/VolunteerTest.java index 49a28c78a..caa54fd03 100644 --- a/src/test/java/com/somemore/domains/volunteer/domain/VolunteerTest.java +++ b/src/test/java/com/somemore/domains/volunteer/domain/VolunteerTest.java @@ -3,7 +3,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static com.somemore.global.auth.oauth.OAuthProvider.NAVER; +import static com.somemore.global.auth.oauth.domain.OAuthProvider.NAVER; import static org.assertj.core.api.Assertions.assertThat; class VolunteerTest { diff --git a/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryTest.java b/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryTest.java index 54fbf59e8..f68277087 100644 --- a/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryTest.java +++ b/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryTest.java @@ -18,7 +18,7 @@ import java.util.Optional; import java.util.UUID; -import static com.somemore.global.auth.oauth.OAuthProvider.NAVER; +import static com.somemore.global.auth.oauth.domain.OAuthProvider.NAVER; import static org.assertj.core.api.Assertions.assertThat; @Transactional diff --git a/src/test/java/com/somemore/domains/volunteer/service/RegisterVolunteerServiceTest.java b/src/test/java/com/somemore/domains/volunteer/service/RegisterVolunteerServiceTest.java index 32ec10c17..148f75022 100644 --- a/src/test/java/com/somemore/domains/volunteer/service/RegisterVolunteerServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteer/service/RegisterVolunteerServiceTest.java @@ -7,7 +7,7 @@ import com.somemore.domains.volunteer.dto.request.VolunteerRegisterRequestDto; import com.somemore.domains.volunteer.repository.VolunteerDetailRepository; import com.somemore.domains.volunteer.repository.VolunteerRepository; -import com.somemore.global.auth.oauth.OAuthProvider; +import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.support.IntegrationTestSupport; import jakarta.persistence.EntityNotFoundException; import org.junit.jupiter.api.DisplayName; diff --git a/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockServiceTest.java b/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockServiceTest.java index 1c6536d5d..00aaa82b4 100644 --- a/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockServiceTest.java @@ -13,7 +13,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import static com.somemore.global.auth.oauth.OAuthProvider.NAVER; +import static com.somemore.global.auth.oauth.domain.OAuthProvider.NAVER; import static org.assertj.core.api.Assertions.assertThat; class UpdateVolunteerLockServiceTest extends IntegrationTestSupport { diff --git a/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileServiceTest.java b/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileServiceTest.java index dd299dc6d..a5492dee3 100644 --- a/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileServiceTest.java @@ -3,7 +3,7 @@ import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.dto.request.VolunteerProfileUpdateRequestDto; import com.somemore.domains.volunteer.repository.VolunteerRepository; -import com.somemore.global.auth.oauth.OAuthProvider; +import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/somemore/domains/volunteer/service/VolunteerQueryServiceTest.java b/src/test/java/com/somemore/domains/volunteer/service/VolunteerQueryServiceTest.java index 07ab9b85e..d34db6a9b 100644 --- a/src/test/java/com/somemore/domains/volunteer/service/VolunteerQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteer/service/VolunteerQueryServiceTest.java @@ -8,7 +8,7 @@ import com.somemore.domains.volunteer.repository.VolunteerDetailRepository; import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; -import com.somemore.global.auth.oauth.OAuthProvider; +import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.global.exception.BadRequestException; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.DisplayName; diff --git a/src/test/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeServiceTest.java b/src/test/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeServiceTest.java index 67d5a0939..eaa3979e0 100644 --- a/src/test/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeServiceTest.java @@ -19,7 +19,7 @@ import static com.somemore.domains.recruitboard.domain.VolunteerCategory.COUNSELING; import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED; -import static com.somemore.global.auth.oauth.OAuthProvider.NAVER; +import static com.somemore.global.auth.oauth.domain.OAuthProvider.NAVER; import static com.somemore.global.exception.ExceptionMessage.*; import static com.somemore.support.fixture.RecruitBoardFixture.createCompletedRecruitBoard; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/test/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeServiceTest.java b/src/test/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeServiceTest.java index 376d1be27..7a315dc2d 100644 --- a/src/test/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeServiceTest.java @@ -25,7 +25,7 @@ import java.util.UUID; import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED; -import static com.somemore.global.auth.oauth.OAuthProvider.NAVER; +import static com.somemore.global.auth.oauth.domain.OAuthProvider.NAVER; import static com.somemore.support.fixture.RecruitBoardFixture.createRecruitBoard; import static org.assertj.core.api.Assertions.assertThat; From adb632a298609cfa62d6987de99777659f48cd7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sun, 29 Dec 2024 22:58:10 +0900 Subject: [PATCH 03/61] =?UTF-8?q?refactor:=20=EB=84=A4=EC=9D=B4=EB=B2=84?= =?UTF-8?q?=20oauth=20=EC=A0=95=EB=B3=B4=20=EB=B2=94=EC=9C=84=20=EC=B6=95?= =?UTF-8?q?=EC=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 카카오와 맞추기 위해서 oauthId만 받아옴 --- .../dto/NaverUserProfileResponseDto.java | 18 +++++++++ .../response/NaverUserProfileResponseDto.java | 38 ------------------- 2 files changed, 18 insertions(+), 38 deletions(-) create mode 100644 src/main/java/com/somemore/global/auth/oauth/naver/dto/NaverUserProfileResponseDto.java delete mode 100644 src/main/java/com/somemore/global/auth/oauth/naver/dto/response/NaverUserProfileResponseDto.java diff --git a/src/main/java/com/somemore/global/auth/oauth/naver/dto/NaverUserProfileResponseDto.java b/src/main/java/com/somemore/global/auth/oauth/naver/dto/NaverUserProfileResponseDto.java new file mode 100644 index 000000000..5272e770b --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/naver/dto/NaverUserProfileResponseDto.java @@ -0,0 +1,18 @@ +package com.somemore.global.auth.oauth.naver.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public record NaverUserProfileResponseDto( + String resultcode, // 결과 코드 + String message, // 결과 메시지 + Response response // 응답 데이터 +) { + @JsonIgnoreProperties(ignoreUnknown = true) + public record Response( + String id // 일련 번호 + ) { + } +} diff --git a/src/main/java/com/somemore/global/auth/oauth/naver/dto/response/NaverUserProfileResponseDto.java b/src/main/java/com/somemore/global/auth/oauth/naver/dto/response/NaverUserProfileResponseDto.java deleted file mode 100644 index 7331b98fe..000000000 --- a/src/main/java/com/somemore/global/auth/oauth/naver/dto/response/NaverUserProfileResponseDto.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.somemore.global.auth.oauth.naver.dto.response; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; -import com.somemore.global.auth.oauth.OAuthProvider; -import com.somemore.domains.volunteer.dto.request.VolunteerRegisterRequestDto; - -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) -public record NaverUserProfileResponseDto( - String resultcode, // 결과 코드 - String message, // 결과 메시지 - Response response // 응답 데이터 -) { - @JsonIgnoreProperties(ignoreUnknown = true) - public record Response( - String id, // 일련 번호 - String name, // 이름 - String email, // 이메일 - String gender, // 성별 (F, M, U) - String birthday, // 생일 (MM-DD) - String birthyear, // 출생 연도 - String mobile // 휴대 전화 번호 - ) {} - - public VolunteerRegisterRequestDto toVolunteerRegisterRequestDto() { - return new VolunteerRegisterRequestDto( - OAuthProvider.NAVER, - this.response.id(), - this.response.name(), - this.response.email(), - this.response.gender(), - this.response.birthday(), - this.response.birthyear(), - this.response.mobile() - ); - } -} From 97b6f046a68dd891e53410e6ec503dbf4e62b0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sun, 29 Dec 2024 23:16:09 +0900 Subject: [PATCH 04/61] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/somemore/domains/volunteer/domain/Volunteer.java | 2 +- .../volunteer/dto/request/VolunteerRegisterRequestDto.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/somemore/domains/volunteer/domain/Volunteer.java b/src/main/java/com/somemore/domains/volunteer/domain/Volunteer.java index 8f4c4e271..49b004787 100644 --- a/src/main/java/com/somemore/domains/volunteer/domain/Volunteer.java +++ b/src/main/java/com/somemore/domains/volunteer/domain/Volunteer.java @@ -1,6 +1,6 @@ package com.somemore.domains.volunteer.domain; -import com.somemore.global.auth.oauth.OAuthProvider; +import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.global.common.entity.BaseEntity; import com.somemore.domains.volunteer.dto.request.VolunteerProfileUpdateRequestDto; import jakarta.persistence.*; diff --git a/src/main/java/com/somemore/domains/volunteer/dto/request/VolunteerRegisterRequestDto.java b/src/main/java/com/somemore/domains/volunteer/dto/request/VolunteerRegisterRequestDto.java index a32e45e20..09bf7072f 100644 --- a/src/main/java/com/somemore/domains/volunteer/dto/request/VolunteerRegisterRequestDto.java +++ b/src/main/java/com/somemore/domains/volunteer/dto/request/VolunteerRegisterRequestDto.java @@ -1,6 +1,6 @@ package com.somemore.domains.volunteer.dto.request; -import com.somemore.global.auth.oauth.OAuthProvider; +import com.somemore.global.auth.oauth.domain.OAuthProvider; public record VolunteerRegisterRequestDto( OAuthProvider oAuthProvider, From be3f7ac10b754c0cdf06fd3c09e3f473eed9ae86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sun, 29 Dec 2024 23:18:18 +0900 Subject: [PATCH 05/61] =?UTF-8?q?refactor:=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/somemore/global/auth/cookie/CookieService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/somemore/global/auth/cookie/CookieService.java b/src/main/java/com/somemore/global/auth/cookie/CookieService.java index b3f5e4fc5..4cc7f7250 100644 --- a/src/main/java/com/somemore/global/auth/cookie/CookieService.java +++ b/src/main/java/com/somemore/global/auth/cookie/CookieService.java @@ -27,7 +27,7 @@ public void deleteAccessToken(HttpServletResponse response) { } private static ResponseCookie generateCookie(TokenType tokenType, String value) { - return ResponseCookie.from(TokenType.ACCESS.name(), value) // 덮어쓰기 위해서 고정 값 + return ResponseCookie.from(TokenType.ACCESS.name(), value) .domain(".somemore.site") .httpOnly(true) .secure(true) From 0f505a73d0fdbf61b6fe8a5ae4d707963021cae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 14:48:53 +0900 Subject: [PATCH 06/61] =?UTF-8?q?feat(jwt):=20=EC=A0=91=EB=91=90=EC=82=AC?= =?UTF-8?q?=20=ED=8F=AC=ED=95=A8=20getter=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/somemore/global/auth/jwt/domain/EncodedToken.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/somemore/global/auth/jwt/domain/EncodedToken.java b/src/main/java/com/somemore/global/auth/jwt/domain/EncodedToken.java index c5e5a1cb3..311d37170 100644 --- a/src/main/java/com/somemore/global/auth/jwt/domain/EncodedToken.java +++ b/src/main/java/com/somemore/global/auth/jwt/domain/EncodedToken.java @@ -3,6 +3,11 @@ public record EncodedToken(String value) { private static final String UNINITIALIZED = "UNINITIALIZED"; + private static final String PREFIX = "Bearer "; + + public String getValueWithPrefix() { + return PREFIX + this.value; + } public boolean isUninitialized() { return value == null From 6afd89a0c2fc9903c81a7cd3324ba57653fc1011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 14:50:17 +0900 Subject: [PATCH 07/61] =?UTF-8?q?feat(oauth):=20oauth=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EB=8F=84=EB=A9=94=EC=9D=B8(=EC=97=94=ED=8B=B0=ED=8B=B0)=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/auth/oauth/domain/OAuthInfo.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main/java/com/somemore/global/auth/oauth/domain/OAuthInfo.java diff --git a/src/main/java/com/somemore/global/auth/oauth/domain/OAuthInfo.java b/src/main/java/com/somemore/global/auth/oauth/domain/OAuthInfo.java new file mode 100644 index 000000000..f0d07753f --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/domain/OAuthInfo.java @@ -0,0 +1,45 @@ +package com.somemore.global.auth.oauth.domain; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Table(name = "oauth_info") +public class OAuthInfo { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + private Long id; + + @Column(name = "user_id", nullable = false) + private UUID userId; + + @Column(name = "oauth_id", nullable = false) + private String oauthId; + + @Enumerated(EnumType.STRING) + @Column(name = "oauth_provider", nullable = false) + private OAuthProvider oAuthProvider; + + @Builder + public OAuthInfo(UUID userId, String oauthId, OAuthProvider oAuthProvider) { + this.userId = userId; + this.oauthId = oauthId; + this.oAuthProvider = oAuthProvider; + } +} From d5ad3860fb7f30316197e0a688c764f2895f800c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 14:50:46 +0900 Subject: [PATCH 08/61] =?UTF-8?q?feat(oauth):=20oauth=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EC=A1=B4=EC=9E=AC=20=ED=99=95=EC=9D=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/oauth/checker/OAuthInfoChecker.java | 7 ++++++ .../oauth/checker/OAuthInfoCheckerImpl.java | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoChecker.java create mode 100644 src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoCheckerImpl.java diff --git a/src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoChecker.java b/src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoChecker.java new file mode 100644 index 000000000..da360dda6 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoChecker.java @@ -0,0 +1,7 @@ +package com.somemore.global.auth.oauth.checker; + +import com.somemore.global.auth.oauth.domain.OAuthProvider; + +public interface OAuthInfoChecker { + boolean doesUserExist(OAuthProvider provider, String id); +} \ No newline at end of file diff --git a/src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoCheckerImpl.java b/src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoCheckerImpl.java new file mode 100644 index 000000000..aea62cf7f --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoCheckerImpl.java @@ -0,0 +1,22 @@ +package com.somemore.global.auth.oauth.checker; + +import com.somemore.global.auth.oauth.domain.OAuthProvider; +import com.somemore.global.auth.oauth.repository.OAuthInfoJpaRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Slf4j +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class OAuthInfoCheckerImpl implements OAuthInfoChecker { + + private final OAuthInfoJpaRepository oAuthInfoJpaRepository; + + @Override + public boolean doesUserExist(OAuthProvider provider, String id) { + return oAuthInfoJpaRepository.existByOAuthProviderAndOauthId(provider, id); + } +} From 294ab05c2cefb828a716034d3f4d571805b312b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 14:51:00 +0900 Subject: [PATCH 09/61] =?UTF-8?q?feat(oauth):=20oauth=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EB=93=B1=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oauth/registrar/OAuthInfoRegistrar.java | 9 +++++ .../registrar/OAuthInfoRegistrarImpl.java | 33 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/java/com/somemore/global/auth/oauth/registrar/OAuthInfoRegistrar.java create mode 100644 src/main/java/com/somemore/global/auth/oauth/registrar/OAuthInfoRegistrarImpl.java diff --git a/src/main/java/com/somemore/global/auth/oauth/registrar/OAuthInfoRegistrar.java b/src/main/java/com/somemore/global/auth/oauth/registrar/OAuthInfoRegistrar.java new file mode 100644 index 000000000..0f26afdd2 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/registrar/OAuthInfoRegistrar.java @@ -0,0 +1,9 @@ +package com.somemore.global.auth.oauth.registrar; + +import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; +import com.somemore.global.auth.oauth.domain.OAuthInfo; +import com.somemore.user.domain.User; + +public interface OAuthInfoRegistrar { + OAuthInfo register(User user, CommonOAuthInfo oauthInfo); +} diff --git a/src/main/java/com/somemore/global/auth/oauth/registrar/OAuthInfoRegistrarImpl.java b/src/main/java/com/somemore/global/auth/oauth/registrar/OAuthInfoRegistrarImpl.java new file mode 100644 index 000000000..7124b78b2 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/registrar/OAuthInfoRegistrarImpl.java @@ -0,0 +1,33 @@ +package com.somemore.global.auth.oauth.registrar; + +import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; +import com.somemore.global.auth.oauth.domain.OAuthInfo; +import com.somemore.global.auth.oauth.repository.OAuthInfoRepository; +import com.somemore.user.domain.User; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Slf4j +@Service +@RequiredArgsConstructor +@Transactional +public class OAuthInfoRegistrarImpl implements OAuthInfoRegistrar { + + private final OAuthInfoRepository oauthInfoRepository; + + @Override + public OAuthInfo register(User user, CommonOAuthInfo commonOAuthInfo) { + return oauthInfoRepository.save( + createOAuthInfo(user, commonOAuthInfo)); + } + + private OAuthInfo createOAuthInfo(User user, CommonOAuthInfo commonOAuthInfo) { + return OAuthInfo.builder() + .userId(user.getId()) + .oauthId(commonOAuthInfo.oauthId()) + .oAuthProvider(commonOAuthInfo.provider()) + .build(); + } +} From db19228531f3911d5569f77359be288c382b886b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 14:55:23 +0900 Subject: [PATCH 10/61] =?UTF-8?q?feat(oauth):=20oauth=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EB=A6=AC=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - oauth provider, id 로 userId 조회 기능 - 존재 유무 확인 기능 - 저장 기능 --- .../repository/OAuthInfoJpaRepository.java | 10 +++++ .../oauth/repository/OAuthInfoRepository.java | 13 ++++++ .../repository/OAuthInfoRepositoryImpl.java | 44 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoJpaRepository.java create mode 100644 src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepository.java create mode 100644 src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepositoryImpl.java diff --git a/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoJpaRepository.java b/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoJpaRepository.java new file mode 100644 index 000000000..5a82317ee --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoJpaRepository.java @@ -0,0 +1,10 @@ +package com.somemore.global.auth.oauth.repository; + +import com.somemore.global.auth.oauth.domain.OAuthInfo; +import com.somemore.global.auth.oauth.domain.OAuthProvider; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface OAuthInfoJpaRepository extends JpaRepository { + + boolean existByOAuthProviderAndOauthId(OAuthProvider provider, String oauthId); +} diff --git a/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepository.java b/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepository.java new file mode 100644 index 000000000..2c6593845 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepository.java @@ -0,0 +1,13 @@ +package com.somemore.global.auth.oauth.repository; + +import com.somemore.global.auth.oauth.domain.OAuthInfo; +import com.somemore.global.auth.oauth.domain.OAuthProvider; + +import java.util.Optional; +import java.util.UUID; + +public interface OAuthInfoRepository { + Optional findUserIdByOAuthProviderAndOauthId(OAuthProvider provider, String oauthId); + boolean existByOAuthProviderAndOauthId(OAuthProvider provider, String oauthId); + OAuthInfo save(OAuthInfo oauthInfo); +} diff --git a/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepositoryImpl.java b/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepositoryImpl.java new file mode 100644 index 000000000..3299cb6a6 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepositoryImpl.java @@ -0,0 +1,44 @@ +package com.somemore.global.auth.oauth.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.somemore.global.auth.oauth.domain.OAuthInfo; +import com.somemore.global.auth.oauth.domain.OAuthProvider; +import com.somemore.global.auth.oauth.domain.QOAuthInfo; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +import java.util.Optional; +import java.util.UUID; + +@Repository +@RequiredArgsConstructor +public class OAuthInfoRepositoryImpl implements OAuthInfoRepository { + + private final JPAQueryFactory queryFactory; + private final OAuthInfoJpaRepository oauthInfoJpaRepository; + + private static final QOAuthInfo oauthInfo = QOAuthInfo.oAuthInfo; + + @Override + public Optional findUserIdByOAuthProviderAndOauthId(OAuthProvider provider, String oauthId) { + return Optional.ofNullable( + queryFactory.select(oauthInfo.userId) + .from(oauthInfo) + .where( + oauthInfo.oauthId.eq(oauthId), + oauthInfo.oAuthProvider.eq(provider) + ) + .fetchOne() + ); + } + + @Override + public boolean existByOAuthProviderAndOauthId(OAuthProvider provider, String oauthId) { + return oauthInfoJpaRepository.existByOAuthProviderAndOauthId(provider, oauthId); + } + + @Override + public OAuthInfo save(OAuthInfo oauthInfo) { + return oauthInfoJpaRepository.save(oauthInfo); + } +} From a912c1a5abc92cc5b69adcf8d11d3ea4b9f63aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:00:08 +0900 Subject: [PATCH 11/61] =?UTF-8?q?feat(oauth):=20oauth=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EB=B3=80=ED=99=98=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 네이버 -> CommonOAuthInfo - 카카오 -> CommonOAuthInfo (예정) --- .../NaverOAuthResponseConverter.java | 21 +++++++++++++++++++ .../converter/OAuthResponseConverter.java | 8 +++++++ .../auth/oauth/domain/CommonOAuthInfo.java | 6 ++++++ 3 files changed, 35 insertions(+) create mode 100644 src/main/java/com/somemore/global/auth/oauth/converter/NaverOAuthResponseConverter.java create mode 100644 src/main/java/com/somemore/global/auth/oauth/converter/OAuthResponseConverter.java create mode 100644 src/main/java/com/somemore/global/auth/oauth/domain/CommonOAuthInfo.java diff --git a/src/main/java/com/somemore/global/auth/oauth/converter/NaverOAuthResponseConverter.java b/src/main/java/com/somemore/global/auth/oauth/converter/NaverOAuthResponseConverter.java new file mode 100644 index 000000000..5deea6def --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/converter/NaverOAuthResponseConverter.java @@ -0,0 +1,21 @@ +package com.somemore.global.auth.oauth.converter; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; +import com.somemore.global.auth.oauth.domain.OAuthProvider; +import com.somemore.global.auth.oauth.naver.dto.NaverUserProfileResponseDto; +import org.springframework.security.oauth2.core.user.OAuth2User; +import org.springframework.stereotype.Component; + +@Component +public class NaverOAuthResponseConverter implements OAuthResponseConverter { + + @Override + public CommonOAuthInfo convert(OAuth2User oAuth2User) { + NaverUserProfileResponseDto naverUserProfileResponseDto = new ObjectMapper().convertValue(oAuth2User.getAttributes(), NaverUserProfileResponseDto.class); + + return new CommonOAuthInfo( + OAuthProvider.NAVER, + naverUserProfileResponseDto.response().id()); + } +} \ No newline at end of file diff --git a/src/main/java/com/somemore/global/auth/oauth/converter/OAuthResponseConverter.java b/src/main/java/com/somemore/global/auth/oauth/converter/OAuthResponseConverter.java new file mode 100644 index 000000000..765774a59 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/converter/OAuthResponseConverter.java @@ -0,0 +1,8 @@ +package com.somemore.global.auth.oauth.converter; + +import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; +import org.springframework.security.oauth2.core.user.OAuth2User; + +public interface OAuthResponseConverter { + CommonOAuthInfo convert(OAuth2User oAuth2User); +} diff --git a/src/main/java/com/somemore/global/auth/oauth/domain/CommonOAuthInfo.java b/src/main/java/com/somemore/global/auth/oauth/domain/CommonOAuthInfo.java new file mode 100644 index 000000000..440ec9674 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/domain/CommonOAuthInfo.java @@ -0,0 +1,6 @@ +package com.somemore.global.auth.oauth.domain; + +public record CommonOAuthInfo( + OAuthProvider provider, + String oauthId) { +} From 685665553f07684505b2010078a95e2fcb5edb42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:02:58 +0900 Subject: [PATCH 12/61] =?UTF-8?q?feat(registerUser):=20oauth,=20local=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EB=93=B1=EB=A1=9D=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 유저 등록 - 유저 세팅 등록 = 유저 공통 속성 등록 --- .../user/service/RegisterUserService.java | 54 +++++++++++++++++++ .../user/usecase/RegisterUserUseCase.java | 11 ++++ 2 files changed, 65 insertions(+) create mode 100644 src/main/java/com/somemore/user/service/RegisterUserService.java create mode 100644 src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java diff --git a/src/main/java/com/somemore/user/service/RegisterUserService.java b/src/main/java/com/somemore/user/service/RegisterUserService.java new file mode 100644 index 000000000..0bc6b98d0 --- /dev/null +++ b/src/main/java/com/somemore/user/service/RegisterUserService.java @@ -0,0 +1,54 @@ +package com.somemore.user.service; + +import com.somemore.global.auth.jwt.domain.UserRole; +import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; +import com.somemore.user.domain.User; +import com.somemore.user.domain.UserCommonAttribute; +import com.somemore.user.domain.UserSetting; +import com.somemore.user.dto.UserAuthInfo; +import com.somemore.user.repository.user.UserRepository; +import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository; +import com.somemore.user.repository.usersetting.UserSettingRepository; +import com.somemore.user.usecase.RegisterUserUseCase; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@Slf4j +@RequiredArgsConstructor +@Transactional +public class RegisterUserService implements RegisterUserUseCase { + + private final UserRepository userRepository; + private final UserSettingRepository userSettingRepository; + private final UserCommonAttributeRepository userCommonAttributeRepository; + + @Override + public User registerOAuthUser(CommonOAuthInfo commonOAuthInfo, UserRole role) { + UserAuthInfo userAuthInfo = UserAuthInfo.createForOAuth(commonOAuthInfo.provider()); + return createAndRegisterUser(role, userAuthInfo); + } + + @Override + public User registerLocalUser(UserAuthInfo userAuthInfo, UserRole role) { + return createAndRegisterUser(role, userAuthInfo); + } + + private User createAndRegisterUser(UserRole role, UserAuthInfo userAuthInfo) { + User user = User.from(userAuthInfo, role); + userRepository.save(user); + UUID userId = user.getId(); + + UserSetting userSetting = UserSetting.from(userId); + userSettingRepository.save(userSetting); + + UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(userId); + userCommonAttributeRepository.save(userCommonAttribute); + + return user; + } +} diff --git a/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java b/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java new file mode 100644 index 000000000..cfda4184e --- /dev/null +++ b/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java @@ -0,0 +1,11 @@ +package com.somemore.user.usecase; + +import com.somemore.global.auth.jwt.domain.UserRole; +import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; +import com.somemore.user.domain.User; +import com.somemore.user.dto.UserAuthInfo; + +public interface RegisterUserUseCase { + User registerOAuthUser(CommonOAuthInfo commonOAuthInfo, UserRole role); + User registerLocalUser(UserAuthInfo userAuthInfo, UserRole role); +} From 156087e6da4fc925134e4434320692422852e741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:04:48 +0900 Subject: [PATCH 13/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EB=8F=84=EB=A9=94=EC=9D=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/somemore/user/domain/User.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/main/java/com/somemore/user/domain/User.java diff --git a/src/main/java/com/somemore/user/domain/User.java b/src/main/java/com/somemore/user/domain/User.java new file mode 100644 index 000000000..ff14dc7db --- /dev/null +++ b/src/main/java/com/somemore/user/domain/User.java @@ -0,0 +1,57 @@ +package com.somemore.user.domain; + +import com.somemore.global.auth.jwt.domain.UserRole; +import com.somemore.global.common.entity.BaseEntity; +import com.somemore.user.dto.UserAuthInfo; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Table(name = "user") +public class User extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.UUID) + @Column(name = "id", nullable = false, columnDefinition = "BINARY(16)") + private UUID id; + + @Column(name = "email", nullable = false) + private String email; + + @Column(name = "password", nullable = false) + private String password; + + @Enumerated(EnumType.STRING) + @Column(name = "role", nullable = false) + private UserRole role; + + + public static User from(UserAuthInfo userAuthInfo, UserRole role) { + return User.builder() + .email(userAuthInfo.email()) + .password(userAuthInfo.password()) + .role(role) + .build(); + } + + @Builder + private User(String email, String password, UserRole role) { + this.email = email; + this.password = password; + this.role = role; + } +} From 19151335eea140f84de8c14bd0d5e545d5006b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:05:20 +0900 Subject: [PATCH 14/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B3=B5=ED=86=B5=20=EC=86=8D=EC=84=B1=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/domain/UserCommonAttribute.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/main/java/com/somemore/user/domain/UserCommonAttribute.java diff --git a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java new file mode 100644 index 000000000..2c169ffc3 --- /dev/null +++ b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java @@ -0,0 +1,56 @@ +package com.somemore.user.domain; + +import com.somemore.global.imageupload.service.ImageUploadService; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Table(name = "user_common_attribute") +public class UserCommonAttribute { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + private Long id; + + @Column(name = "user_id", nullable = false) + private UUID userId; + + @Column(name = "nickname", nullable = false) + private String nickname; + + @Column(name = "img_url", nullable = false) + private String imgUrl; + + @Column(name = "introduce", nullable = false) + private String introduce; + + public static UserCommonAttribute createDefault(UUID userId) { + return UserCommonAttribute.builder() + .userId(userId) + .nickname(String.valueOf(UUID.randomUUID()).substring(0, 8)) + .imgUrl(ImageUploadService.DEFAULT_IMAGE_URL) + .introduce("") + .build(); + } + + @Builder + private UserCommonAttribute(UUID userId, String nickname, String imgUrl, String introduce) { + this.userId = userId; + this.nickname = nickname; + this.imgUrl = imgUrl; + this.introduce = introduce; + } +} From 927146fb38ddeffac149306e81ec072ecc1e6be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:05:33 +0900 Subject: [PATCH 15/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/somemore/user/domain/UserSetting.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main/java/com/somemore/user/domain/UserSetting.java diff --git a/src/main/java/com/somemore/user/domain/UserSetting.java b/src/main/java/com/somemore/user/domain/UserSetting.java new file mode 100644 index 000000000..68c4e5f1a --- /dev/null +++ b/src/main/java/com/somemore/user/domain/UserSetting.java @@ -0,0 +1,51 @@ +package com.somemore.user.domain; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Table(name = "user_setting") +public class UserSetting { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + private Long id; + + @Column(name = "user_id", nullable = false) + private UUID userId; + + @Column(name = "isAuthenticated", nullable = false) + private boolean isAuthenticated; + + @Column(name = "isSmsAgreed", nullable = false) + private boolean isSmsAgreed; + + + public static UserSetting from(UUID userId) { + return UserSetting.builder() + .userId(userId) + .isAuthenticated(false) + .isSmsAgreed(false) + .build(); + } + + @Builder + private UserSetting(UUID userId, boolean isAuthenticated, boolean isSmsAgreed) { + this.userId = userId; + this.isAuthenticated = isAuthenticated; + this.isSmsAgreed = isSmsAgreed; + } +} From 3a859471da617e67c221679912c76875dade5b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:05:51 +0900 Subject: [PATCH 16/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=A6=AC=ED=8F=AC=EC=A7=80=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 저장 기능 --- .../usersetting/UserSettingJpaRepository.java | 7 +++++++ .../usersetting/UserSettingRepository.java | 8 ++++++++ .../usersetting/UserSettingRepositoryImpl.java | 17 +++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/main/java/com/somemore/user/repository/usersetting/UserSettingJpaRepository.java create mode 100644 src/main/java/com/somemore/user/repository/usersetting/UserSettingRepository.java create mode 100644 src/main/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImpl.java diff --git a/src/main/java/com/somemore/user/repository/usersetting/UserSettingJpaRepository.java b/src/main/java/com/somemore/user/repository/usersetting/UserSettingJpaRepository.java new file mode 100644 index 000000000..25a1643e0 --- /dev/null +++ b/src/main/java/com/somemore/user/repository/usersetting/UserSettingJpaRepository.java @@ -0,0 +1,7 @@ +package com.somemore.user.repository.usersetting; + +import com.somemore.user.domain.UserSetting; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserSettingJpaRepository extends JpaRepository { +} diff --git a/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepository.java b/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepository.java new file mode 100644 index 000000000..420ac2dca --- /dev/null +++ b/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepository.java @@ -0,0 +1,8 @@ +package com.somemore.user.repository.usersetting; + +import com.somemore.user.domain.UserSetting; + +public interface UserSettingRepository { + + UserSetting save(UserSetting userSetting); +} diff --git a/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImpl.java b/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImpl.java new file mode 100644 index 000000000..59b0f7505 --- /dev/null +++ b/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImpl.java @@ -0,0 +1,17 @@ +package com.somemore.user.repository.usersetting; + +import com.somemore.user.domain.UserSetting; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class UserSettingRepositoryImpl implements UserSettingRepository { + + private final UserSettingJpaRepository userSettingJpaRepository; + + @Override + public UserSetting save(UserSetting userSetting) { + return userSettingJpaRepository.save(userSetting); + } +} From 2322782a3a98804b66863b89b1ff891e82b05952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:06:03 +0900 Subject: [PATCH 17/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 저장 기능 --- .../user/repository/user/UserJpaRepository.java | 9 +++++++++ .../user/repository/user/UserRepository.java | 8 ++++++++ .../repository/user/UserRepositoryImpl.java | 17 +++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 src/main/java/com/somemore/user/repository/user/UserJpaRepository.java create mode 100644 src/main/java/com/somemore/user/repository/user/UserRepository.java create mode 100644 src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java diff --git a/src/main/java/com/somemore/user/repository/user/UserJpaRepository.java b/src/main/java/com/somemore/user/repository/user/UserJpaRepository.java new file mode 100644 index 000000000..84f621b24 --- /dev/null +++ b/src/main/java/com/somemore/user/repository/user/UserJpaRepository.java @@ -0,0 +1,9 @@ +package com.somemore.user.repository.user; + +import com.somemore.user.domain.User; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.UUID; + +public interface UserJpaRepository extends JpaRepository { +} diff --git a/src/main/java/com/somemore/user/repository/user/UserRepository.java b/src/main/java/com/somemore/user/repository/user/UserRepository.java new file mode 100644 index 000000000..225b1c39f --- /dev/null +++ b/src/main/java/com/somemore/user/repository/user/UserRepository.java @@ -0,0 +1,8 @@ +package com.somemore.user.repository.user; + +import com.somemore.user.domain.User; + +public interface UserRepository { + + User save(User user); +} diff --git a/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java b/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java new file mode 100644 index 000000000..a5cf3bbbf --- /dev/null +++ b/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java @@ -0,0 +1,17 @@ +package com.somemore.user.repository.user; + +import com.somemore.user.domain.User; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class UserRepositoryImpl implements UserRepository { + + private final UserJpaRepository userJpaRepository; + + @Override + public User save(User user) { + return userJpaRepository.save(user); + } +} From 3c7d762b31f7363741c51f087919c40065f8a51a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:06:16 +0900 Subject: [PATCH 18/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B3=B5=ED=86=B5=20=EC=86=8D=EC=84=B1=20=EB=A6=AC=ED=8F=AC?= =?UTF-8?q?=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 저장 기능 --- .../UserCommonAttributeJpaRepository.java | 7 +++++++ .../UserCommonAttributeRepository.java | 8 ++++++++ .../UserCommonAttributeRepositoryImpl.java | 17 +++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeJpaRepository.java create mode 100644 src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java create mode 100644 src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java diff --git a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeJpaRepository.java b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeJpaRepository.java new file mode 100644 index 000000000..c16264434 --- /dev/null +++ b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeJpaRepository.java @@ -0,0 +1,7 @@ +package com.somemore.user.repository.usercommonattribute; + +import com.somemore.user.domain.UserCommonAttribute; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserCommonAttributeJpaRepository extends JpaRepository { +} diff --git a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java new file mode 100644 index 000000000..acb3713fe --- /dev/null +++ b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java @@ -0,0 +1,8 @@ +package com.somemore.user.repository.usercommonattribute; + +import com.somemore.user.domain.UserCommonAttribute; + +public interface UserCommonAttributeRepository { + + UserCommonAttribute save(UserCommonAttribute userCommonAttribute); +} diff --git a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java new file mode 100644 index 000000000..be061ea3d --- /dev/null +++ b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java @@ -0,0 +1,17 @@ +package com.somemore.user.repository.usercommonattribute; + +import com.somemore.user.domain.UserCommonAttribute; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class UserCommonAttributeRepositoryImpl implements UserCommonAttributeRepository { + + private final UserCommonAttributeJpaRepository userCommonAttributeJpaRepository; + + @Override + public UserCommonAttribute save(UserCommonAttribute userCommonAttribute) { + return userCommonAttributeJpaRepository.save(userCommonAttribute); + } +} From 7b93cdc63073276244ddb4182dd7b6c0d007f17e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:09:22 +0900 Subject: [PATCH 19/61] =?UTF-8?q?feat(auth):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=20=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - oauth 전용 정적 팩토리 메서드 추가 --- .../java/com/somemore/user/dto/UserAuthInfo.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/com/somemore/user/dto/UserAuthInfo.java diff --git a/src/main/java/com/somemore/user/dto/UserAuthInfo.java b/src/main/java/com/somemore/user/dto/UserAuthInfo.java new file mode 100644 index 000000000..9af888af9 --- /dev/null +++ b/src/main/java/com/somemore/user/dto/UserAuthInfo.java @@ -0,0 +1,15 @@ +package com.somemore.user.dto; + +import com.somemore.global.auth.oauth.domain.OAuthProvider; + +import java.util.UUID; + +public record UserAuthInfo(String email, + String password) { + + public static UserAuthInfo createForOAuth(OAuthProvider provider) { + String email = provider.getProviderName() + UUID.randomUUID(); + String password = String.valueOf(UUID.randomUUID()); + return new UserAuthInfo(email, password); + } +} From 987054d17a9e9613b67ac3f91cf101280fd3ed20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:37:27 +0900 Subject: [PATCH 20/61] =?UTF-8?q?feat(oauth):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EB=B6=88=EB=9F=AC=EC=98=A4=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 불러오기에서 유저 프로세싱 삭제. --- .../oauth/service/CustomOAuth2UserService.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/somemore/global/auth/oauth/service/CustomOAuth2UserService.java b/src/main/java/com/somemore/global/auth/oauth/service/CustomOAuth2UserService.java index e2ef43d21..6f57cfa96 100644 --- a/src/main/java/com/somemore/global/auth/oauth/service/CustomOAuth2UserService.java +++ b/src/main/java/com/somemore/global/auth/oauth/service/CustomOAuth2UserService.java @@ -1,7 +1,5 @@ package com.somemore.global.auth.oauth.service; -import com.somemore.global.auth.oauth.OAuthProvider; -import com.somemore.global.auth.oauth.naver.service.command.NaverOAuth2UserInfoService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService; @@ -16,24 +14,18 @@ @RequiredArgsConstructor public class CustomOAuth2UserService implements OAuth2UserService { - private final NaverOAuth2UserInfoService naverOAuth2UserInfoService; - @Override public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException { try { - OAuth2UserService oAuth2UserService = new DefaultOAuth2UserService(); - OAuth2User oAuth2User = oAuth2UserService.loadUser(userRequest); - - return switch (OAuthProvider.from(getRegistrationId(userRequest))) { - case NAVER -> naverOAuth2UserInfoService.processOAuth2User(oAuth2User); - }; + return fetchOAuthUser(userRequest); } catch (OAuth2AuthenticationException e) { - log.error("OAuth 사용자 정보를 로드하는 중 문제가 발생했습니다: {}", e.getMessage(), e); + log.error("OAuth 사용자 정보를 불러오는 중 문제가 발생했습니다: {}", e.getMessage(), e); throw e; } } - private static String getRegistrationId(OAuth2UserRequest userRequest) { - return userRequest.getClientRegistration().getRegistrationId(); + private OAuth2User fetchOAuthUser(OAuth2UserRequest userRequest) { + OAuth2UserService oAuth2UserService = new DefaultOAuth2UserService(); + return oAuth2UserService.loadUser(userRequest); } } From 4c38f74719527c28091de5bbf0ff5315614ba3cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:39:48 +0900 Subject: [PATCH 21/61] =?UTF-8?q?feat(oauth):=20=EC=9D=B8=EC=A6=9D=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5=20=ED=95=B8=EB=93=A4=EB=9F=AC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 액세스 토큰 전달 방법 수정 (쿠키 -> 헤더). - 로직 개선 --- .../handler/CustomOAuthSuccessHandler.java | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java b/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java index 97f27f961..44918eed6 100644 --- a/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java +++ b/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java @@ -1,12 +1,10 @@ package com.somemore.global.auth.oauth.handler; -import com.somemore.global.auth.cookie.CookieUseCase; import com.somemore.global.auth.jwt.domain.EncodedToken; import com.somemore.global.auth.jwt.domain.UserRole; import com.somemore.global.auth.jwt.usecase.GenerateTokensOnLoginUseCase; import com.somemore.global.auth.oauth.processor.OAuthUserProcessor; import com.somemore.global.auth.redirect.RedirectUseCase; -import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; @@ -14,10 +12,10 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.Authentication; import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; +import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; import org.springframework.stereotype.Component; -import java.io.IOException; import java.util.UUID; @Component @@ -25,40 +23,43 @@ @Slf4j public class CustomOAuthSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { - private final ProcessNaverOAuthUserService processNaverOAuthService; - private final VolunteerQueryUseCase volunteerQueryUseCase; + private final OAuthUserProcessor oauthUserProcessor; private final GenerateTokensOnLoginUseCase generateTokensOnLoginUseCase; - private final CookieUseCase cookieUseCase; private final RedirectUseCase redirectUseCase; + public static final String AUTHORIZATION = "Authorization"; + @Value("${app.front-url}") private String frontendRootUrl; @Override - public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { - String oAuthId; - switch (getOAuthProvider(authentication)) { - case NAVER -> oAuthId = processNaverOAuthService.processOAuthUser(authentication); - default -> { - log.error("지원하지 않는 OAuth 제공자입니다."); - throw new IllegalArgumentException(); - } - } + public void onAuthenticationSuccess(HttpServletRequest request, + HttpServletResponse response, + Authentication authentication) { + OAuth2User oauthUser = extractOAuthUser(authentication); + UUID userId = oauthUserProcessor.fetchUserIdByOAuthUser(oauthUser); + + processAccessToken(response, userId); + redirectUseCase.redirect(request, response, frontendRootUrl); + } - UUID volunteerId = volunteerQueryUseCase.getVolunteerIdByOAuthId(oAuthId); + private void processAccessToken(HttpServletResponse response, UUID userId) { EncodedToken accessToken = generateTokensOnLoginUseCase.saveRefreshTokenAndReturnAccessToken( - volunteerId, UserRole.VOLUNTEER - ); + userId, UserRole.VOLUNTEER); - cookieUseCase.setAccessToken(response, accessToken.value()); - redirectUseCase.redirect(request, response, frontendRootUrl); + setAccessToken(response, accessToken); + } + + private void setAccessToken(HttpServletResponse response, EncodedToken accessToken) { + response.addHeader(AUTHORIZATION, accessToken.getValueWithPrefix()); } - private static OAuthProvider getOAuthProvider(Authentication authentication) { + private OAuth2User extractOAuthUser(Authentication authentication) { if (authentication instanceof OAuth2AuthenticationToken token) { - return OAuthProvider.from(token.getAuthorizedClientRegistrationId()); + return token.getPrincipal(); } - throw new IllegalArgumentException(); + log.error("Authentication 객체가 OAuth2AuthenticationToken 타입이 아닙니다: {}", authentication.getClass().getName()); + throw new IllegalArgumentException("잘못된 인증 객체입니다."); } } From bf7fa786284328d862d75c103c45ec01fa378f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:49:49 +0900 Subject: [PATCH 22/61] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/somemore/develop/controller/TokenGenerateMachine.java | 0 .../com/somemore/global/auth/idpw/filter/IdPwAuthFilter.java | 2 +- .../auth/idpw/provider/CustomAuthenticationProvider.java | 2 +- .../global/auth/jwt/service/GenerateTokensOnLoginService.java | 2 +- .../global/auth/jwt/usecase/GenerateTokensOnLoginUseCase.java | 2 +- .../global/auth/oauth/handler/CustomOAuthSuccessHandler.java | 2 +- src/main/java/com/somemore/user/domain/User.java | 1 - .../somemore/{global/auth/jwt => user}/domain/UserRole.java | 4 ++-- .../java/com/somemore/user/service/RegisterUserService.java | 2 +- .../java/com/somemore/user/usecase/RegisterUserUseCase.java | 2 +- .../volunteer/service/SignOutVolunteerServiceTest.java | 2 +- .../com/somemore/global/auth/jwt/service/JwtServiceTest.java | 3 +-- 12 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/somemore/develop/controller/TokenGenerateMachine.java rename src/main/java/com/somemore/{global/auth/jwt => user}/domain/UserRole.java (94%) diff --git a/src/main/java/com/somemore/develop/controller/TokenGenerateMachine.java b/src/main/java/com/somemore/develop/controller/TokenGenerateMachine.java new file mode 100644 index 000000000..e69de29bb diff --git a/src/main/java/com/somemore/global/auth/idpw/filter/IdPwAuthFilter.java b/src/main/java/com/somemore/global/auth/idpw/filter/IdPwAuthFilter.java index 1847b7335..d4d2170a2 100644 --- a/src/main/java/com/somemore/global/auth/idpw/filter/IdPwAuthFilter.java +++ b/src/main/java/com/somemore/global/auth/idpw/filter/IdPwAuthFilter.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.somemore.global.auth.cookie.CookieUseCase; import com.somemore.global.auth.jwt.domain.EncodedToken; -import com.somemore.global.auth.jwt.domain.UserRole; +import com.somemore.user.domain.UserRole; import com.somemore.global.auth.jwt.usecase.GenerateTokensOnLoginUseCase; import jakarta.servlet.FilterChain; import jakarta.servlet.http.HttpServletRequest; diff --git a/src/main/java/com/somemore/global/auth/idpw/provider/CustomAuthenticationProvider.java b/src/main/java/com/somemore/global/auth/idpw/provider/CustomAuthenticationProvider.java index 56adb259f..fc099f569 100644 --- a/src/main/java/com/somemore/global/auth/idpw/provider/CustomAuthenticationProvider.java +++ b/src/main/java/com/somemore/global/auth/idpw/provider/CustomAuthenticationProvider.java @@ -3,7 +3,7 @@ import com.somemore.global.auth.authentication.JwtAuthenticationToken; import com.somemore.global.auth.jwt.domain.EncodedToken; import com.somemore.global.auth.jwt.domain.TokenType; -import com.somemore.global.auth.jwt.domain.UserRole; +import com.somemore.user.domain.UserRole; import com.somemore.global.auth.jwt.usecase.JwtUseCase; import com.somemore.domains.center.usecase.query.CenterSignUseCase; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/somemore/global/auth/jwt/service/GenerateTokensOnLoginService.java b/src/main/java/com/somemore/global/auth/jwt/service/GenerateTokensOnLoginService.java index 5d41cf234..b7e3998e9 100644 --- a/src/main/java/com/somemore/global/auth/jwt/service/GenerateTokensOnLoginService.java +++ b/src/main/java/com/somemore/global/auth/jwt/service/GenerateTokensOnLoginService.java @@ -1,6 +1,6 @@ package com.somemore.global.auth.jwt.service; -import com.somemore.global.auth.jwt.domain.UserRole; +import com.somemore.user.domain.UserRole; import com.somemore.global.auth.jwt.domain.EncodedToken; import com.somemore.global.auth.jwt.domain.TokenType; import com.somemore.global.auth.jwt.generator.JwtGenerator; diff --git a/src/main/java/com/somemore/global/auth/jwt/usecase/GenerateTokensOnLoginUseCase.java b/src/main/java/com/somemore/global/auth/jwt/usecase/GenerateTokensOnLoginUseCase.java index f17795775..6f1786bb8 100644 --- a/src/main/java/com/somemore/global/auth/jwt/usecase/GenerateTokensOnLoginUseCase.java +++ b/src/main/java/com/somemore/global/auth/jwt/usecase/GenerateTokensOnLoginUseCase.java @@ -1,7 +1,7 @@ package com.somemore.global.auth.jwt.usecase; import com.somemore.global.auth.jwt.domain.EncodedToken; -import com.somemore.global.auth.jwt.domain.UserRole; +import com.somemore.user.domain.UserRole; import java.util.UUID; diff --git a/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java b/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java index 44918eed6..da97e5d0a 100644 --- a/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java +++ b/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java @@ -1,7 +1,7 @@ package com.somemore.global.auth.oauth.handler; import com.somemore.global.auth.jwt.domain.EncodedToken; -import com.somemore.global.auth.jwt.domain.UserRole; +import com.somemore.user.domain.UserRole; import com.somemore.global.auth.jwt.usecase.GenerateTokensOnLoginUseCase; import com.somemore.global.auth.oauth.processor.OAuthUserProcessor; import com.somemore.global.auth.redirect.RedirectUseCase; diff --git a/src/main/java/com/somemore/user/domain/User.java b/src/main/java/com/somemore/user/domain/User.java index ff14dc7db..4a56bde7f 100644 --- a/src/main/java/com/somemore/user/domain/User.java +++ b/src/main/java/com/somemore/user/domain/User.java @@ -1,6 +1,5 @@ package com.somemore.user.domain; -import com.somemore.global.auth.jwt.domain.UserRole; import com.somemore.global.common.entity.BaseEntity; import com.somemore.user.dto.UserAuthInfo; import jakarta.persistence.Column; diff --git a/src/main/java/com/somemore/global/auth/jwt/domain/UserRole.java b/src/main/java/com/somemore/user/domain/UserRole.java similarity index 94% rename from src/main/java/com/somemore/global/auth/jwt/domain/UserRole.java rename to src/main/java/com/somemore/user/domain/UserRole.java index 4195fe5bd..e85bf9fb0 100644 --- a/src/main/java/com/somemore/global/auth/jwt/domain/UserRole.java +++ b/src/main/java/com/somemore/user/domain/UserRole.java @@ -1,7 +1,7 @@ -package com.somemore.global.auth.jwt.domain; +package com.somemore.user.domain; -import com.somemore.global.auth.jwt.exception.JwtException; import com.somemore.global.auth.jwt.exception.JwtErrorType; +import com.somemore.global.auth.jwt.exception.JwtException; import lombok.RequiredArgsConstructor; import org.springframework.security.core.GrantedAuthority; diff --git a/src/main/java/com/somemore/user/service/RegisterUserService.java b/src/main/java/com/somemore/user/service/RegisterUserService.java index 0bc6b98d0..18b988194 100644 --- a/src/main/java/com/somemore/user/service/RegisterUserService.java +++ b/src/main/java/com/somemore/user/service/RegisterUserService.java @@ -1,6 +1,6 @@ package com.somemore.user.service; -import com.somemore.global.auth.jwt.domain.UserRole; +import com.somemore.user.domain.UserRole; import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; import com.somemore.user.domain.User; import com.somemore.user.domain.UserCommonAttribute; diff --git a/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java b/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java index cfda4184e..c34994ada 100644 --- a/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java +++ b/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java @@ -1,6 +1,6 @@ package com.somemore.user.usecase; -import com.somemore.global.auth.jwt.domain.UserRole; +import com.somemore.user.domain.UserRole; import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; import com.somemore.user.domain.User; import com.somemore.user.dto.UserAuthInfo; diff --git a/src/test/java/com/somemore/domains/volunteer/service/SignOutVolunteerServiceTest.java b/src/test/java/com/somemore/domains/volunteer/service/SignOutVolunteerServiceTest.java index de887e52c..d4730c6c8 100644 --- a/src/test/java/com/somemore/domains/volunteer/service/SignOutVolunteerServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteer/service/SignOutVolunteerServiceTest.java @@ -3,7 +3,7 @@ import com.somemore.global.auth.cookie.CookieUseCase; import com.somemore.global.auth.jwt.domain.EncodedToken; import com.somemore.global.auth.jwt.domain.TokenType; -import com.somemore.global.auth.jwt.domain.UserRole; +import com.somemore.user.domain.UserRole; import com.somemore.global.auth.jwt.exception.JwtErrorType; import com.somemore.global.auth.jwt.exception.JwtException; import com.somemore.global.auth.jwt.generator.JwtGenerator; diff --git a/src/test/java/com/somemore/global/auth/jwt/service/JwtServiceTest.java b/src/test/java/com/somemore/global/auth/jwt/service/JwtServiceTest.java index 0aa802e5d..16439e97a 100644 --- a/src/test/java/com/somemore/global/auth/jwt/service/JwtServiceTest.java +++ b/src/test/java/com/somemore/global/auth/jwt/service/JwtServiceTest.java @@ -3,12 +3,11 @@ import com.somemore.support.IntegrationTestSupport; import com.somemore.global.auth.jwt.domain.EncodedToken; import com.somemore.global.auth.jwt.domain.TokenType; -import com.somemore.global.auth.jwt.domain.UserRole; +import com.somemore.user.domain.UserRole; import com.somemore.global.auth.jwt.exception.JwtErrorType; import com.somemore.global.auth.jwt.exception.JwtException; import com.somemore.global.auth.jwt.refresh.domain.RefreshToken; import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; -import com.somemore.global.auth.jwt.service.JwtService; import com.somemore.global.auth.jwt.validator.JwtValidator; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; From 4d54d78172db135f93e053f6e03dd109ce32ab98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:50:26 +0900 Subject: [PATCH 23/61] =?UTF-8?q?feat(userRole):=20default=20oauth=20userR?= =?UTF-8?q?ole=20getter=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/auth/oauth/handler/CustomOAuthSuccessHandler.java | 2 +- src/main/java/com/somemore/user/domain/UserRole.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java b/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java index da97e5d0a..7510a1f7b 100644 --- a/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java +++ b/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java @@ -46,7 +46,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, private void processAccessToken(HttpServletResponse response, UUID userId) { EncodedToken accessToken = generateTokensOnLoginUseCase.saveRefreshTokenAndReturnAccessToken( - userId, UserRole.VOLUNTEER); + userId, UserRole.getOAuthUserDefaultRole()); setAccessToken(response, accessToken); } diff --git a/src/main/java/com/somemore/user/domain/UserRole.java b/src/main/java/com/somemore/user/domain/UserRole.java index e85bf9fb0..710466fdf 100644 --- a/src/main/java/com/somemore/user/domain/UserRole.java +++ b/src/main/java/com/somemore/user/domain/UserRole.java @@ -18,6 +18,10 @@ public String getAuthority() { return this.authority; } + public static UserRole getOAuthUserDefaultRole() { + return VOLUNTEER; + } + public static UserRole from(String role) { for (UserRole userRole : values()) { if (userRole.name().equals(role)) { From 539b5d830f912f81b7d295968436724e96a4570c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 15:56:03 +0900 Subject: [PATCH 24/61] =?UTF-8?q?refactor(oauth):=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EB=A6=AC=EB=94=94=EB=A0=89=EC=85=98=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/CustomOAuthSuccessHandler.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java b/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java index 7510a1f7b..12eb7da18 100644 --- a/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java +++ b/src/main/java/com/somemore/global/auth/oauth/handler/CustomOAuthSuccessHandler.java @@ -1,15 +1,14 @@ package com.somemore.global.auth.oauth.handler; import com.somemore.global.auth.jwt.domain.EncodedToken; -import com.somemore.user.domain.UserRole; import com.somemore.global.auth.jwt.usecase.GenerateTokensOnLoginUseCase; import com.somemore.global.auth.oauth.processor.OAuthUserProcessor; import com.somemore.global.auth.redirect.RedirectUseCase; +import com.somemore.user.domain.UserRole; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.Authentication; import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; import org.springframework.security.oauth2.core.user.OAuth2User; @@ -28,9 +27,7 @@ public class CustomOAuthSuccessHandler extends SimpleUrlAuthenticationSuccessHan private final RedirectUseCase redirectUseCase; public static final String AUTHORIZATION = "Authorization"; - - @Value("${app.front-url}") - private String frontendRootUrl; + public static final String MAIN_PATH = "/main"; @Override public void onAuthenticationSuccess(HttpServletRequest request, @@ -40,7 +37,12 @@ public void onAuthenticationSuccess(HttpServletRequest request, UUID userId = oauthUserProcessor.fetchUserIdByOAuthUser(oauthUser); processAccessToken(response, userId); - redirectUseCase.redirect(request, response, frontendRootUrl); + redirect(request, response); + } + + private void redirect(HttpServletRequest request, HttpServletResponse response) { + // TODO 유저 정보 커스텀 확인 분기 + redirectUseCase.redirect(request, response, MAIN_PATH); } private void processAccessToken(HttpServletResponse response, UUID userId) { @@ -48,10 +50,6 @@ private void processAccessToken(HttpServletResponse response, UUID userId) { generateTokensOnLoginUseCase.saveRefreshTokenAndReturnAccessToken( userId, UserRole.getOAuthUserDefaultRole()); - setAccessToken(response, accessToken); - } - - private void setAccessToken(HttpServletResponse response, EncodedToken accessToken) { response.addHeader(AUTHORIZATION, accessToken.getValueWithPrefix()); } From 144fa4ed938d6494f6ef62fd02c296d8a4ce0c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 15:57:07 +0900 Subject: [PATCH 25/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/somemore/global/exception/ExceptionMessage.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/somemore/global/exception/ExceptionMessage.java b/src/main/java/com/somemore/global/exception/ExceptionMessage.java index 6f476a891..9cdd95b88 100644 --- a/src/main/java/com/somemore/global/exception/ExceptionMessage.java +++ b/src/main/java/com/somemore/global/exception/ExceptionMessage.java @@ -7,6 +7,9 @@ @RequiredArgsConstructor @Getter public enum ExceptionMessage { + // USER + NOT_EXIST_USER("존재하지 않는 유저입니다."), + // CENTER NOT_EXISTS_CENTER("존재하지 않는 기관입니다."), NOT_EXISTS_PREFER_ITEM("존재하지 않는 선호물품 ID 입니다"), From 5c7172aa607ad82b6d1dbc97277c2f2885e0aa9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:19:51 +0900 Subject: [PATCH 26/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B3=B5=ED=86=B5=20=EC=86=8D=EC=84=B1=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 커스텀 확인 필드 --- .../com/somemore/user/domain/UserCommonAttribute.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java index 2c169ffc3..816e2340d 100644 --- a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java +++ b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java @@ -11,6 +11,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; import java.util.UUID; @@ -37,20 +38,25 @@ public class UserCommonAttribute { @Column(name = "introduce", nullable = false) private String introduce; + @Column(name = "is_customized", nullable = false) + private boolean isCustomized; + public static UserCommonAttribute createDefault(UUID userId) { return UserCommonAttribute.builder() .userId(userId) .nickname(String.valueOf(UUID.randomUUID()).substring(0, 8)) .imgUrl(ImageUploadService.DEFAULT_IMAGE_URL) .introduce("") + .isCustomized(false) .build(); } @Builder - private UserCommonAttribute(UUID userId, String nickname, String imgUrl, String introduce) { + private UserCommonAttribute(UUID userId, String nickname, String imgUrl, String introduce, boolean isCustomized) { this.userId = userId; this.nickname = nickname; this.imgUrl = imgUrl; this.introduce = introduce; + this.isCustomized = isCustomized; } } From fb100d6e4ac30500212fb523aab0cc74e1e370aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:20:08 +0900 Subject: [PATCH 27/61] =?UTF-8?q?feat(redirection):=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EB=A6=AC=EB=94=94=EB=A0=89=EC=85=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 로직 개선 - 실패 케이스 추가 --- .../java/com/somemore/global/auth/redirect/RedirectService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/somemore/global/auth/redirect/RedirectService.java b/src/main/java/com/somemore/global/auth/redirect/RedirectService.java index 36285b9a5..ac9acc85f 100644 --- a/src/main/java/com/somemore/global/auth/redirect/RedirectService.java +++ b/src/main/java/com/somemore/global/auth/redirect/RedirectService.java @@ -44,4 +44,4 @@ private void handleRedirectFailure(HttpServletRequest request, HttpServletRespon private String buildFallbackUrl() { return frontUrl + RedirectService.ERROR_PATH; } -} +} \ No newline at end of file From 1cb824909eed692c63d470db27c637a15fd4b45c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:31:43 +0900 Subject: [PATCH 28/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/repository/user/UserRepository.java | 4 ++++ .../repository/user/UserRepositoryImpl.java | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/com/somemore/user/repository/user/UserRepository.java b/src/main/java/com/somemore/user/repository/user/UserRepository.java index 225b1c39f..56d69c320 100644 --- a/src/main/java/com/somemore/user/repository/user/UserRepository.java +++ b/src/main/java/com/somemore/user/repository/user/UserRepository.java @@ -2,7 +2,11 @@ import com.somemore.user.domain.User; +import java.util.Optional; +import java.util.UUID; + public interface UserRepository { + Optional findById(UUID id); User save(User user); } diff --git a/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java b/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java index a5cf3bbbf..b7fb27a54 100644 --- a/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java +++ b/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java @@ -1,15 +1,35 @@ package com.somemore.user.repository.user; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQueryFactory; import com.somemore.user.domain.User; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; +import java.util.Optional; +import java.util.UUID; + @Repository @RequiredArgsConstructor public class UserRepositoryImpl implements UserRepository { + private final JPAQueryFactory queryFactory; private final UserJpaRepository userJpaRepository; + private static final com.somemore.user.domain.QUser user = com.somemore.user.domain.QUser.user; + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable( + queryFactory.selectFrom(user) + .where(isNotDeleted()) + .fetchOne()); + } + + private static BooleanExpression isNotDeleted() { + return user.deleted.eq(false); + } + @Override public User save(User user) { return userJpaRepository.save(user); From 5d737343bca300ddfb548220a333a75b5c693efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:33:34 +0900 Subject: [PATCH 29/61] =?UTF-8?q?feat(oauth):=20oauth=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - oauth 정보로 userId 조회 --- .../oauth/service/OAuthInfoQueryService.java | 28 +++++++++++++++++++ .../oauth/usecase/OAuthInfoQueryUseCase.java | 10 +++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/com/somemore/global/auth/oauth/service/OAuthInfoQueryService.java create mode 100644 src/main/java/com/somemore/global/auth/oauth/usecase/OAuthInfoQueryUseCase.java diff --git a/src/main/java/com/somemore/global/auth/oauth/service/OAuthInfoQueryService.java b/src/main/java/com/somemore/global/auth/oauth/service/OAuthInfoQueryService.java new file mode 100644 index 000000000..19050f7ee --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/service/OAuthInfoQueryService.java @@ -0,0 +1,28 @@ +package com.somemore.global.auth.oauth.service; + +import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; +import com.somemore.global.auth.oauth.repository.OAuthInfoRepository; +import com.somemore.global.auth.oauth.usecase.OAuthInfoQueryUseCase; +import jakarta.persistence.EntityNotFoundException; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@Slf4j +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class OAuthInfoQueryService implements OAuthInfoQueryUseCase { + + private final OAuthInfoRepository oAuthInfoRepository; + + public UUID getUserIdByCommonOAuthInfo(CommonOAuthInfo commonOAuthInfo) { + return oAuthInfoRepository.findUserIdByOAuthProviderAndOauthId( + commonOAuthInfo.provider(), + commonOAuthInfo.oauthId() + ).orElseThrow(EntityNotFoundException::new); + } +} diff --git a/src/main/java/com/somemore/global/auth/oauth/usecase/OAuthInfoQueryUseCase.java b/src/main/java/com/somemore/global/auth/oauth/usecase/OAuthInfoQueryUseCase.java new file mode 100644 index 000000000..b81f10946 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/usecase/OAuthInfoQueryUseCase.java @@ -0,0 +1,10 @@ +package com.somemore.global.auth.oauth.usecase; + +import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; + +import java.util.UUID; + +public interface OAuthInfoQueryUseCase { + + UUID getUserIdByCommonOAuthInfo(CommonOAuthInfo commonOAuthInfo); +} From 6e2d1a3e269892f37d0f68749c3eab7e839db0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:35:54 +0900 Subject: [PATCH 30/61] =?UTF-8?q?feat(oauth):=20oauth=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 프레임워크에서 프로바이더에게 제공받는 정보로 구성된 oauthUser를 oauthInfo로 변환 - 위 oauthInfo를 기준으로 userId 조회 - user가 없으면, 등록 후 userId 반환 --- .../oauth/processor/OAuthUserProcessor.java | 9 +++ .../processor/OAuthUserProcessorImpl.java | 64 +++++++++++++++++++ .../usecase/ProcessOAuthUserUseCase.java | 10 --- 3 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/somemore/global/auth/oauth/processor/OAuthUserProcessor.java create mode 100644 src/main/java/com/somemore/global/auth/oauth/processor/OAuthUserProcessorImpl.java delete mode 100644 src/main/java/com/somemore/global/auth/oauth/usecase/ProcessOAuthUserUseCase.java diff --git a/src/main/java/com/somemore/global/auth/oauth/processor/OAuthUserProcessor.java b/src/main/java/com/somemore/global/auth/oauth/processor/OAuthUserProcessor.java new file mode 100644 index 000000000..c9bd55bf7 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/processor/OAuthUserProcessor.java @@ -0,0 +1,9 @@ +package com.somemore.global.auth.oauth.processor; + +import org.springframework.security.oauth2.core.user.OAuth2User; + +import java.util.UUID; + +public interface OAuthUserProcessor { + UUID fetchUserIdByOAuthUser(OAuth2User oauthUser); +} diff --git a/src/main/java/com/somemore/global/auth/oauth/processor/OAuthUserProcessorImpl.java b/src/main/java/com/somemore/global/auth/oauth/processor/OAuthUserProcessorImpl.java new file mode 100644 index 000000000..8eeefdb82 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/oauth/processor/OAuthUserProcessorImpl.java @@ -0,0 +1,64 @@ +package com.somemore.global.auth.oauth.processor; + +import com.somemore.user.domain.UserRole; +import com.somemore.global.auth.oauth.checker.OAuthInfoChecker; +import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; +import com.somemore.global.auth.oauth.converter.OAuthResponseConverter; +import com.somemore.global.auth.oauth.registrar.OAuthInfoRegistrar; +import com.somemore.global.auth.oauth.service.OAuthInfoQueryService; +import com.somemore.user.domain.User; +import com.somemore.user.usecase.RegisterUserUseCase; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.oauth2.core.user.OAuth2User; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Slf4j +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class OAuthUserProcessorImpl implements OAuthUserProcessor { + + private final OAuthResponseConverter oauthResponseConverter; + private final OAuthInfoChecker oauthInfoChecker; + private final OAuthInfoRegistrar oauthInfoRegistrar; + private final RegisterUserUseCase registerUserUseCase; + private final OAuthInfoQueryService oAuthInfoQueryService; + + @Override + public UUID fetchUserIdByOAuthUser(OAuth2User oauthUser) { + CommonOAuthInfo oauthInfo = oauthResponseConverter.convert(oauthUser); + return findUserIdByOAuthInfo(oauthInfo); + } + + private UUID findUserIdByOAuthInfo(CommonOAuthInfo oauthInfo) { + if (isNewUser(oauthInfo)) { + User user = registerOAuthUser(oauthInfo); + return user.getId(); + } + return oAuthInfoQueryService.getUserIdByCommonOAuthInfo(oauthInfo); + } + + private User registerOAuthUser(CommonOAuthInfo oauthInfo) { + User user = registerUser(oauthInfo); + registerOAuthInfo(user, oauthInfo); + // TODO 봉사자 등록 이벤트 발행 + + return user; + } + + private boolean isNewUser(CommonOAuthInfo oauthInfo) { + return !oauthInfoChecker.doesUserExist(oauthInfo.provider(), oauthInfo.oauthId()); + } + + private User registerUser(CommonOAuthInfo oauthInfo) { + return registerUserUseCase.registerOAuthUser(oauthInfo, UserRole.getOAuthUserDefaultRole()); + } + + private void registerOAuthInfo(User user, CommonOAuthInfo oauthInfo) { + oauthInfoRegistrar.register(user, oauthInfo); + } +} diff --git a/src/main/java/com/somemore/global/auth/oauth/usecase/ProcessOAuthUserUseCase.java b/src/main/java/com/somemore/global/auth/oauth/usecase/ProcessOAuthUserUseCase.java deleted file mode 100644 index de477db59..000000000 --- a/src/main/java/com/somemore/global/auth/oauth/usecase/ProcessOAuthUserUseCase.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.somemore.global.auth.oauth.usecase; - -import jakarta.servlet.ServletException; -import org.springframework.security.core.Authentication; - -import java.io.IOException; - -public interface ProcessOAuthUserUseCase { - String processOAuthUser(Authentication authentication) throws IOException, ServletException; -} From 73a1d13602a236ee4d9146bc11a5b62174ebb593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:37:31 +0900 Subject: [PATCH 31/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B3=B5=ED=86=B5=20=EC=86=8D=EC=84=B1=20=EB=A6=AC=ED=8F=AC?= =?UTF-8?q?=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserCommonAttributeRepository.java | 4 ++++ .../UserCommonAttributeRepositoryImpl.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java index acb3713fe..822739fb2 100644 --- a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java +++ b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java @@ -2,7 +2,11 @@ import com.somemore.user.domain.UserCommonAttribute; +import java.util.Optional; +import java.util.UUID; + public interface UserCommonAttributeRepository { + Optional findByUserId(UUID userId); UserCommonAttribute save(UserCommonAttribute userCommonAttribute); } diff --git a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java index be061ea3d..341d47f60 100644 --- a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java +++ b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java @@ -1,15 +1,30 @@ package com.somemore.user.repository.usercommonattribute; +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.somemore.user.domain.QUserCommonAttribute; import com.somemore.user.domain.UserCommonAttribute; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; +import java.util.Optional; +import java.util.UUID; + @Repository @RequiredArgsConstructor public class UserCommonAttributeRepositoryImpl implements UserCommonAttributeRepository { + private final JPAQueryFactory queryFactory; private final UserCommonAttributeJpaRepository userCommonAttributeJpaRepository; + private static final QUserCommonAttribute userCommonAttribute = QUserCommonAttribute.userCommonAttribute; + + @Override + public Optional findByUserId(UUID userId) { + return Optional.ofNullable( + queryFactory.selectFrom(userCommonAttribute) + .fetchOne()); + } + @Override public UserCommonAttribute save(UserCommonAttribute userCommonAttribute) { return userCommonAttributeJpaRepository.save(userCommonAttribute); From 9d3862352d6098f6d5d6cf26acf30b595e56c2de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 17:04:57 +0900 Subject: [PATCH 32/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B3=B5=ED=86=B5=20=EC=86=8D=EC=84=B1=20=EB=B2=A0=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=83=81=EC=86=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/somemore/user/domain/UserCommonAttribute.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java index 816e2340d..30db7a20e 100644 --- a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java +++ b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java @@ -1,5 +1,6 @@ package com.somemore.user.domain; +import com.somemore.global.common.entity.BaseEntity; import com.somemore.global.imageupload.service.ImageUploadService; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -19,7 +20,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name = "user_common_attribute") -public class UserCommonAttribute { +public class UserCommonAttribute extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) From 239bf32e382f63cee8a27bb0a82178282d9ae606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 17:19:14 +0900 Subject: [PATCH 33/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B3=B5=ED=86=B5=20=EC=86=8D=EC=84=B1=20=EB=A6=AC=ED=8F=AC?= =?UTF-8?q?=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - userId, deleted 조건 추가. (Q클래스가 오류나서 이제서야 추가) - 단일 컬럼(사용자화 확인) 조회 추가. --- .../UserCommonAttributeRepository.java | 1 + .../UserCommonAttributeRepositoryImpl.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java index 822739fb2..3b802fe5a 100644 --- a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java +++ b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepository.java @@ -9,4 +9,5 @@ public interface UserCommonAttributeRepository { Optional findByUserId(UUID userId); UserCommonAttribute save(UserCommonAttribute userCommonAttribute); + Optional findIsCustomizedByUserId(UUID userId); } diff --git a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java index 341d47f60..eefbe6e76 100644 --- a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java +++ b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java @@ -1,5 +1,6 @@ package com.somemore.user.repository.usercommonattribute; +import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import com.somemore.user.domain.QUserCommonAttribute; import com.somemore.user.domain.UserCommonAttribute; @@ -22,6 +23,9 @@ public class UserCommonAttributeRepositoryImpl implements UserCommonAttributeRep public Optional findByUserId(UUID userId) { return Optional.ofNullable( queryFactory.selectFrom(userCommonAttribute) + .where( + eqUserId(userId), + isNotDeleted()) .fetchOne()); } @@ -29,4 +33,24 @@ public Optional findByUserId(UUID userId) { public UserCommonAttribute save(UserCommonAttribute userCommonAttribute) { return userCommonAttributeJpaRepository.save(userCommonAttribute); } + + @Override + public Optional findIsCustomizedByUserId(UUID userId) { + return Optional.ofNullable( + queryFactory.select(userCommonAttribute.isCustomized) + .where( + eqUserId(userId), + isNotDeleted()) + .fetchOne() + ); + } + + private static BooleanExpression eqUserId(UUID userId) { + return userCommonAttribute.userId.eq(userId); + } + + private static BooleanExpression isNotDeleted() { + return userCommonAttribute.deleted.eq(false); + } + } From 89bb67af9a24d81873bc503065e59bdce45a7cfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 17:20:10 +0900 Subject: [PATCH 34/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 유저, 유저 공통 속성, 유저 세팅을 모두 조회하는 서비스 추가 --- .../user/service/UserQueryService.java | 43 +++++++++++++++++++ .../user/usecase/UserQueryUseCase.java | 13 ++++++ 2 files changed, 56 insertions(+) create mode 100644 src/main/java/com/somemore/user/service/UserQueryService.java create mode 100644 src/main/java/com/somemore/user/usecase/UserQueryUseCase.java diff --git a/src/main/java/com/somemore/user/service/UserQueryService.java b/src/main/java/com/somemore/user/service/UserQueryService.java new file mode 100644 index 000000000..8ee4aff29 --- /dev/null +++ b/src/main/java/com/somemore/user/service/UserQueryService.java @@ -0,0 +1,43 @@ +package com.somemore.user.service; + +import com.somemore.global.exception.NoSuchElementException; +import com.somemore.user.domain.User; +import com.somemore.user.domain.UserCommonAttribute; +import com.somemore.user.repository.user.UserRepository; +import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository; +import com.somemore.user.usecase.UserQueryUseCase; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +import static com.somemore.global.exception.ExceptionMessage.NOT_EXIST_USER; + +@Service +@Slf4j +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class UserQueryService implements UserQueryUseCase { + + private final UserRepository userRepository; + private final UserCommonAttributeRepository userCommonAttributeRepository; + + @Override + public User getById(UUID id) { + return userRepository.findById(id) + .orElseThrow(() -> new NoSuchElementException(NOT_EXIST_USER)); + } + + @Override + public UserCommonAttribute getCommonAttributeByUserId(UUID userId) { + return userCommonAttributeRepository.findByUserId(userId) + .orElseThrow(() -> new NoSuchElementException(NOT_EXIST_USER)); + } + + @Override + public boolean getIsCustomizedByUserId(UUID userId) { + return false; + } +} diff --git a/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java b/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java new file mode 100644 index 000000000..ad17f1632 --- /dev/null +++ b/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java @@ -0,0 +1,13 @@ +package com.somemore.user.usecase; + +import com.somemore.user.domain.User; +import com.somemore.user.domain.UserCommonAttribute; + +import java.util.UUID; + +public interface UserQueryUseCase { + + User getById(UUID id); + UserCommonAttribute getCommonAttributeByUserId(UUID userId); + boolean getIsCustomizedByUserId(UUID userId); +} From 1df63ce05d46802f1072edde20863958d418967c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 21:46:36 +0900 Subject: [PATCH 35/61] =?UTF-8?q?feat(user):=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=82=AC=EC=9A=A9=EC=9E=90=ED=99=94=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 유저 공통 속성 필드의 커스텀 여부를 검증하는 서비스 추가 - 두 가지 접근 방식(객체 조회, 필드 조회) 중 결정 필요 - TODO: 접근 방식 선택 후 추상화 작업 예정 --- .../service/ValidateBasicInfoService.java | 37 +++++++++++++++++++ .../usecase/ValidateBasicInfoUseCase.java | 8 ++++ 2 files changed, 45 insertions(+) create mode 100644 src/main/java/com/somemore/user/service/ValidateBasicInfoService.java create mode 100644 src/main/java/com/somemore/user/usecase/ValidateBasicInfoUseCase.java diff --git a/src/main/java/com/somemore/user/service/ValidateBasicInfoService.java b/src/main/java/com/somemore/user/service/ValidateBasicInfoService.java new file mode 100644 index 000000000..40c3cacd3 --- /dev/null +++ b/src/main/java/com/somemore/user/service/ValidateBasicInfoService.java @@ -0,0 +1,37 @@ +package com.somemore.user.service; + +import com.somemore.user.domain.UserCommonAttribute; +import com.somemore.user.usecase.UserQueryUseCase; +import com.somemore.user.usecase.ValidateBasicInfoUseCase; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@Slf4j +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class ValidateBasicInfoService implements ValidateBasicInfoUseCase { + + private final UserQueryUseCase userQueryUseCase; + + @Override + public boolean isBasicInfoComplete(UUID userId) { + // 객체지향적: UserCommonAttribute 객체를 활용하여 데이터를 관리 + // 최신 데이터와는 조금 멀어질 수 있음 + UserCommonAttribute userCommonAttribute = userQueryUseCase.getCommonAttributeByUserId(userId); + boolean isCustomized1 = userCommonAttribute.isCustomized(); + + // 비용 절감: 특정 필드만 조회하여 데이터베이스 접근을 최소화 + // 최신 데이터에 더 가까움 + boolean isCustomized2 = userQueryUseCase.getIsCustomizedByUserId(userId); + + // TODO: + // - 두 접근 방식 중 하나를 선택. + + return isCustomized1 && isCustomized2; + } +} diff --git a/src/main/java/com/somemore/user/usecase/ValidateBasicInfoUseCase.java b/src/main/java/com/somemore/user/usecase/ValidateBasicInfoUseCase.java new file mode 100644 index 000000000..7ff4994f6 --- /dev/null +++ b/src/main/java/com/somemore/user/usecase/ValidateBasicInfoUseCase.java @@ -0,0 +1,8 @@ +package com.somemore.user.usecase; + +import java.util.UUID; + +public interface ValidateBasicInfoUseCase { + + boolean isBasicInfoComplete(UUID userId); +} From 654926cd5fe604da3b6502757ee176d71379957e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 21:47:21 +0900 Subject: [PATCH 36/61] =?UTF-8?q?feat(oauth):=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B2=84=20=EA=B4=80=EB=A0=A8=20oauth=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 달라진 oauth 결정 사항에 따라서 기존 로직 삭제. --- .../auth/oauth/naver/domain/NaverUser.java | 23 ---------- .../naver/repository/NaverUserRepository.java | 9 ---- .../command/NaverOAuth2UserInfoService.java | 43 ------------------- .../command/RegisterNaverUserService.java | 25 ----------- .../service/query/CheckNaverUserService.java | 22 ---------- .../query/ProcessNaverOAuthUserService.java | 43 ------------------- .../command/RegisterNaverUserUseCase.java | 5 --- .../usecase/query/CheckNaverUserUseCase.java | 5 --- .../naver/util/OAuthResponseConverter.java | 20 --------- 9 files changed, 195 deletions(-) delete mode 100644 src/main/java/com/somemore/global/auth/oauth/naver/domain/NaverUser.java delete mode 100644 src/main/java/com/somemore/global/auth/oauth/naver/repository/NaverUserRepository.java delete mode 100644 src/main/java/com/somemore/global/auth/oauth/naver/service/command/NaverOAuth2UserInfoService.java delete mode 100644 src/main/java/com/somemore/global/auth/oauth/naver/service/command/RegisterNaverUserService.java delete mode 100644 src/main/java/com/somemore/global/auth/oauth/naver/service/query/CheckNaverUserService.java delete mode 100644 src/main/java/com/somemore/global/auth/oauth/naver/service/query/ProcessNaverOAuthUserService.java delete mode 100644 src/main/java/com/somemore/global/auth/oauth/naver/usecase/command/RegisterNaverUserUseCase.java delete mode 100644 src/main/java/com/somemore/global/auth/oauth/naver/usecase/query/CheckNaverUserUseCase.java delete mode 100644 src/main/java/com/somemore/global/auth/oauth/naver/util/OAuthResponseConverter.java diff --git a/src/main/java/com/somemore/global/auth/oauth/naver/domain/NaverUser.java b/src/main/java/com/somemore/global/auth/oauth/naver/domain/NaverUser.java deleted file mode 100644 index fcdf393f5..000000000 --- a/src/main/java/com/somemore/global/auth/oauth/naver/domain/NaverUser.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.somemore.global.auth.oauth.naver.domain; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import lombok.*; - -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Entity -@Table(name = "naver_user") -public class NaverUser { - @Id - private String oauthId; - - private NaverUser(String oauthId) { - this.oauthId = oauthId; - } - - public static NaverUser from(String oauthId) { - return new NaverUser(oauthId); - } -} diff --git a/src/main/java/com/somemore/global/auth/oauth/naver/repository/NaverUserRepository.java b/src/main/java/com/somemore/global/auth/oauth/naver/repository/NaverUserRepository.java deleted file mode 100644 index 5b8f93f83..000000000 --- a/src/main/java/com/somemore/global/auth/oauth/naver/repository/NaverUserRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.somemore.global.auth.oauth.naver.repository; - -import com.somemore.global.auth.oauth.naver.domain.NaverUser; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface NaverUserRepository extends JpaRepository { -} diff --git a/src/main/java/com/somemore/global/auth/oauth/naver/service/command/NaverOAuth2UserInfoService.java b/src/main/java/com/somemore/global/auth/oauth/naver/service/command/NaverOAuth2UserInfoService.java deleted file mode 100644 index 05814e5cf..000000000 --- a/src/main/java/com/somemore/global/auth/oauth/naver/service/command/NaverOAuth2UserInfoService.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.somemore.global.auth.oauth.naver.service.command; - -import com.somemore.global.auth.oauth.naver.dto.response.NaverUserProfileResponseDto; -import com.somemore.global.auth.oauth.naver.usecase.query.CheckNaverUserUseCase; -import com.somemore.global.auth.oauth.naver.usecase.command.RegisterNaverUserUseCase; -import com.somemore.global.auth.oauth.naver.util.OAuthResponseConverter; -import com.somemore.domains.volunteer.usecase.RegisterVolunteerUseCase; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.security.oauth2.core.user.OAuth2User; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Slf4j -@RequiredArgsConstructor -@Service -@Transactional -public class NaverOAuth2UserInfoService { - - private final CheckNaverUserUseCase checkNaverUserUseCase; - private final RegisterNaverUserUseCase registerNaverUserUseCase; - private final RegisterVolunteerUseCase registerVolunteerUseCase; - - public OAuth2User processOAuth2User(OAuth2User oAuth2User) { - NaverUserProfileResponseDto dto = OAuthResponseConverter.convertToNaverUserProfileResponseDto(oAuth2User); - String naverOauthId = dto.response().id(); - - if (isNewUser(naverOauthId)) { - registerUser(dto); - } - - return oAuth2User; - } - - private boolean isNewUser(String id) { - return !checkNaverUserUseCase.isNaverUserExists(id); - } - - private void registerUser(NaverUserProfileResponseDto dto) { - registerNaverUserUseCase.registerNaverUser(dto.response().id()); - registerVolunteerUseCase.registerVolunteer(dto.toVolunteerRegisterRequestDto()); - } -} diff --git a/src/main/java/com/somemore/global/auth/oauth/naver/service/command/RegisterNaverUserService.java b/src/main/java/com/somemore/global/auth/oauth/naver/service/command/RegisterNaverUserService.java deleted file mode 100644 index 14c2b270b..000000000 --- a/src/main/java/com/somemore/global/auth/oauth/naver/service/command/RegisterNaverUserService.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.somemore.global.auth.oauth.naver.service.command; - -import com.somemore.global.auth.oauth.naver.domain.NaverUser; -import com.somemore.global.auth.oauth.naver.repository.NaverUserRepository; -import com.somemore.global.auth.oauth.naver.usecase.command.RegisterNaverUserUseCase; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Slf4j -@Service -@RequiredArgsConstructor -@Transactional -public class RegisterNaverUserService implements RegisterNaverUserUseCase { - - private final NaverUserRepository naverUserRepository; - - @Override - public void registerNaverUser(String oAuthId) { - NaverUser naverUser = NaverUser.from(oAuthId); - - naverUserRepository.save(naverUser); - } -} diff --git a/src/main/java/com/somemore/global/auth/oauth/naver/service/query/CheckNaverUserService.java b/src/main/java/com/somemore/global/auth/oauth/naver/service/query/CheckNaverUserService.java deleted file mode 100644 index 5249c3d6d..000000000 --- a/src/main/java/com/somemore/global/auth/oauth/naver/service/query/CheckNaverUserService.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.somemore.global.auth.oauth.naver.service.query; - -import com.somemore.global.auth.oauth.naver.repository.NaverUserRepository; -import com.somemore.global.auth.oauth.naver.usecase.query.CheckNaverUserUseCase; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Slf4j -@Service -@RequiredArgsConstructor -@Transactional(readOnly = true) -public class CheckNaverUserService implements CheckNaverUserUseCase { - - private final NaverUserRepository naverUserRepository; - - @Override - public boolean isNaverUserExists(String id) { - return naverUserRepository.existsById(id); - } -} diff --git a/src/main/java/com/somemore/global/auth/oauth/naver/service/query/ProcessNaverOAuthUserService.java b/src/main/java/com/somemore/global/auth/oauth/naver/service/query/ProcessNaverOAuthUserService.java deleted file mode 100644 index 4341b61c1..000000000 --- a/src/main/java/com/somemore/global/auth/oauth/naver/service/query/ProcessNaverOAuthUserService.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.somemore.global.auth.oauth.naver.service.query; - -import com.somemore.global.auth.oauth.OAuthProvider; -import com.somemore.global.auth.oauth.naver.dto.response.NaverUserProfileResponseDto; -import com.somemore.global.auth.oauth.naver.usecase.query.CheckNaverUserUseCase; -import com.somemore.global.auth.oauth.usecase.ProcessOAuthUserUseCase; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.security.core.Authentication; -import org.springframework.security.oauth2.core.user.OAuth2User; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import static com.somemore.global.auth.oauth.naver.util.OAuthResponseConverter.convertToNaverUserProfileResponseDto; - -@Slf4j -@Service -@RequiredArgsConstructor -@Transactional(readOnly = true) -public class ProcessNaverOAuthUserService implements ProcessOAuthUserUseCase { - - private final CheckNaverUserUseCase checkNaverUserUseCase; - - @Override - public String processOAuthUser(Authentication authentication) { - OAuth2User oAuth2User = (OAuth2User) authentication.getPrincipal(); - return processUserInformation(oAuth2User); - } - - private String processUserInformation(OAuth2User oAuth2User) { - NaverUserProfileResponseDto dto = convertToNaverUserProfileResponseDto(oAuth2User); - String oAuthId = dto.response().id(); - - if (checkNaverUserUseCase.isNaverUserExists(oAuthId)) { - return oAuthId; - } - - log.error("유저가 회원 가입을 진행했으나, 존재하지 않는 상태입니다. OAuth Provider: {}, OAuth ID: {}", - OAuthProvider.NAVER, - oAuthId); - throw new IllegalStateException(); - } -} diff --git a/src/main/java/com/somemore/global/auth/oauth/naver/usecase/command/RegisterNaverUserUseCase.java b/src/main/java/com/somemore/global/auth/oauth/naver/usecase/command/RegisterNaverUserUseCase.java deleted file mode 100644 index 8624afcfb..000000000 --- a/src/main/java/com/somemore/global/auth/oauth/naver/usecase/command/RegisterNaverUserUseCase.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.somemore.global.auth.oauth.naver.usecase.command; - -public interface RegisterNaverUserUseCase { - void registerNaverUser(String oAuthId); -} diff --git a/src/main/java/com/somemore/global/auth/oauth/naver/usecase/query/CheckNaverUserUseCase.java b/src/main/java/com/somemore/global/auth/oauth/naver/usecase/query/CheckNaverUserUseCase.java deleted file mode 100644 index 3593b181e..000000000 --- a/src/main/java/com/somemore/global/auth/oauth/naver/usecase/query/CheckNaverUserUseCase.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.somemore.global.auth.oauth.naver.usecase.query; - -public interface CheckNaverUserUseCase { - boolean isNaverUserExists(String id); -} diff --git a/src/main/java/com/somemore/global/auth/oauth/naver/util/OAuthResponseConverter.java b/src/main/java/com/somemore/global/auth/oauth/naver/util/OAuthResponseConverter.java deleted file mode 100644 index f13bdc993..000000000 --- a/src/main/java/com/somemore/global/auth/oauth/naver/util/OAuthResponseConverter.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.somemore.global.auth.oauth.naver.util; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.somemore.global.auth.oauth.naver.dto.response.NaverUserProfileResponseDto; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.springframework.security.oauth2.core.user.OAuth2User; - -import java.util.Map; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class OAuthResponseConverter { - - public static NaverUserProfileResponseDto convertToNaverUserProfileResponseDto(OAuth2User oAuth2User) { - ObjectMapper objectMapper = new ObjectMapper(); - - Map attributes = oAuth2User.getAttributes(); - return objectMapper.convertValue(attributes, NaverUserProfileResponseDto.class); - } -} From 7750e80f12ea75ed3d7160ccc67313eefeaf12cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 21:49:19 +0900 Subject: [PATCH 37/61] =?UTF-8?q?refactor(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=20=EC=A0=95=EB=B3=B4=20dto=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/somemore/user/domain/User.java | 8 ++++---- ...erAuthInfo.java => UserAuthInfoRequestDto.java} | 8 ++++---- .../somemore/user/service/RegisterUserService.java | 14 +++++++------- .../somemore/user/usecase/RegisterUserUseCase.java | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) rename src/main/java/com/somemore/user/dto/{UserAuthInfo.java => UserAuthInfoRequestDto.java} (50%) diff --git a/src/main/java/com/somemore/user/domain/User.java b/src/main/java/com/somemore/user/domain/User.java index 4a56bde7f..1a5feed9a 100644 --- a/src/main/java/com/somemore/user/domain/User.java +++ b/src/main/java/com/somemore/user/domain/User.java @@ -1,7 +1,7 @@ package com.somemore.user.domain; import com.somemore.global.common.entity.BaseEntity; -import com.somemore.user.dto.UserAuthInfo; +import com.somemore.user.dto.UserAuthInfoRequestDto; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -39,10 +39,10 @@ public class User extends BaseEntity { private UserRole role; - public static User from(UserAuthInfo userAuthInfo, UserRole role) { + public static User from(UserAuthInfoRequestDto userAuthInfoRequestDto, UserRole role) { return User.builder() - .email(userAuthInfo.email()) - .password(userAuthInfo.password()) + .email(userAuthInfoRequestDto.email()) + .password(userAuthInfoRequestDto.password()) .role(role) .build(); } diff --git a/src/main/java/com/somemore/user/dto/UserAuthInfo.java b/src/main/java/com/somemore/user/dto/UserAuthInfoRequestDto.java similarity index 50% rename from src/main/java/com/somemore/user/dto/UserAuthInfo.java rename to src/main/java/com/somemore/user/dto/UserAuthInfoRequestDto.java index 9af888af9..4868cea52 100644 --- a/src/main/java/com/somemore/user/dto/UserAuthInfo.java +++ b/src/main/java/com/somemore/user/dto/UserAuthInfoRequestDto.java @@ -4,12 +4,12 @@ import java.util.UUID; -public record UserAuthInfo(String email, - String password) { +public record UserAuthInfoRequestDto(String email, + String password) { - public static UserAuthInfo createForOAuth(OAuthProvider provider) { + public static UserAuthInfoRequestDto createForOAuth(OAuthProvider provider) { String email = provider.getProviderName() + UUID.randomUUID(); String password = String.valueOf(UUID.randomUUID()); - return new UserAuthInfo(email, password); + return new UserAuthInfoRequestDto(email, password); } } diff --git a/src/main/java/com/somemore/user/service/RegisterUserService.java b/src/main/java/com/somemore/user/service/RegisterUserService.java index 18b988194..ced60f65e 100644 --- a/src/main/java/com/somemore/user/service/RegisterUserService.java +++ b/src/main/java/com/somemore/user/service/RegisterUserService.java @@ -5,7 +5,7 @@ import com.somemore.user.domain.User; import com.somemore.user.domain.UserCommonAttribute; import com.somemore.user.domain.UserSetting; -import com.somemore.user.dto.UserAuthInfo; +import com.somemore.user.dto.UserAuthInfoRequestDto; import com.somemore.user.repository.user.UserRepository; import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository; import com.somemore.user.repository.usersetting.UserSettingRepository; @@ -29,17 +29,17 @@ public class RegisterUserService implements RegisterUserUseCase { @Override public User registerOAuthUser(CommonOAuthInfo commonOAuthInfo, UserRole role) { - UserAuthInfo userAuthInfo = UserAuthInfo.createForOAuth(commonOAuthInfo.provider()); - return createAndRegisterUser(role, userAuthInfo); + UserAuthInfoRequestDto userAuthInfoRequestDto = UserAuthInfoRequestDto.createForOAuth(commonOAuthInfo.provider()); + return createAndRegisterUser(role, userAuthInfoRequestDto); } @Override - public User registerLocalUser(UserAuthInfo userAuthInfo, UserRole role) { - return createAndRegisterUser(role, userAuthInfo); + public User registerLocalUser(UserAuthInfoRequestDto userAuthInfoRequestDto, UserRole role) { + return createAndRegisterUser(role, userAuthInfoRequestDto); } - private User createAndRegisterUser(UserRole role, UserAuthInfo userAuthInfo) { - User user = User.from(userAuthInfo, role); + private User createAndRegisterUser(UserRole role, UserAuthInfoRequestDto userAuthInfoRequestDto) { + User user = User.from(userAuthInfoRequestDto, role); userRepository.save(user); UUID userId = user.getId(); diff --git a/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java b/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java index c34994ada..f242c377a 100644 --- a/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java +++ b/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java @@ -3,9 +3,9 @@ import com.somemore.user.domain.UserRole; import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; import com.somemore.user.domain.User; -import com.somemore.user.dto.UserAuthInfo; +import com.somemore.user.dto.UserAuthInfoRequestDto; public interface RegisterUserUseCase { User registerOAuthUser(CommonOAuthInfo commonOAuthInfo, UserRole role); - User registerLocalUser(UserAuthInfo userAuthInfo, UserRole role); + User registerLocalUser(UserAuthInfoRequestDto userAuthInfoRequestDto, UserRole role); } From 9a02fed0de14527adee4e7b94d826c5846bf88d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 22:10:53 +0900 Subject: [PATCH 38/61] =?UTF-8?q?feat(oauth):=20oauth=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=ED=81=B4=EB=9E=98=EC=8A=A4=EC=9D=98=20baseEntity=20?= =?UTF-8?q?=EC=83=81=EC=86=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/somemore/global/auth/oauth/domain/OAuthInfo.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/somemore/global/auth/oauth/domain/OAuthInfo.java b/src/main/java/com/somemore/global/auth/oauth/domain/OAuthInfo.java index f0d07753f..3c7250db0 100644 --- a/src/main/java/com/somemore/global/auth/oauth/domain/OAuthInfo.java +++ b/src/main/java/com/somemore/global/auth/oauth/domain/OAuthInfo.java @@ -1,5 +1,6 @@ package com.somemore.global.auth.oauth.domain; +import com.somemore.global.common.entity.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -19,7 +20,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name = "oauth_info") -public class OAuthInfo { +public class OAuthInfo extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) From d89e00f580c4df091a994ad6a65593338e46587c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 22:12:09 +0900 Subject: [PATCH 39/61] =?UTF-8?q?feat(oauth):=20oauthInfo=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=88=98=EC=A0=95,?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/auth/oauth/checker/OAuthInfoCheckerImpl.java | 6 +++--- .../global/auth/oauth/repository/OAuthInfoRepository.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoCheckerImpl.java b/src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoCheckerImpl.java index aea62cf7f..9fd5ea8cd 100644 --- a/src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoCheckerImpl.java +++ b/src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoCheckerImpl.java @@ -1,7 +1,7 @@ package com.somemore.global.auth.oauth.checker; import com.somemore.global.auth.oauth.domain.OAuthProvider; -import com.somemore.global.auth.oauth.repository.OAuthInfoJpaRepository; +import com.somemore.global.auth.oauth.repository.OAuthInfoRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -13,10 +13,10 @@ @Transactional(readOnly = true) public class OAuthInfoCheckerImpl implements OAuthInfoChecker { - private final OAuthInfoJpaRepository oAuthInfoJpaRepository; + private final OAuthInfoRepository oAuthInfoRepository; @Override public boolean doesUserExist(OAuthProvider provider, String id) { - return oAuthInfoJpaRepository.existByOAuthProviderAndOauthId(provider, id); + return oAuthInfoRepository.existsByOAuthProviderAndOauthId(provider, id); } } diff --git a/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepository.java b/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepository.java index 2c6593845..db1982211 100644 --- a/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepository.java +++ b/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepository.java @@ -8,6 +8,6 @@ public interface OAuthInfoRepository { Optional findUserIdByOAuthProviderAndOauthId(OAuthProvider provider, String oauthId); - boolean existByOAuthProviderAndOauthId(OAuthProvider provider, String oauthId); + boolean existsByOAuthProviderAndOauthId(OAuthProvider provider, String oauthId); OAuthInfo save(OAuthInfo oauthInfo); } From e480db51b56385be633b8d2560c533f8306b1627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 31 Dec 2024 22:17:43 +0900 Subject: [PATCH 40/61] =?UTF-8?q?feat(oauth):=20OAuthInfo=20=EB=A6=AC?= =?UTF-8?q?=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=EC=B2=B4=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - JPA 메서드 네이밍으로 인한 오류 수정 (OAuth → oauth로 통일된 상태, Jpa는 oAuth를 원하는 상태) - QueryDSL 공통 조건 메서드 추출 --- .../repository/OAuthInfoJpaRepository.java | 3 --- .../repository/OAuthInfoRepositoryImpl.java | 25 ++++++++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoJpaRepository.java b/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoJpaRepository.java index 5a82317ee..f95fa7bbb 100644 --- a/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoJpaRepository.java +++ b/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoJpaRepository.java @@ -1,10 +1,7 @@ package com.somemore.global.auth.oauth.repository; import com.somemore.global.auth.oauth.domain.OAuthInfo; -import com.somemore.global.auth.oauth.domain.OAuthProvider; import org.springframework.data.jpa.repository.JpaRepository; public interface OAuthInfoJpaRepository extends JpaRepository { - - boolean existByOAuthProviderAndOauthId(OAuthProvider provider, String oauthId); } diff --git a/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepositoryImpl.java b/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepositoryImpl.java index 3299cb6a6..3a4403eb8 100644 --- a/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepositoryImpl.java +++ b/src/main/java/com/somemore/global/auth/oauth/repository/OAuthInfoRepositoryImpl.java @@ -1,5 +1,6 @@ package com.somemore.global.auth.oauth.repository; +import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import com.somemore.global.auth.oauth.domain.OAuthInfo; import com.somemore.global.auth.oauth.domain.OAuthProvider; @@ -25,20 +26,36 @@ public Optional findUserIdByOAuthProviderAndOauthId(OAuthProvider provider queryFactory.select(oauthInfo.userId) .from(oauthInfo) .where( - oauthInfo.oauthId.eq(oauthId), - oauthInfo.oAuthProvider.eq(provider) + eqOAuthInfo(provider, oauthId), + isNotDeleted() ) .fetchOne() ); } @Override - public boolean existByOAuthProviderAndOauthId(OAuthProvider provider, String oauthId) { - return oauthInfoJpaRepository.existByOAuthProviderAndOauthId(provider, oauthId); + public boolean existsByOAuthProviderAndOauthId(OAuthProvider provider, String oauthId) { + return queryFactory.selectOne() + .from(oauthInfo) + .where( + eqOAuthInfo(provider, oauthId), + isNotDeleted() + ) + .fetchFirst() != null; } @Override public OAuthInfo save(OAuthInfo oauthInfo) { return oauthInfoJpaRepository.save(oauthInfo); } + + private BooleanExpression eqOAuthInfo(OAuthProvider provider, String oauthId) { + return oauthInfo.oauthId.eq(oauthId) + .and(oauthInfo.oAuthProvider.eq(provider)); + } + + private BooleanExpression isNotDeleted() { + return oauthInfo.deleted.eq(false); + } + } From c9774f0f3625d7bdaf9d00e6885b6d5007483563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Wed, 1 Jan 2025 18:08:11 +0900 Subject: [PATCH 41/61] =?UTF-8?q?refactor(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Qclass import 문제 해결 - 메서드 순서 변경 --- .../user/repository/user/UserRepositoryImpl.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java b/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java index b7fb27a54..eb03501da 100644 --- a/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java +++ b/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java @@ -2,6 +2,7 @@ import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; +import com.somemore.user.domain.QUser; import com.somemore.user.domain.User; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; @@ -16,7 +17,7 @@ public class UserRepositoryImpl implements UserRepository { private final JPAQueryFactory queryFactory; private final UserJpaRepository userJpaRepository; - private static final com.somemore.user.domain.QUser user = com.somemore.user.domain.QUser.user; + private static final QUser user = QUser.user; @Override public Optional findById(UUID id) { @@ -26,12 +27,12 @@ public Optional findById(UUID id) { .fetchOne()); } - private static BooleanExpression isNotDeleted() { - return user.deleted.eq(false); - } - @Override public User save(User user) { return userJpaRepository.save(user); } + + private static BooleanExpression isNotDeleted() { + return user.deleted.eq(false); + } } From a1a6db0cc9c02320907da3310493dd35c2bb9f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Wed, 1 Jan 2025 18:41:03 +0900 Subject: [PATCH 42/61] =?UTF-8?q?refactor(user):=20userAuthInfo=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - RequestDto로 두는 것보다 VO의 개념으로 두는 것이 더 올바르다고 판단. --- src/main/java/com/somemore/user/domain/User.java | 8 ++++---- ...erAuthInfoRequestDto.java => UserAuthInfo.java} | 8 ++++---- .../somemore/user/service/RegisterUserService.java | 14 +++++++------- .../somemore/user/usecase/RegisterUserUseCase.java | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) rename src/main/java/com/somemore/user/dto/{UserAuthInfoRequestDto.java => UserAuthInfo.java} (50%) diff --git a/src/main/java/com/somemore/user/domain/User.java b/src/main/java/com/somemore/user/domain/User.java index 1a5feed9a..4a56bde7f 100644 --- a/src/main/java/com/somemore/user/domain/User.java +++ b/src/main/java/com/somemore/user/domain/User.java @@ -1,7 +1,7 @@ package com.somemore.user.domain; import com.somemore.global.common.entity.BaseEntity; -import com.somemore.user.dto.UserAuthInfoRequestDto; +import com.somemore.user.dto.UserAuthInfo; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -39,10 +39,10 @@ public class User extends BaseEntity { private UserRole role; - public static User from(UserAuthInfoRequestDto userAuthInfoRequestDto, UserRole role) { + public static User from(UserAuthInfo userAuthInfo, UserRole role) { return User.builder() - .email(userAuthInfoRequestDto.email()) - .password(userAuthInfoRequestDto.password()) + .email(userAuthInfo.email()) + .password(userAuthInfo.password()) .role(role) .build(); } diff --git a/src/main/java/com/somemore/user/dto/UserAuthInfoRequestDto.java b/src/main/java/com/somemore/user/dto/UserAuthInfo.java similarity index 50% rename from src/main/java/com/somemore/user/dto/UserAuthInfoRequestDto.java rename to src/main/java/com/somemore/user/dto/UserAuthInfo.java index 4868cea52..9af888af9 100644 --- a/src/main/java/com/somemore/user/dto/UserAuthInfoRequestDto.java +++ b/src/main/java/com/somemore/user/dto/UserAuthInfo.java @@ -4,12 +4,12 @@ import java.util.UUID; -public record UserAuthInfoRequestDto(String email, - String password) { +public record UserAuthInfo(String email, + String password) { - public static UserAuthInfoRequestDto createForOAuth(OAuthProvider provider) { + public static UserAuthInfo createForOAuth(OAuthProvider provider) { String email = provider.getProviderName() + UUID.randomUUID(); String password = String.valueOf(UUID.randomUUID()); - return new UserAuthInfoRequestDto(email, password); + return new UserAuthInfo(email, password); } } diff --git a/src/main/java/com/somemore/user/service/RegisterUserService.java b/src/main/java/com/somemore/user/service/RegisterUserService.java index ced60f65e..18b988194 100644 --- a/src/main/java/com/somemore/user/service/RegisterUserService.java +++ b/src/main/java/com/somemore/user/service/RegisterUserService.java @@ -5,7 +5,7 @@ import com.somemore.user.domain.User; import com.somemore.user.domain.UserCommonAttribute; import com.somemore.user.domain.UserSetting; -import com.somemore.user.dto.UserAuthInfoRequestDto; +import com.somemore.user.dto.UserAuthInfo; import com.somemore.user.repository.user.UserRepository; import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository; import com.somemore.user.repository.usersetting.UserSettingRepository; @@ -29,17 +29,17 @@ public class RegisterUserService implements RegisterUserUseCase { @Override public User registerOAuthUser(CommonOAuthInfo commonOAuthInfo, UserRole role) { - UserAuthInfoRequestDto userAuthInfoRequestDto = UserAuthInfoRequestDto.createForOAuth(commonOAuthInfo.provider()); - return createAndRegisterUser(role, userAuthInfoRequestDto); + UserAuthInfo userAuthInfo = UserAuthInfo.createForOAuth(commonOAuthInfo.provider()); + return createAndRegisterUser(role, userAuthInfo); } @Override - public User registerLocalUser(UserAuthInfoRequestDto userAuthInfoRequestDto, UserRole role) { - return createAndRegisterUser(role, userAuthInfoRequestDto); + public User registerLocalUser(UserAuthInfo userAuthInfo, UserRole role) { + return createAndRegisterUser(role, userAuthInfo); } - private User createAndRegisterUser(UserRole role, UserAuthInfoRequestDto userAuthInfoRequestDto) { - User user = User.from(userAuthInfoRequestDto, role); + private User createAndRegisterUser(UserRole role, UserAuthInfo userAuthInfo) { + User user = User.from(userAuthInfo, role); userRepository.save(user); UUID userId = user.getId(); diff --git a/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java b/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java index f242c377a..c34994ada 100644 --- a/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java +++ b/src/main/java/com/somemore/user/usecase/RegisterUserUseCase.java @@ -3,9 +3,9 @@ import com.somemore.user.domain.UserRole; import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; import com.somemore.user.domain.User; -import com.somemore.user.dto.UserAuthInfoRequestDto; +import com.somemore.user.dto.UserAuthInfo; public interface RegisterUserUseCase { User registerOAuthUser(CommonOAuthInfo commonOAuthInfo, UserRole role); - User registerLocalUser(UserAuthInfoRequestDto userAuthInfoRequestDto, UserRole role); + User registerLocalUser(UserAuthInfo userAuthInfo, UserRole role); } From 5be3fd24d2438c228a529d11c4482716dba38871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Wed, 1 Jan 2025 18:49:32 +0900 Subject: [PATCH 43/61] =?UTF-8?q?refactor(user):=20user=20entity=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - user가 특정 데이터베이스(H2 등)의 예약어로 사용됨. --- src/main/java/com/somemore/user/domain/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/somemore/user/domain/User.java b/src/main/java/com/somemore/user/domain/User.java index 4a56bde7f..6cd2db640 100644 --- a/src/main/java/com/somemore/user/domain/User.java +++ b/src/main/java/com/somemore/user/domain/User.java @@ -20,7 +20,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "user") +@Table(name = "users") public class User extends BaseEntity { @Id From 0f4b57b26031c5c8aaa33427eeb101a8398a23e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 06:11:21 +0900 Subject: [PATCH 44/61] =?UTF-8?q?fix(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B3=B5=ED=86=B5=20=EC=86=8D=EC=84=B1=20=EB=A6=AC=ED=8F=AC?= =?UTF-8?q?=EC=A7=80=ED=86=A0=EB=A6=AC=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 빠진 조건을 채움. --- .../usercommonattribute/UserCommonAttributeRepositoryImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java index eefbe6e76..b76c478e6 100644 --- a/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java +++ b/src/main/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImpl.java @@ -38,6 +38,7 @@ public UserCommonAttribute save(UserCommonAttribute userCommonAttribute) { public Optional findIsCustomizedByUserId(UUID userId) { return Optional.ofNullable( queryFactory.select(userCommonAttribute.isCustomized) + .from(userCommonAttribute) .where( eqUserId(userId), isNotDeleted()) From 0f3c0d25800bab0ad4a4cbfd73704e646d97dfd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 06:12:02 +0900 Subject: [PATCH 45/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B3=B5=ED=86=B5=20=EC=86=8D=EC=84=B1=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=ED=99=94=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 구현은 프론트엔드와의 협의 후로 미룸. --- .../java/com/somemore/user/domain/UserCommonAttribute.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java index 30db7a20e..b23e49a44 100644 --- a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java +++ b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java @@ -42,6 +42,11 @@ public class UserCommonAttribute extends BaseEntity { @Column(name = "is_customized", nullable = false) private boolean isCustomized; + public void customize() { + // TODO param의 정보를 필드에 업데이트 + this.isCustomized = true; + } + public static UserCommonAttribute createDefault(UUID userId) { return UserCommonAttribute.builder() .userId(userId) From 58445042652d24030852aec345a16d4ddfffa897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 06:12:58 +0900 Subject: [PATCH 46/61] =?UTF-8?q?fix(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 빠진 조건을 채움. --- .../com/somemore/user/repository/user/UserRepositoryImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java b/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java index eb03501da..c6b1a0ba4 100644 --- a/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java +++ b/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java @@ -23,7 +23,9 @@ public class UserRepositoryImpl implements UserRepository { public Optional findById(UUID id) { return Optional.ofNullable( queryFactory.selectFrom(user) - .where(isNotDeleted()) + .where( + user.id.eq(id), + isNotDeleted()) .fetchOne()); } From 3936b5fa00ebfe410bfc29b80cc032b50b149159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 06:13:26 +0900 Subject: [PATCH 47/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/somemore/user/service/UserQueryService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/somemore/user/service/UserQueryService.java b/src/main/java/com/somemore/user/service/UserQueryService.java index 8ee4aff29..ad965d0af 100644 --- a/src/main/java/com/somemore/user/service/UserQueryService.java +++ b/src/main/java/com/somemore/user/service/UserQueryService.java @@ -38,6 +38,8 @@ public UserCommonAttribute getCommonAttributeByUserId(UUID userId) { @Override public boolean getIsCustomizedByUserId(UUID userId) { - return false; + return userCommonAttributeRepository.findIsCustomizedByUserId(userId) + .orElseThrow(() -> new NoSuchElementException(NOT_EXIST_USER)); } + } From 36c5a1b7b46b7bbf4195214c1c6298036dec663a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 06:14:51 +0900 Subject: [PATCH 48/61] =?UTF-8?q?test(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/UserRepositoryImplTest.java | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/test/java/com/somemore/user/repository/user/UserRepositoryImplTest.java diff --git a/src/test/java/com/somemore/user/repository/user/UserRepositoryImplTest.java b/src/test/java/com/somemore/user/repository/user/UserRepositoryImplTest.java new file mode 100644 index 000000000..42ae0dca8 --- /dev/null +++ b/src/test/java/com/somemore/user/repository/user/UserRepositoryImplTest.java @@ -0,0 +1,108 @@ +package com.somemore.user.repository.user; + +import com.somemore.global.auth.oauth.domain.OAuthProvider; +import com.somemore.support.IntegrationTestSupport; +import com.somemore.user.domain.User; +import com.somemore.user.domain.UserRole; +import com.somemore.user.dto.UserAuthInfo; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +@Transactional +class UserRepositoryImplTest extends IntegrationTestSupport { + + @Autowired + private UserRepositoryImpl userRepository; + + @DisplayName("OAuth 유저(봉사자)를 저장할 수 있다.") + @Test + void saveOAuthVolunteerUser() { + // given + UserAuthInfo userAuthInfo = UserAuthInfo.createForOAuth(OAuthProvider.NAVER); + User user = User.from(userAuthInfo, UserRole.VOLUNTEER); + + // when + User savedUser = userRepository.save(user); + + // then + assertThat(savedUser).isNotNull(); + assertThat(savedUser.getId()).isNotNull(); + assertThat(savedUser.getRole()).isEqualTo(UserRole.VOLUNTEER); + assertThat(savedUser.getEmail()).isEqualTo(userAuthInfo.email()); + } + + @DisplayName("OAuth 유저(기관)를 저장할 수 있다.") + @Test + void saveOAuthCenterUser() { + // given + UserAuthInfo userAuthInfo = UserAuthInfo.createForOAuth(OAuthProvider.NAVER); + User user = User.from(userAuthInfo, UserRole.CENTER); + + // when + User savedUser = userRepository.save(user); + + // then + assertThat(savedUser).isNotNull(); + assertThat(savedUser.getId()).isNotNull(); + assertThat(savedUser.getRole()).isEqualTo(UserRole.CENTER); + assertThat(savedUser.getEmail()).isEqualTo(userAuthInfo.email()); + } + + @DisplayName("Local 유저(기관)를 저장할 수 있다.") + @Test + void saveLocalCenterUser() { + // given + UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.test", "test"); + User user = User.from(userAuthInfo, UserRole.CENTER); + + // when + User savedUser = userRepository.save(user); + + // then + assertThat(savedUser).isNotNull(); + assertThat(savedUser.getId()).isNotNull(); + assertThat(savedUser.getRole()).isEqualTo(UserRole.CENTER); + assertThat(savedUser.getEmail()).isEqualTo(userAuthInfo.email()); + } + + @DisplayName("유저아이디로 유저를 조회할 수 있다.") + @Test + void findById() { + // given + UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.test", "test"); + User user = User.from(userAuthInfo, UserRole.CENTER); + User savedUser = userRepository.save(user); + + // when + Optional findUser = userRepository.findById(savedUser.getId()); + + // then + assertThat(findUser).isPresent(); + assertThat(findUser.get().getId()).isEqualTo(savedUser.getId()); + assertThat(findUser.get().getRole()).isEqualTo(UserRole.CENTER); + assertThat(savedUser.getEmail()).isEqualTo(userAuthInfo.email()); + } + + @DisplayName("유효하지 않은 유저 아이디로 유저를 조회할 수 없다.") + @Test + void findByInvalidId() { + // given + UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.test", "test"); + User user = User.from(userAuthInfo, UserRole.CENTER); + userRepository.save(user); + UUID invalidUserId = UUID.randomUUID(); + + // when + Optional findUser = userRepository.findById(invalidUserId); + + // then + assertThat(findUser).isEmpty(); + } +} From bf2bc3eadb4e34f6747f867ac7b17738c9dfa9a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 06:15:21 +0900 Subject: [PATCH 49/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=84=B8=ED=8C=85=EC=9D=98=20baseEntity=20=EC=83=81=EC=86=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/somemore/user/domain/UserSetting.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/somemore/user/domain/UserSetting.java b/src/main/java/com/somemore/user/domain/UserSetting.java index 68c4e5f1a..8cc08cd95 100644 --- a/src/main/java/com/somemore/user/domain/UserSetting.java +++ b/src/main/java/com/somemore/user/domain/UserSetting.java @@ -1,5 +1,6 @@ package com.somemore.user.domain; +import com.somemore.global.common.entity.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -17,7 +18,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name = "user_setting") -public class UserSetting { +public class UserSetting extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) From 3936954a3bf1fc4fccf9fd22eadacee66726b1d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 06:15:48 +0900 Subject: [PATCH 50/61] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=84=B8=ED=8C=85=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 유저 아이디 기준 조회. --- .../usersetting/UserSettingRepository.java | 4 ++++ .../UserSettingRepositoryImpl.java | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepository.java b/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepository.java index 420ac2dca..45bae3d88 100644 --- a/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepository.java +++ b/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepository.java @@ -2,7 +2,11 @@ import com.somemore.user.domain.UserSetting; +import java.util.Optional; +import java.util.UUID; + public interface UserSettingRepository { + Optional findByUserId(UUID userId); UserSetting save(UserSetting userSetting); } diff --git a/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImpl.java b/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImpl.java index 59b0f7505..cecd4e5eb 100644 --- a/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImpl.java +++ b/src/main/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImpl.java @@ -1,15 +1,35 @@ package com.somemore.user.repository.usersetting; +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.somemore.user.domain.QUserSetting; import com.somemore.user.domain.UserSetting; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; +import java.util.Optional; +import java.util.UUID; + @Repository @RequiredArgsConstructor public class UserSettingRepositoryImpl implements UserSettingRepository { + private final JPAQueryFactory queryFactory; private final UserSettingJpaRepository userSettingJpaRepository; + private static final QUserSetting userSetting = QUserSetting.userSetting; + + @Override + public Optional findByUserId(UUID userId) { + return Optional.ofNullable( + queryFactory.selectFrom(userSetting) + .where( + userSetting.userId.eq(userId), + userSetting.deleted.eq(false) + ) + .fetchOne() + ); + } + @Override public UserSetting save(UserSetting userSetting) { return userSettingJpaRepository.save(userSetting); From af2fbdff023440c4b7731d641d7e19fba77e77ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 06:16:17 +0900 Subject: [PATCH 51/61] =?UTF-8?q?test(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=84=B8=ED=8C=85=20=EC=A1=B0=ED=9A=8C,=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserSettingRepositoryImplTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/test/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImplTest.java diff --git a/src/test/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImplTest.java b/src/test/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImplTest.java new file mode 100644 index 000000000..c6b11d39e --- /dev/null +++ b/src/test/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImplTest.java @@ -0,0 +1,54 @@ +package com.somemore.user.repository.usersetting; + +import com.somemore.support.IntegrationTestSupport; +import com.somemore.user.domain.UserSetting; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +@Transactional +class UserSettingRepositoryImplTest extends IntegrationTestSupport { + + @Autowired + private UserSettingRepositoryImpl userSettingRepository; + + @DisplayName("유저 아이디로 유저 세팅을 조회할 수 있다.") + @Test + void findByUserId() { + // given + UUID userId = UUID.randomUUID(); + UserSetting userSetting = UserSetting.from(userId); + UserSetting savedUserSetting = userSettingRepository.save(userSetting); + + // when + Optional foundUserSetting = userSettingRepository.findByUserId(userId); + + // then + assertThat(foundUserSetting).isNotNull(); + assertThat(foundUserSetting).get().isEqualTo(savedUserSetting); + } + + @DisplayName("유저 세팅을 저장할 수 있다.") + @Test + void saveUserSetting() { + // given + UUID userId = UUID.randomUUID(); + UserSetting userSetting = UserSetting.from(userId); + + // when + UserSetting savedUserSetting = userSettingRepository.save(userSetting); + + // then + assertThat(savedUserSetting).isNotNull(); + assertThat(savedUserSetting.getId()).isNotNull(); + assertThat(savedUserSetting.isAuthenticated()).isEqualTo(false); + assertThat(savedUserSetting.isSmsAgreed()).isEqualTo(false); + } + +} \ No newline at end of file From 80eba668913625c152911e335bab8ceb6e01365d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 06:16:57 +0900 Subject: [PATCH 52/61] =?UTF-8?q?test(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/service/UserQueryServiceTest.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/test/java/com/somemore/user/service/UserQueryServiceTest.java diff --git a/src/test/java/com/somemore/user/service/UserQueryServiceTest.java b/src/test/java/com/somemore/user/service/UserQueryServiceTest.java new file mode 100644 index 000000000..2ea3c0ea7 --- /dev/null +++ b/src/test/java/com/somemore/user/service/UserQueryServiceTest.java @@ -0,0 +1,77 @@ +package com.somemore.user.service; + +import com.somemore.global.auth.oauth.domain.OAuthProvider; +import com.somemore.support.IntegrationTestSupport; +import com.somemore.user.domain.User; +import com.somemore.user.domain.UserCommonAttribute; +import com.somemore.user.domain.UserRole; +import com.somemore.user.dto.UserAuthInfo; +import com.somemore.user.repository.user.UserRepository; +import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import static org.assertj.core.api.Assertions.assertThat; + +@Transactional +class UserQueryServiceTest extends IntegrationTestSupport { + + @Autowired + private UserQueryService userQueryService; + + @Autowired + private UserRepository userRepository; + + @Autowired + private UserCommonAttributeRepository userCommonAttributeRepository; + + private User user; + + @BeforeEach + void setup() { + UserAuthInfo userAuthInfo = UserAuthInfo.createForOAuth(OAuthProvider.NAVER); + + user = userRepository.save(User.from(userAuthInfo, UserRole.VOLUNTEER)); + userCommonAttributeRepository.save(UserCommonAttribute.createDefault(user.getId())); + } + + + @DisplayName("유저 아이디로 유저를 조회할 수 있다.") + @Test + void getById() { + // given + + // when + User foundUser = userQueryService.getById(user.getId()); + + // then + assertThat(foundUser).isNotNull(); + } + + @DisplayName("유저 아이디로 유저 공통 속성을 조회할 수 있다.") + @Test + void getCommonAttributeByUserID() { + // given + + // when + UserCommonAttribute foundCommonAttribute = userQueryService.getCommonAttributeByUserId(user.getId()); + + // then + assertThat(foundCommonAttribute).isNotNull(); + } + + @DisplayName("유저가 필수 입력 필드를 사용자화하지 않은 경우 기본 값 false를 반환한다.") + @Test + void getIsCustomizedByUserId_ReturnsFalse_WhenDefaultValue() { + // given + + // when + boolean isCustomized = userQueryService.getIsCustomizedByUserId(user.getId()); + + // then + assertThat(isCustomized).isEqualTo(false); + } +} From 7eaa28ca662c1a1d9bc6041212b74081ff1021d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 06:17:17 +0900 Subject: [PATCH 53/61] =?UTF-8?q?test(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B3=B5=ED=86=B5=20=EC=86=8D=EC=84=B1=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...UserCommonAttributeRepositoryImplTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java diff --git a/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java b/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java new file mode 100644 index 000000000..f08690747 --- /dev/null +++ b/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java @@ -0,0 +1,39 @@ +package com.somemore.user.repository.usercommonattribute; + +import com.somemore.global.imageupload.service.ImageUploadService; +import com.somemore.support.IntegrationTestSupport; +import com.somemore.user.domain.UserCommonAttribute; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +@Transactional +class UserCommonAttributeRepositoryImplTest extends IntegrationTestSupport { + + @Autowired + private UserCommonAttributeRepositoryImpl userCommonAttributeRepository; + + @DisplayName("유저 공통 속성을 저장할 수 있다.") + @Test + void saveUserCommonAttribute() { + // given + UUID userId = UUID.randomUUID(); + UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(userId); + + // when + UserCommonAttribute savedUserCommonAttribute = userCommonAttributeRepository.save(userCommonAttribute); + + // then + assertThat(savedUserCommonAttribute).isNotNull(); + assertThat(savedUserCommonAttribute.getId()).isNotNull(); + assertThat(savedUserCommonAttribute.getUserId()).isEqualTo(userId); + assertThat(savedUserCommonAttribute.getImgUrl()).isEqualTo(ImageUploadService.DEFAULT_IMAGE_URL); + assertThat(savedUserCommonAttribute.isCustomized()).isEqualTo(false); + + } +} \ No newline at end of file From cfef5cb897489d9b71f18566c90540dd2ee5cf45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 06:17:38 +0900 Subject: [PATCH 54/61] =?UTF-8?q?test(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B3=B5=ED=86=B5=20=EC=86=8D=EC=84=B1=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=ED=99=94=20=EA=B2=80=EC=A6=9D=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ValidateBasicInfoServiceTest.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java diff --git a/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java b/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java new file mode 100644 index 000000000..7217f27ea --- /dev/null +++ b/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java @@ -0,0 +1,66 @@ +package com.somemore.user.service; + +import com.somemore.support.IntegrationTestSupport; +import com.somemore.user.domain.User; +import com.somemore.user.domain.UserCommonAttribute; +import com.somemore.user.domain.UserRole; +import com.somemore.user.dto.UserAuthInfo; +import com.somemore.user.repository.user.UserRepository; +import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import static org.assertj.core.api.Assertions.assertThat; + +@Transactional +class ValidateBasicInfoServiceTest extends IntegrationTestSupport { + + @Autowired + private ValidateBasicInfoService validateBasicInfoService; + + @Autowired + private UserRepository userRepository; + + @Autowired + private UserCommonAttributeRepository userCommonAttributeRepository; + + private User user; + + @BeforeEach + void setup() { + UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.com", "Test User"); + user = userRepository.save(User.from(userAuthInfo, UserRole.VOLUNTEER)); + } + + @DisplayName("필수 입력 정보가 입력되었다면, true를 반환한다.") + @Test + void isBasicInfoComplete_ReturnsTrue() { + // given + UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(user.getId()); + userCommonAttribute.customize(); + userCommonAttributeRepository.save(userCommonAttribute); + + // when + boolean result = validateBasicInfoService.isBasicInfoComplete(user.getId()); + + // then + assertThat(result).isTrue(); + } + + @DisplayName("필수 입력 정보가 입력되지 않았다면, false를 반환한다.") + @Test + void isNotBasicInfoComplete_ReturnsFalse() { + // given + UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(user.getId()); + userCommonAttributeRepository.save(userCommonAttribute); + + // when + boolean result = validateBasicInfoService.isBasicInfoComplete(user.getId()); + + // then + assertThat(result).isFalse(); + } +} \ No newline at end of file From f568e011de9ab4812e59531e9ced9ff94b3a602d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 06:17:48 +0900 Subject: [PATCH 55/61] =?UTF-8?q?test(user):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/service/RegisterUserServiceTest.java | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/test/java/com/somemore/user/service/RegisterUserServiceTest.java diff --git a/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java b/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java new file mode 100644 index 000000000..fbf92f14f --- /dev/null +++ b/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java @@ -0,0 +1,110 @@ +package com.somemore.user.service; + +import com.somemore.global.auth.oauth.domain.CommonOAuthInfo; +import com.somemore.global.auth.oauth.domain.OAuthProvider; +import com.somemore.global.imageupload.service.ImageUploadService; +import com.somemore.support.IntegrationTestSupport; +import com.somemore.user.domain.User; +import com.somemore.user.domain.UserCommonAttribute; +import com.somemore.user.domain.UserRole; +import com.somemore.user.domain.UserSetting; +import com.somemore.user.dto.UserAuthInfo; +import com.somemore.user.repository.user.UserRepository; +import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository; +import com.somemore.user.repository.usersetting.UserSettingRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +@Transactional +class RegisterUserServiceTest extends IntegrationTestSupport { + + @Autowired + private RegisterUserService registerUserService; + + @Autowired + private UserRepository userRepository; + + @Autowired + private UserSettingRepository userSettingRepository; + + @Autowired + private UserCommonAttributeRepository userCommonAttributeRepository; + + @BeforeEach + void setup() { + } + + @DisplayName("OAuth 사용자를 기본 ROLE인 봉사자로 등록할 수 있다.") + @Test + void registerOAuthUser() { + // given + OAuthProvider provider = OAuthProvider.NAVER; + CommonOAuthInfo commonOAuthInfo = new CommonOAuthInfo(provider, "test"); + + // when + User registeredUser = registerUserService.registerOAuthUser(commonOAuthInfo, UserRole.getOAuthUserDefaultRole()); + + // then + User savedUser = userRepository.findById(registeredUser.getId()).orElseThrow(); + UserSetting savedSetting = userSettingRepository.findByUserId(registeredUser.getId()).orElseThrow(); + UserCommonAttribute savedCommonAttribute = userCommonAttributeRepository.findByUserId(registeredUser.getId()).orElseThrow(); + + assertThat(savedUser).isNotNull(); + assertThat(savedUser.getRole()).isEqualTo(UserRole.getOAuthUserDefaultRole()); + assertThat(savedUser.getEmail().length()).isEqualTo(UUID.randomUUID().toString().length() + provider.getProviderName().length()); + + assertThat(savedSetting).isNotNull(); + assertThat(savedSetting.getUserId()).isEqualTo(savedUser.getId()); + boolean userDefaultSetting = false; + assertThat(savedSetting.isSmsAgreed()).isEqualTo(userDefaultSetting); + assertThat(savedSetting.isAuthenticated()).isEqualTo(userDefaultSetting); + + assertThat(savedCommonAttribute).isNotNull(); + assertThat(savedCommonAttribute.getUserId()).isEqualTo(savedUser.getId()); + assertThat(savedCommonAttribute.getNickname().length()).isEqualTo(8); + assertThat(savedCommonAttribute.getIntroduce()).isEqualTo(""); + assertThat(savedCommonAttribute.getImgUrl()).isEqualTo(ImageUploadService.DEFAULT_IMAGE_URL); + assertThat(savedCommonAttribute.isCustomized()).isEqualTo(userDefaultSetting); + + } + + @DisplayName("로컬 사용자를 등록할 수 있다.") + @Test + void registerLocalUser() { + // given + UserAuthInfo userAuthInfo = new UserAuthInfo("test", "test"); + UserRole role = UserRole.CENTER; + + // when + User registeredUser = registerUserService.registerLocalUser(userAuthInfo, role); + + // then + User savedUser = userRepository.findById(registeredUser.getId()).orElseThrow(); + UserSetting savedSetting = userSettingRepository.findByUserId(registeredUser.getId()).orElseThrow(); + UserCommonAttribute savedCommonAttribute = userCommonAttributeRepository.findByUserId(registeredUser.getId()).orElseThrow(); + + assertThat(savedUser).isNotNull(); + assertThat(savedUser.getRole()).isEqualTo(role); + assertThat(savedUser.getEmail()).isEqualTo("test"); + + assertThat(savedSetting).isNotNull(); + assertThat(savedSetting.getUserId()).isEqualTo(savedUser.getId()); + boolean userDefaultSetting = false; + assertThat(savedSetting.isSmsAgreed()).isEqualTo(userDefaultSetting); + assertThat(savedSetting.isAuthenticated()).isEqualTo(userDefaultSetting); + + assertThat(savedCommonAttribute).isNotNull(); + assertThat(savedCommonAttribute.getUserId()).isEqualTo(savedUser.getId()); + assertThat(savedCommonAttribute.getNickname().length()).isEqualTo(8); + assertThat(savedCommonAttribute.getIntroduce()).isEqualTo(""); + assertThat(savedCommonAttribute.getImgUrl()).isEqualTo(ImageUploadService.DEFAULT_IMAGE_URL); + assertThat(savedCommonAttribute.isCustomized()).isEqualTo(userDefaultSetting); + } +} \ No newline at end of file From 71dc6a4f6c48d39602f6725b6d921a454586d06e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 06:36:57 +0900 Subject: [PATCH 56/61] =?UTF-8?q?refactor:=20=EA=B9=83=ED=97=88=EB=B8=8C?= =?UTF-8?q?=20=EA=B0=9C=ED=96=89=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../somemore/global/auth/oauth/checker/OAuthInfoChecker.java | 2 +- .../auth/oauth/converter/NaverOAuthResponseConverter.java | 2 +- .../com/somemore/global/auth/redirect/RedirectService.java | 2 +- .../repository/usersetting/UserSettingRepositoryImplTest.java | 3 +-- .../com/somemore/user/service/RegisterUserServiceTest.java | 2 +- .../somemore/user/service/ValidateBasicInfoServiceTest.java | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoChecker.java b/src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoChecker.java index da360dda6..68ec5f31c 100644 --- a/src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoChecker.java +++ b/src/main/java/com/somemore/global/auth/oauth/checker/OAuthInfoChecker.java @@ -4,4 +4,4 @@ public interface OAuthInfoChecker { boolean doesUserExist(OAuthProvider provider, String id); -} \ No newline at end of file +} diff --git a/src/main/java/com/somemore/global/auth/oauth/converter/NaverOAuthResponseConverter.java b/src/main/java/com/somemore/global/auth/oauth/converter/NaverOAuthResponseConverter.java index 5deea6def..a3d68acb3 100644 --- a/src/main/java/com/somemore/global/auth/oauth/converter/NaverOAuthResponseConverter.java +++ b/src/main/java/com/somemore/global/auth/oauth/converter/NaverOAuthResponseConverter.java @@ -18,4 +18,4 @@ public CommonOAuthInfo convert(OAuth2User oAuth2User) { OAuthProvider.NAVER, naverUserProfileResponseDto.response().id()); } -} \ No newline at end of file +} diff --git a/src/main/java/com/somemore/global/auth/redirect/RedirectService.java b/src/main/java/com/somemore/global/auth/redirect/RedirectService.java index ac9acc85f..36285b9a5 100644 --- a/src/main/java/com/somemore/global/auth/redirect/RedirectService.java +++ b/src/main/java/com/somemore/global/auth/redirect/RedirectService.java @@ -44,4 +44,4 @@ private void handleRedirectFailure(HttpServletRequest request, HttpServletRespon private String buildFallbackUrl() { return frontUrl + RedirectService.ERROR_PATH; } -} \ No newline at end of file +} diff --git a/src/test/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImplTest.java b/src/test/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImplTest.java index c6b11d39e..8c52068c7 100644 --- a/src/test/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImplTest.java +++ b/src/test/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImplTest.java @@ -50,5 +50,4 @@ void saveUserSetting() { assertThat(savedUserSetting.isAuthenticated()).isEqualTo(false); assertThat(savedUserSetting.isSmsAgreed()).isEqualTo(false); } - -} \ No newline at end of file +} diff --git a/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java b/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java index fbf92f14f..633d49e93 100644 --- a/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java +++ b/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java @@ -107,4 +107,4 @@ void registerLocalUser() { assertThat(savedCommonAttribute.getImgUrl()).isEqualTo(ImageUploadService.DEFAULT_IMAGE_URL); assertThat(savedCommonAttribute.isCustomized()).isEqualTo(userDefaultSetting); } -} \ No newline at end of file +} diff --git a/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java b/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java index 7217f27ea..a4e76036b 100644 --- a/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java +++ b/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java @@ -63,4 +63,4 @@ void isNotBasicInfoComplete_ReturnsFalse() { // then assertThat(result).isFalse(); } -} \ No newline at end of file +} From 12186c591e972b605306d56e838454a2a5e19dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:29:04 +0900 Subject: [PATCH 57/61] =?UTF-8?q?refactor:=20=EA=B9=83=ED=97=88=EB=B8=8C?= =?UTF-8?q?=20=EA=B0=9C=ED=96=89=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserCommonAttributeRepositoryImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java b/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java index f08690747..fd05ddbe1 100644 --- a/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java +++ b/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java @@ -36,4 +36,4 @@ void saveUserCommonAttribute() { assertThat(savedUserCommonAttribute.isCustomized()).isEqualTo(false); } -} \ No newline at end of file +} From 0a44b9a886fc5343c8a3a7254289d44a51901b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:37:45 +0900 Subject: [PATCH 58/61] =?UTF-8?q?fix(oauth):=20=ED=8A=B8=EB=9E=9C=EC=9E=AD?= =?UTF-8?q?=EC=85=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/auth/oauth/processor/OAuthUserProcessorImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/somemore/global/auth/oauth/processor/OAuthUserProcessorImpl.java b/src/main/java/com/somemore/global/auth/oauth/processor/OAuthUserProcessorImpl.java index 8eeefdb82..b2ceb6913 100644 --- a/src/main/java/com/somemore/global/auth/oauth/processor/OAuthUserProcessorImpl.java +++ b/src/main/java/com/somemore/global/auth/oauth/processor/OAuthUserProcessorImpl.java @@ -19,7 +19,7 @@ @Slf4j @Service @RequiredArgsConstructor -@Transactional(readOnly = true) +@Transactional public class OAuthUserProcessorImpl implements OAuthUserProcessor { private final OAuthResponseConverter oauthResponseConverter; From 1c3024c9ab36dccd29a074f94c6db54960a6bd4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:38:12 +0900 Subject: [PATCH 59/61] =?UTF-8?q?test(user):=20=EA=B0=9D=EC=B2=B4=EA=B0=84?= =?UTF-8?q?=20=EB=8F=99=EB=93=B1=20=EB=B9=84=EA=B5=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserCommonAttributeRepositoryImplTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java b/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java index fd05ddbe1..0b9827b1f 100644 --- a/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java +++ b/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java @@ -30,6 +30,8 @@ void saveUserCommonAttribute() { // then assertThat(savedUserCommonAttribute).isNotNull(); + assertThat(savedUserCommonAttribute).isEqualTo(userCommonAttribute); + assertThat(savedUserCommonAttribute.getId()).isNotNull(); assertThat(savedUserCommonAttribute.getUserId()).isEqualTo(userId); assertThat(savedUserCommonAttribute.getImgUrl()).isEqualTo(ImageUploadService.DEFAULT_IMAGE_URL); From b0b34902c26274b2bfd5e44d50646c53ffa34d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:42:34 +0900 Subject: [PATCH 60/61] =?UTF-8?q?feat(oauth):=20=EC=A0=95=EC=A0=81=20?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A6=AC=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 도메인 내부에 public으로 create 메서드를 만들어 private 빌더 패턴을 활용 --- .../somemore/global/auth/oauth/domain/OAuthInfo.java | 11 ++++++++++- .../auth/oauth/registrar/OAuthInfoRegistrarImpl.java | 12 +++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/somemore/global/auth/oauth/domain/OAuthInfo.java b/src/main/java/com/somemore/global/auth/oauth/domain/OAuthInfo.java index 3c7250db0..b0f6f9f77 100644 --- a/src/main/java/com/somemore/global/auth/oauth/domain/OAuthInfo.java +++ b/src/main/java/com/somemore/global/auth/oauth/domain/OAuthInfo.java @@ -1,6 +1,7 @@ package com.somemore.global.auth.oauth.domain; import com.somemore.global.common.entity.BaseEntity; +import com.somemore.user.domain.User; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -37,8 +38,16 @@ public class OAuthInfo extends BaseEntity { @Column(name = "oauth_provider", nullable = false) private OAuthProvider oAuthProvider; + public static OAuthInfo create(User user, CommonOAuthInfo commonOAuthInfo) { + return OAuthInfo.builder() + .userId(user.getId()) + .oauthId(commonOAuthInfo.oauthId()) + .oAuthProvider(commonOAuthInfo.provider()) + .build(); + } + @Builder - public OAuthInfo(UUID userId, String oauthId, OAuthProvider oAuthProvider) { + private OAuthInfo(UUID userId, String oauthId, OAuthProvider oAuthProvider) { this.userId = userId; this.oauthId = oauthId; this.oAuthProvider = oAuthProvider; diff --git a/src/main/java/com/somemore/global/auth/oauth/registrar/OAuthInfoRegistrarImpl.java b/src/main/java/com/somemore/global/auth/oauth/registrar/OAuthInfoRegistrarImpl.java index 7124b78b2..34a350036 100644 --- a/src/main/java/com/somemore/global/auth/oauth/registrar/OAuthInfoRegistrarImpl.java +++ b/src/main/java/com/somemore/global/auth/oauth/registrar/OAuthInfoRegistrarImpl.java @@ -19,15 +19,9 @@ public class OAuthInfoRegistrarImpl implements OAuthInfoRegistrar { @Override public OAuthInfo register(User user, CommonOAuthInfo commonOAuthInfo) { - return oauthInfoRepository.save( - createOAuthInfo(user, commonOAuthInfo)); + OAuthInfo oAuthInfo = OAuthInfo.create(user, commonOAuthInfo); + return oauthInfoRepository.save(oAuthInfo); } - private OAuthInfo createOAuthInfo(User user, CommonOAuthInfo commonOAuthInfo) { - return OAuthInfo.builder() - .userId(user.getId()) - .oauthId(commonOAuthInfo.oauthId()) - .oAuthProvider(commonOAuthInfo.provider()) - .build(); - } + } From f25b0488d20425f6bc6c6c937ffc60e71373bc59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:51:55 +0900 Subject: [PATCH 61/61] =?UTF-8?q?test(refactor):=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 소나 큐브 이슈 해결 --- .../UserCommonAttributeRepositoryImplTest.java | 7 ++++--- .../usersetting/UserSettingRepositoryImplTest.java | 9 +++++---- .../user/service/RegisterUserServiceTest.java | 12 ++++-------- .../somemore/user/service/UserQueryServiceTest.java | 2 +- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java b/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java index 0b9827b1f..8bc183b1f 100644 --- a/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java +++ b/src/test/java/com/somemore/user/repository/usercommonattribute/UserCommonAttributeRepositoryImplTest.java @@ -29,13 +29,14 @@ void saveUserCommonAttribute() { UserCommonAttribute savedUserCommonAttribute = userCommonAttributeRepository.save(userCommonAttribute); // then - assertThat(savedUserCommonAttribute).isNotNull(); - assertThat(savedUserCommonAttribute).isEqualTo(userCommonAttribute); + assertThat(savedUserCommonAttribute) + .isNotNull() + .isEqualTo(userCommonAttribute); assertThat(savedUserCommonAttribute.getId()).isNotNull(); assertThat(savedUserCommonAttribute.getUserId()).isEqualTo(userId); assertThat(savedUserCommonAttribute.getImgUrl()).isEqualTo(ImageUploadService.DEFAULT_IMAGE_URL); - assertThat(savedUserCommonAttribute.isCustomized()).isEqualTo(false); + assertThat(savedUserCommonAttribute.isCustomized()).isFalse(); } } diff --git a/src/test/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImplTest.java b/src/test/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImplTest.java index 8c52068c7..9bd5fc2cb 100644 --- a/src/test/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImplTest.java +++ b/src/test/java/com/somemore/user/repository/usersetting/UserSettingRepositoryImplTest.java @@ -30,8 +30,9 @@ void findByUserId() { Optional foundUserSetting = userSettingRepository.findByUserId(userId); // then - assertThat(foundUserSetting).isNotNull(); - assertThat(foundUserSetting).get().isEqualTo(savedUserSetting); + assertThat(foundUserSetting) + .isPresent() + .hasValue(savedUserSetting); } @DisplayName("유저 세팅을 저장할 수 있다.") @@ -47,7 +48,7 @@ void saveUserSetting() { // then assertThat(savedUserSetting).isNotNull(); assertThat(savedUserSetting.getId()).isNotNull(); - assertThat(savedUserSetting.isAuthenticated()).isEqualTo(false); - assertThat(savedUserSetting.isSmsAgreed()).isEqualTo(false); + assertThat(savedUserSetting.isAuthenticated()).isFalse(); + assertThat(savedUserSetting.isSmsAgreed()).isFalse(); } } diff --git a/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java b/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java index 633d49e93..9614c8d87 100644 --- a/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java +++ b/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java @@ -37,10 +37,6 @@ class RegisterUserServiceTest extends IntegrationTestSupport { @Autowired private UserCommonAttributeRepository userCommonAttributeRepository; - @BeforeEach - void setup() { - } - @DisplayName("OAuth 사용자를 기본 ROLE인 봉사자로 등록할 수 있다.") @Test void registerOAuthUser() { @@ -58,8 +54,8 @@ void registerOAuthUser() { assertThat(savedUser).isNotNull(); assertThat(savedUser.getRole()).isEqualTo(UserRole.getOAuthUserDefaultRole()); - assertThat(savedUser.getEmail().length()).isEqualTo(UUID.randomUUID().toString().length() + provider.getProviderName().length()); - + assertThat(savedUser.getEmail()) + .hasSize(UUID.randomUUID().toString().length() + provider.getProviderName().length()); assertThat(savedSetting).isNotNull(); assertThat(savedSetting.getUserId()).isEqualTo(savedUser.getId()); boolean userDefaultSetting = false; @@ -68,7 +64,7 @@ void registerOAuthUser() { assertThat(savedCommonAttribute).isNotNull(); assertThat(savedCommonAttribute.getUserId()).isEqualTo(savedUser.getId()); - assertThat(savedCommonAttribute.getNickname().length()).isEqualTo(8); + assertThat(savedCommonAttribute.getNickname()).hasSize(8); assertThat(savedCommonAttribute.getIntroduce()).isEqualTo(""); assertThat(savedCommonAttribute.getImgUrl()).isEqualTo(ImageUploadService.DEFAULT_IMAGE_URL); assertThat(savedCommonAttribute.isCustomized()).isEqualTo(userDefaultSetting); @@ -102,7 +98,7 @@ void registerLocalUser() { assertThat(savedCommonAttribute).isNotNull(); assertThat(savedCommonAttribute.getUserId()).isEqualTo(savedUser.getId()); - assertThat(savedCommonAttribute.getNickname().length()).isEqualTo(8); + assertThat(savedCommonAttribute.getNickname()).hasSize(8); assertThat(savedCommonAttribute.getIntroduce()).isEqualTo(""); assertThat(savedCommonAttribute.getImgUrl()).isEqualTo(ImageUploadService.DEFAULT_IMAGE_URL); assertThat(savedCommonAttribute.isCustomized()).isEqualTo(userDefaultSetting); diff --git a/src/test/java/com/somemore/user/service/UserQueryServiceTest.java b/src/test/java/com/somemore/user/service/UserQueryServiceTest.java index 2ea3c0ea7..8ecdc67e2 100644 --- a/src/test/java/com/somemore/user/service/UserQueryServiceTest.java +++ b/src/test/java/com/somemore/user/service/UserQueryServiceTest.java @@ -72,6 +72,6 @@ void getIsCustomizedByUserId_ReturnsFalse_WhenDefaultValue() { boolean isCustomized = userQueryService.getIsCustomizedByUserId(user.getId()); // then - assertThat(isCustomized).isEqualTo(false); + assertThat(isCustomized).isFalse(); } }