From e8d147001959b021d7e2679af4570df1122ebfbf 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, 13 Jan 2025 16:44:48 +0900 Subject: [PATCH 01/34] =?UTF-8?q?refactor:=20sign-in=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=9D=B4=EB=8F=99=20=EB=B0=8F?= =?UTF-8?q?=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/VolunteerSignController.java | 48 ------------------- .../auth/controller/SignController.java | 18 ++++++- .../service/GenerateOAuthUrlService.java | 4 +- .../usecase/GenerateOAuthUrlUseCase.java | 2 +- .../service/GenerateOAuthUrlServiceTest.java | 1 + 5 files changed, 21 insertions(+), 52 deletions(-) delete mode 100644 src/main/java/com/somemore/domains/volunteer/controller/VolunteerSignController.java rename src/main/java/com/somemore/{domains/volunteer => global/auth/oauth}/service/GenerateOAuthUrlService.java (89%) rename src/main/java/com/somemore/{domains/volunteer => global/auth/oauth}/usecase/GenerateOAuthUrlUseCase.java (65%) diff --git a/src/main/java/com/somemore/domains/volunteer/controller/VolunteerSignController.java b/src/main/java/com/somemore/domains/volunteer/controller/VolunteerSignController.java deleted file mode 100644 index 0373acc2b..000000000 --- a/src/main/java/com/somemore/domains/volunteer/controller/VolunteerSignController.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.somemore.domains.volunteer.controller; - -import com.somemore.domains.volunteer.usecase.GenerateOAuthUrlUseCase; -import com.somemore.global.auth.signout.usecase.SignOutUseCase; -import com.somemore.global.common.response.ApiResponse; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.view.RedirectView; - -@RestController -@Slf4j -@RequiredArgsConstructor -@RequestMapping("/api/volunteer") -@Tag(name = "Volunteer Sign API", description = "봉사자 로그인, 로그아웃") -public class VolunteerSignController { - - private final GenerateOAuthUrlUseCase generateOAuthUrlUseCase; - private final SignOutUseCase signOutUseCase; - - @PostMapping("/sign-in/oauth/{oauthProvider}") - public RedirectView signIn( - @Parameter(name = "oauthProvider", description = "OAuth 제공자 선택", example = "naver", required = true, schema = @Schema(allowableValues = {"naver"})) - @PathVariable("oauthProvider") String oauthProvider) { - - String redirectUrl = generateOAuthUrlUseCase.generateUrl(oauthProvider); - - return new RedirectView(redirectUrl); - } - - @PostMapping("/sign-out") - public ApiResponse signOut( - HttpServletResponse response, - @AuthenticationPrincipal String userId) { - - signOutUseCase.signOut(response, userId); - - return ApiResponse.ok("로그아웃되었습니다"); - } -} diff --git a/src/main/java/com/somemore/global/auth/controller/SignController.java b/src/main/java/com/somemore/global/auth/controller/SignController.java index 151acbafa..0d7ce9ec6 100644 --- a/src/main/java/com/somemore/global/auth/controller/SignController.java +++ b/src/main/java/com/somemore/global/auth/controller/SignController.java @@ -1,24 +1,30 @@ package com.somemore.global.auth.controller; +import com.somemore.global.auth.oauth.usecase.GenerateOAuthUrlUseCase; import com.somemore.global.auth.dto.SignRequestDto; import com.somemore.global.auth.signout.usecase.SignOutUseCase; import com.somemore.global.common.response.ApiResponse; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.view.RedirectView; @RestController @RequiredArgsConstructor @RequestMapping("/api") -@Tag(name = "Sign API", description = "ID,PW 로그인, 로그아웃") +@Tag(name = "Sign API", description = "유저 로그인, 로그아웃") public class SignController { private final SignOutUseCase signOutUseCase; + private final GenerateOAuthUrlUseCase generateOAuthUrlUseCase; /* * ID 및 PW 기반 로그인 엔드포인트 (Swagger 문서화를 위한 엔드포인트) @@ -37,6 +43,16 @@ public ApiResponse signIn( return ApiResponse.ok("로그인되었습니다."); } + @PostMapping("/sign-in/oauth/{oauthProvider}") + public RedirectView signIn( + @Parameter(name = "oauthProvider", description = "OAuth 제공자 선택", example = "naver", required = true, schema = @Schema(allowableValues = {"naver, kakao"})) + @PathVariable("oauthProvider") String oauthProvider) { + + String redirectUrl = generateOAuthUrlUseCase.generateUrl(oauthProvider); + + return new RedirectView(redirectUrl); + } + @PostMapping("/sign-out") public ApiResponse signOut( HttpServletResponse response, diff --git a/src/main/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlService.java b/src/main/java/com/somemore/global/auth/oauth/service/GenerateOAuthUrlService.java similarity index 89% rename from src/main/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlService.java rename to src/main/java/com/somemore/global/auth/oauth/service/GenerateOAuthUrlService.java index ffb0dd755..d5ce7d845 100644 --- a/src/main/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlService.java +++ b/src/main/java/com/somemore/global/auth/oauth/service/GenerateOAuthUrlService.java @@ -1,7 +1,7 @@ -package com.somemore.domains.volunteer.service; +package com.somemore.global.auth.oauth.service; -import com.somemore.domains.volunteer.usecase.GenerateOAuthUrlUseCase; import com.somemore.global.auth.oauth.domain.OAuthProvider; +import com.somemore.global.auth.oauth.usecase.GenerateOAuthUrlUseCase; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/com/somemore/domains/volunteer/usecase/GenerateOAuthUrlUseCase.java b/src/main/java/com/somemore/global/auth/oauth/usecase/GenerateOAuthUrlUseCase.java similarity index 65% rename from src/main/java/com/somemore/domains/volunteer/usecase/GenerateOAuthUrlUseCase.java rename to src/main/java/com/somemore/global/auth/oauth/usecase/GenerateOAuthUrlUseCase.java index a9b3db0f1..bdfb7797d 100644 --- a/src/main/java/com/somemore/domains/volunteer/usecase/GenerateOAuthUrlUseCase.java +++ b/src/main/java/com/somemore/global/auth/oauth/usecase/GenerateOAuthUrlUseCase.java @@ -1,4 +1,4 @@ -package com.somemore.domains.volunteer.usecase; +package com.somemore.global.auth.oauth.usecase; public interface GenerateOAuthUrlUseCase { String generateUrl(String oAuthProvider); diff --git a/src/test/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlServiceTest.java b/src/test/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlServiceTest.java index 92d6aebfe..a865d1479 100644 --- a/src/test/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlServiceTest.java @@ -1,6 +1,7 @@ package com.somemore.domains.volunteer.service; import com.somemore.global.auth.oauth.domain.OAuthProvider; +import com.somemore.global.auth.oauth.service.GenerateOAuthUrlService; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; From 0c9b3412179d6a0bddb7c5ba821748ef488e638a 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, 13 Jan 2025 20:07:18 +0900 Subject: [PATCH 02/34] =?UTF-8?q?feat(cookie):=20=EC=BF=A0=ED=82=A4=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EB=A1=9C=EC=A7=81=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/controller/SignController.java | 5 ++- .../auth/signout/service/SignOutService.java | 7 ++-- .../auth/signout/usecase/SignOutUseCase.java | 4 ++- .../sign}/SignOutVolunteerServiceTest.java | 34 ++++++++----------- 4 files changed, 25 insertions(+), 25 deletions(-) rename src/test/java/com/somemore/{domains/volunteer/service => global/auth/sign}/SignOutVolunteerServiceTest.java (69%) diff --git a/src/main/java/com/somemore/global/auth/controller/SignController.java b/src/main/java/com/somemore/global/auth/controller/SignController.java index 0d7ce9ec6..81800faab 100644 --- a/src/main/java/com/somemore/global/auth/controller/SignController.java +++ b/src/main/java/com/somemore/global/auth/controller/SignController.java @@ -1,5 +1,6 @@ package com.somemore.global.auth.controller; +import com.somemore.global.auth.annotation.CurrentUser; import com.somemore.global.auth.oauth.usecase.GenerateOAuthUrlUseCase; import com.somemore.global.auth.dto.SignRequestDto; import com.somemore.global.auth.signout.usecase.SignOutUseCase; @@ -17,6 +18,8 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.view.RedirectView; +import java.util.UUID; + @RestController @RequiredArgsConstructor @RequestMapping("/api") @@ -56,7 +59,7 @@ public RedirectView signIn( @PostMapping("/sign-out") public ApiResponse signOut( HttpServletResponse response, - @AuthenticationPrincipal String userId) { + @CurrentUser UUID userId) { signOutUseCase.signOut(response, userId); diff --git a/src/main/java/com/somemore/global/auth/signout/service/SignOutService.java b/src/main/java/com/somemore/global/auth/signout/service/SignOutService.java index 0172f03b7..04af3bf86 100644 --- a/src/main/java/com/somemore/global/auth/signout/service/SignOutService.java +++ b/src/main/java/com/somemore/global/auth/signout/service/SignOutService.java @@ -9,6 +9,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.UUID; + @Slf4j @Service @RequiredArgsConstructor @@ -21,9 +23,8 @@ public class SignOutService implements SignOutUseCase { @Override public void signOut( HttpServletResponse response, - String volunteerId) { + UUID userId) { - cookieUseCase.deleteAccessToken(response); - refreshTokenManager.removeRefreshToken(volunteerId); + refreshTokenManager.removeRefreshToken(userId.toString()); } } diff --git a/src/main/java/com/somemore/global/auth/signout/usecase/SignOutUseCase.java b/src/main/java/com/somemore/global/auth/signout/usecase/SignOutUseCase.java index 480d9abe4..a6ec99e7a 100644 --- a/src/main/java/com/somemore/global/auth/signout/usecase/SignOutUseCase.java +++ b/src/main/java/com/somemore/global/auth/signout/usecase/SignOutUseCase.java @@ -2,7 +2,9 @@ import jakarta.servlet.http.HttpServletResponse; +import java.util.UUID; + public interface SignOutUseCase { - void signOut(HttpServletResponse response, String volunteerId); + void signOut(HttpServletResponse response, UUID userId); } diff --git a/src/test/java/com/somemore/domains/volunteer/service/SignOutVolunteerServiceTest.java b/src/test/java/com/somemore/global/auth/sign/SignOutVolunteerServiceTest.java similarity index 69% rename from src/test/java/com/somemore/domains/volunteer/service/SignOutVolunteerServiceTest.java rename to src/test/java/com/somemore/global/auth/sign/SignOutVolunteerServiceTest.java index 23b4e5e76..867f653e5 100644 --- a/src/test/java/com/somemore/domains/volunteer/service/SignOutVolunteerServiceTest.java +++ b/src/test/java/com/somemore/global/auth/sign/SignOutVolunteerServiceTest.java @@ -1,9 +1,7 @@ -package com.somemore.domains.volunteer.service; +package com.somemore.global.auth.sign; -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.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; @@ -11,6 +9,7 @@ import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; import com.somemore.global.auth.signout.service.SignOutService; import com.somemore.support.IntegrationTestSupport; +import com.somemore.user.domain.UserRole; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -19,17 +18,16 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.mock.web.MockHttpServletResponse; -import java.util.Arrays; +import java.util.UUID; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatNoException; +import static org.assertj.core.api.Assertions.assertThatThrownBy; -class SignOutVolunteerServiceTest extends IntegrationTestSupport { +class SignOutServiceTest extends IntegrationTestSupport { @Autowired private SignOutService signOutVolunteerService; @Autowired - private CookieUseCase cookieUseCase; - @Autowired private RefreshTokenManager refreshTokenManager; @Autowired private JwtGenerator jwtGenerator; @@ -37,14 +35,14 @@ class SignOutVolunteerServiceTest extends IntegrationTestSupport { private RedisTemplate redisTemplate; private MockHttpServletResponse response; - private String volunteerId; + private UUID userId; private UserRole role; @BeforeEach void setUp() { response = new MockHttpServletResponse(); - volunteerId = "test-volunteer"; + userId = UUID.randomUUID(); role = UserRole.VOLUNTEER; } @@ -58,35 +56,31 @@ void tearDown() { @DisplayName("로그아웃 시 액세스 토큰 쿠키를 삭제하고 리프레시 토큰을 제거해야 한다.") void signOutDeletesTokens() { // Given - EncodedToken accessToken = jwtGenerator.generateToken(volunteerId, role.getAuthority(), TokenType.ACCESS); + EncodedToken accessToken = jwtGenerator.generateToken(userId.toString(), role.getAuthority(), TokenType.ACCESS); RefreshToken refreshToken = new RefreshToken( - volunteerId, + userId.toString(), accessToken, - jwtGenerator.generateToken(volunteerId, role.getAuthority(), TokenType.REFRESH)); + jwtGenerator.generateToken(userId.toString(), role.getAuthority(), TokenType.REFRESH)); refreshTokenManager.save(refreshToken); - cookieUseCase.setToken(response, accessToken.value(), TokenType.ACCESS); // When - signOutVolunteerService.signOut(response, volunteerId); + signOutVolunteerService.signOut(response, userId); // Then assertThatThrownBy(() -> refreshTokenManager.findRefreshTokenByAccessToken(accessToken)) .isInstanceOf(JwtException.class) .hasMessage(JwtErrorType.EXPIRED_TOKEN.getMessage()); - - assertThat(Arrays.toString(response.getCookies())).contains(TokenType.SIGN_OUT.name()); } @Test @DisplayName("로그아웃 시 리프레시 토큰이 없어도 예외가 발생하지 않는다.") void signOutWithoutRefreshToken() { // When - signOutVolunteerService.signOut(response, volunteerId); + signOutVolunteerService.signOut(response, userId); // Then - assertThatNoException().isThrownBy(() -> signOutVolunteerService.signOut(response, volunteerId)); - assertThat(Arrays.toString(response.getCookies())).contains(TokenType.SIGN_OUT.name()); + assertThatNoException().isThrownBy(() -> signOutVolunteerService.signOut(response, userId)); } } From 61fa54c4b9ef3af64972f0bd45a6798786e376e4 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, 13 Jan 2025 20:17:44 +0900 Subject: [PATCH 03/34] =?UTF-8?q?feat(sign):=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=82=AD=EC=A0=9C,?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EA=B0=9C=EC=84=A0,=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/controller/SignController.java | 68 ------------------- .../auth/controller/SignInController.java | 58 ++++++++++++++++ .../auth/controller/SignOutController.java | 32 +++++++++ .../service/GenerateOAuthUrlService.java | 33 --------- .../usecase/GenerateOAuthUrlUseCase.java | 5 -- .../service/GenerateOAuthUrlServiceTest.java | 51 -------------- 6 files changed, 90 insertions(+), 157 deletions(-) delete mode 100644 src/main/java/com/somemore/global/auth/controller/SignController.java create mode 100644 src/main/java/com/somemore/global/auth/controller/SignInController.java create mode 100644 src/main/java/com/somemore/global/auth/controller/SignOutController.java delete mode 100644 src/main/java/com/somemore/global/auth/oauth/service/GenerateOAuthUrlService.java delete mode 100644 src/main/java/com/somemore/global/auth/oauth/usecase/GenerateOAuthUrlUseCase.java delete mode 100644 src/test/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlServiceTest.java diff --git a/src/main/java/com/somemore/global/auth/controller/SignController.java b/src/main/java/com/somemore/global/auth/controller/SignController.java deleted file mode 100644 index 81800faab..000000000 --- a/src/main/java/com/somemore/global/auth/controller/SignController.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.somemore.global.auth.controller; - -import com.somemore.global.auth.annotation.CurrentUser; -import com.somemore.global.auth.oauth.usecase.GenerateOAuthUrlUseCase; -import com.somemore.global.auth.dto.SignRequestDto; -import com.somemore.global.auth.signout.usecase.SignOutUseCase; -import com.somemore.global.common.response.ApiResponse; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.view.RedirectView; - -import java.util.UUID; - -@RestController -@RequiredArgsConstructor -@RequestMapping("/api") -@Tag(name = "Sign API", description = "유저 로그인, 로그아웃") -public class SignController { - - private final SignOutUseCase signOutUseCase; - private final GenerateOAuthUrlUseCase generateOAuthUrlUseCase; - - /* - * ID 및 PW 기반 로그인 엔드포인트 (Swagger 문서화를 위한 엔드포인트) - * - * 이 엔드포인트는 실제로 작동하지 않으며, Spring Security 필터 체인에 의해 요청이 처리됩니다. - * 로그인 요청은 필터에서 가로채어 인증 절차를 수행하며, 이 엔드포인트로 전달되지 않습니다. - * 따라서 이 엔드포인트는 로그인 요청의 처리를 위한 진입점이 아니라, - * Swagger API 문서화를 위해 정의된 엔드포인트입니다. - * - * 실제 로그인 절차는 필터에서 처리됩니다. - */ - @PostMapping("/sign-in/id-pw") - public ApiResponse signIn( - @RequestParam SignRequestDto signRequestDto - ) { - return ApiResponse.ok("로그인되었습니다."); - } - - @PostMapping("/sign-in/oauth/{oauthProvider}") - public RedirectView signIn( - @Parameter(name = "oauthProvider", description = "OAuth 제공자 선택", example = "naver", required = true, schema = @Schema(allowableValues = {"naver, kakao"})) - @PathVariable("oauthProvider") String oauthProvider) { - - String redirectUrl = generateOAuthUrlUseCase.generateUrl(oauthProvider); - - return new RedirectView(redirectUrl); - } - - @PostMapping("/sign-out") - public ApiResponse signOut( - HttpServletResponse response, - @CurrentUser UUID userId) { - - signOutUseCase.signOut(response, userId); - - return ApiResponse.ok("로그아웃되었습니다"); - } -} diff --git a/src/main/java/com/somemore/global/auth/controller/SignInController.java b/src/main/java/com/somemore/global/auth/controller/SignInController.java new file mode 100644 index 000000000..59bed19fb --- /dev/null +++ b/src/main/java/com/somemore/global/auth/controller/SignInController.java @@ -0,0 +1,58 @@ +package com.somemore.global.auth.controller; + +import com.somemore.global.auth.dto.SignRequestDto; +import com.somemore.global.common.response.ApiResponse; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping() +@Tag(name = "SignIn API", description = "유저 로그인") +public class SignInController { + + /** + * ID 및 PW 기반 로그인 엔드포인트 (Swagger 문서화를 위한 더미 엔드포인트) + *

+ * 이 엔드포인트는 실제로 동작하지 않으며, Spring Security의 필터 체인에 의해 요청이 처리됩니다. + * 사용자가 ID/PW로 로그인을 시도하면, 해당 요청은 Spring Security 필터 체인에서 가로채어 인증 절차를 수행하며, + * 이 엔드포인트로 전달되지 않습니다. + *

+ * 따라서 이 엔드포인트는 실제 인증 로직과는 무관하며, Swagger API 문서화를 위해 정의된 것입니다. + *

+ * 실제 인증 절차는 Spring Security의 필터에서 처리됩니다. + */ + @PostMapping("/api/sign-in/id-pw") + public ApiResponse signIn( + @RequestParam SignRequestDto signRequestDto) { + return ApiResponse.ok("로그인되었습니다."); + } + + /** + * OAuth2 소셜 로그인 엔드포인트 (Swagger 문서화를 위한 더미 엔드포인트) + *

+ * 이 엔드포인트는 실제로 동작하지 않으며, Spring Security가 제공하는 OAuth2 클라이언트 기능에 의해 처리됩니다. + * 클라이언트가 특정 OAuth 제공자(Naver, Kakao 등)로 로그인 요청을 보내면, + * 요청은 Spring Security의 OAuth2 필터 체인에 의해 가로채어 처리되며, 이 엔드포인트로 전달되지 않습니다. + *

+ * 따라서 이 엔드포인트는 실제 소셜 로그인 처리를 위한 진입점이 아니라, + * Swagger API 문서화를 위해 정의된 것입니다. + *

+ * 실제 OAuth2 로그인 절차는 Spring Security가 처리합니다. + */ + @GetMapping("oauth2/authorization/{oauthProvider}") + public ApiResponse signIn( + @Parameter(name = "oauthProvider", description = "OAuth 제공자 선택", example = "naver", required = true, schema = @Schema(allowableValues = {"naver, kakao"})) + @PathVariable("oauthProvider") String oauthProvider) { + + return ApiResponse.ok("로그인되었습니다."); + } +} diff --git a/src/main/java/com/somemore/global/auth/controller/SignOutController.java b/src/main/java/com/somemore/global/auth/controller/SignOutController.java new file mode 100644 index 000000000..f0b018904 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/controller/SignOutController.java @@ -0,0 +1,32 @@ +package com.somemore.global.auth.controller; + +import com.somemore.global.auth.annotation.CurrentUser; +import com.somemore.global.auth.signout.usecase.SignOutUseCase; +import com.somemore.global.common.response.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.UUID; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api") +@Tag(name = "SignOut API", description = "유저 로그아웃") +public class SignOutController { + + private final SignOutUseCase signOutUseCase; + + @PostMapping("/sign-out") + public ApiResponse signOut( + HttpServletResponse response, + @CurrentUser UUID userId) { + + signOutUseCase.signOut(response, userId); + + return ApiResponse.ok("로그아웃되었습니다"); + } +} diff --git a/src/main/java/com/somemore/global/auth/oauth/service/GenerateOAuthUrlService.java b/src/main/java/com/somemore/global/auth/oauth/service/GenerateOAuthUrlService.java deleted file mode 100644 index d5ce7d845..000000000 --- a/src/main/java/com/somemore/global/auth/oauth/service/GenerateOAuthUrlService.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.somemore.global.auth.oauth.service; - -import com.somemore.global.auth.oauth.domain.OAuthProvider; -import com.somemore.global.auth.oauth.usecase.GenerateOAuthUrlUseCase; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import org.springframework.web.util.UriComponentsBuilder; - -@Slf4j -@Service -@RequiredArgsConstructor -public class GenerateOAuthUrlService implements GenerateOAuthUrlUseCase { - - @Value("${app.back-url}") - private String backendRootUrl; - - @Override - public String generateUrl(String oAuthProvider) { - return UriComponentsBuilder.fromHttpUrl(generateBaseUrl()) - .pathSegment(OAuthProvider.from(oAuthProvider).getProviderName()) - .build() - .toUriString(); - } - - private String generateBaseUrl() { - return UriComponentsBuilder.fromHttpUrl(backendRootUrl) - .path("/oauth2/authorization") - .build() - .toUriString(); - } -} diff --git a/src/main/java/com/somemore/global/auth/oauth/usecase/GenerateOAuthUrlUseCase.java b/src/main/java/com/somemore/global/auth/oauth/usecase/GenerateOAuthUrlUseCase.java deleted file mode 100644 index bdfb7797d..000000000 --- a/src/main/java/com/somemore/global/auth/oauth/usecase/GenerateOAuthUrlUseCase.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.somemore.global.auth.oauth.usecase; - -public interface GenerateOAuthUrlUseCase { - String generateUrl(String oAuthProvider); -} diff --git a/src/test/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlServiceTest.java b/src/test/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlServiceTest.java deleted file mode 100644 index a865d1479..000000000 --- a/src/test/java/com/somemore/domains/volunteer/service/GenerateOAuthUrlServiceTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.somemore.domains.volunteer.service; - -import com.somemore.global.auth.oauth.domain.OAuthProvider; -import com.somemore.global.auth.oauth.service.GenerateOAuthUrlService; -import com.somemore.support.IntegrationTestSupport; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; - -import static org.assertj.core.api.Assertions.assertThat; - -class GenerateOAuthUrlServiceTest extends IntegrationTestSupport { - - @Autowired - private GenerateOAuthUrlService generateOAuthUrlService; - - @Value("${app.back-url}") - private String backendRootUrl; - - - @Test - @DisplayName("Naver 제공자를 위한 OAuth URL이 올바르게 생성되는지 검증") - void generateUrl_ShouldReturnCorrectUrl_ForNaver() { - // Given - String oAuthProvider = OAuthProvider.NAVER.getProviderName(); - - // When - String result = generateOAuthUrlService.generateUrl(oAuthProvider); - - // Then - String expectedUrl = backendRootUrl + "/oauth2/authorization/naver"; - - assertThat(result).isEqualTo(expectedUrl); - } - - @Test - @DisplayName("Kakao 제공자를 위한 OAuth URL이 올바르게 생성되는지 검증") - void generateUrl_ShouldReturnCorrectUrl_ForKakao() { - // Given - String oAuthProvider = OAuthProvider.KAKAO.getProviderName(); - - // When - String result = generateOAuthUrlService.generateUrl(oAuthProvider); - - // Then - String expectedUrl = backendRootUrl + "/oauth2/authorization/kakao"; - - assertThat(result).isEqualTo(expectedUrl); - } -} From 4f144371607cf8fdc32e59b8ae5a50f252e36c43 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, 13 Jan 2025 20:25:00 +0900 Subject: [PATCH 04/34] =?UTF-8?q?feat(sign):=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=9C=A0=EC=A0=80=20=EC=A0=95=EB=B3=B4=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20=EC=97=94=EB=93=9C=ED=8F=AC=EC=9D=B8=ED=8A=B8=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 --- .../global/auth/controller/AuthController.java | 11 ----------- .../global/auth/usecase/AuthQueryService.java | 6 ------ .../global/auth/usecase/AuthQueryUseCase.java | 1 - 3 files changed, 18 deletions(-) diff --git a/src/main/java/com/somemore/global/auth/controller/AuthController.java b/src/main/java/com/somemore/global/auth/controller/AuthController.java index f5fdeccde..bf2180e7a 100644 --- a/src/main/java/com/somemore/global/auth/controller/AuthController.java +++ b/src/main/java/com/somemore/global/auth/controller/AuthController.java @@ -21,17 +21,6 @@ public class AuthController { private final AuthQueryUseCase authQueryUseCase; - @GetMapping("/user-info") - public ApiResponse getUserInfo( - @CurrentUser UUID userId - ) { - UserRole role = authQueryUseCase.getRoleByUserId(userId); - - return ApiResponse.ok(HttpStatus.OK.value(), - UserInfoResponseDto.of(userId, role), - "유저 정보 응답 성공"); - } - @GetMapping("/token") public ApiResponse getToken( @CurrentUser UUID userId diff --git a/src/main/java/com/somemore/global/auth/usecase/AuthQueryService.java b/src/main/java/com/somemore/global/auth/usecase/AuthQueryService.java index 9da0b7180..328bef0a9 100644 --- a/src/main/java/com/somemore/global/auth/usecase/AuthQueryService.java +++ b/src/main/java/com/somemore/global/auth/usecase/AuthQueryService.java @@ -15,14 +15,8 @@ @Transactional(readOnly = true) public class AuthQueryService implements AuthQueryUseCase { - private final UserQueryUseCase userQueryUseCase; private final RefreshTokenManager refreshTokenManager; - @Override - public UserRole getRoleByUserId(UUID userId) { - return userQueryUseCase.getRoleById(userId); - } - @Override public EncodedToken getAccessTokenByUserId(UUID userId) { return new EncodedToken( diff --git a/src/main/java/com/somemore/global/auth/usecase/AuthQueryUseCase.java b/src/main/java/com/somemore/global/auth/usecase/AuthQueryUseCase.java index 74caed416..b01397d2f 100644 --- a/src/main/java/com/somemore/global/auth/usecase/AuthQueryUseCase.java +++ b/src/main/java/com/somemore/global/auth/usecase/AuthQueryUseCase.java @@ -6,6 +6,5 @@ import java.util.UUID; public interface AuthQueryUseCase { - UserRole getRoleByUserId(UUID userId); EncodedToken getAccessTokenByUserId(UUID userId); } From 53a14196bf4c493ac2432dc3d5706489b1326853 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, 13 Jan 2025 21:00:48 +0900 Subject: [PATCH 05/34] =?UTF-8?q?feat(ApiResponse):=20=EA=B0=80=EB=8F=85?= =?UTF-8?q?=EC=84=B1=20=EA=B0=9C=EC=84=A0,=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/common/response/ApiResponse.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/somemore/global/common/response/ApiResponse.java b/src/main/java/com/somemore/global/common/response/ApiResponse.java index c88f32b39..427ddf281 100644 --- a/src/main/java/com/somemore/global/common/response/ApiResponse.java +++ b/src/main/java/com/somemore/global/common/response/ApiResponse.java @@ -3,11 +3,14 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.http.HttpStatus; @NoArgsConstructor @Getter public class ApiResponse { + public static final String EMPTY = ""; + @Schema(description = "응답 상태 코드. 성공 시 200, 실패 시 오류 코드", example = "200") private int code; @Schema(description = "응답에 대한 메시지. 요청 성공/실패에 대한 설명", example = "요청 성공") @@ -15,16 +18,20 @@ public class ApiResponse { @Schema(description = "API 요청 처리 결과로 반환되는 데이터") private T data; - public static ApiResponse ok(int status, T data, String message) { - return new ApiResponse<>(status, message, data); + public static ApiResponse ok(String message) { + return new ApiResponse<>(HttpStatus.OK.value(), message, ""); + } + + public static ApiResponse ok(T data, String message) { + return new ApiResponse<>(HttpStatus.OK.value(), message, data); } public static ApiResponse ok(int status, String message) { - return new ApiResponse<>(status, message, ""); + return new ApiResponse<>(status, message, EMPTY); } - public static ApiResponse ok(String message) { - return new ApiResponse<>(200, message, ""); + public static ApiResponse ok(int status, T data, String message) { + return new ApiResponse<>(status, message, data); } public ApiResponse(int code, String message, T data) { From 23fd618ca283a760bedaa08bddec50632abc9069 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, 13 Jan 2025 21:02:54 +0900 Subject: [PATCH 06/34] =?UTF-8?q?refactor:=20DTO=20=EB=AA=85=EB=AA=85=20?= =?UTF-8?q?=EA=B5=AC=EC=B2=B4=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/{controller => sign/in}/SignInController.java | 5 ++--- .../SignRequestDto.java => sign/in/SignInRequestDto.java} | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) rename src/main/java/com/somemore/global/auth/{controller => sign/in}/SignInController.java (94%) rename src/main/java/com/somemore/global/auth/{dto/SignRequestDto.java => sign/in/SignInRequestDto.java} (84%) diff --git a/src/main/java/com/somemore/global/auth/controller/SignInController.java b/src/main/java/com/somemore/global/auth/sign/in/SignInController.java similarity index 94% rename from src/main/java/com/somemore/global/auth/controller/SignInController.java rename to src/main/java/com/somemore/global/auth/sign/in/SignInController.java index 59bed19fb..7b603fb43 100644 --- a/src/main/java/com/somemore/global/auth/controller/SignInController.java +++ b/src/main/java/com/somemore/global/auth/sign/in/SignInController.java @@ -1,6 +1,5 @@ -package com.somemore.global.auth.controller; +package com.somemore.global.auth.sign.in; -import com.somemore.global.auth.dto.SignRequestDto; import com.somemore.global.common.response.ApiResponse; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Schema; @@ -32,7 +31,7 @@ public class SignInController { */ @PostMapping("/api/sign-in/id-pw") public ApiResponse signIn( - @RequestParam SignRequestDto signRequestDto) { + @RequestParam SignInRequestDto signInRequestDto) { return ApiResponse.ok("로그인되었습니다."); } diff --git a/src/main/java/com/somemore/global/auth/dto/SignRequestDto.java b/src/main/java/com/somemore/global/auth/sign/in/SignInRequestDto.java similarity index 84% rename from src/main/java/com/somemore/global/auth/dto/SignRequestDto.java rename to src/main/java/com/somemore/global/auth/sign/in/SignInRequestDto.java index dca6711c1..462171e35 100644 --- a/src/main/java/com/somemore/global/auth/dto/SignRequestDto.java +++ b/src/main/java/com/somemore/global/auth/sign/in/SignInRequestDto.java @@ -1,11 +1,11 @@ -package com.somemore.global.auth.dto; +package com.somemore.global.auth.sign.in; import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; import io.swagger.v3.oas.annotations.media.Schema; @JsonNaming(SnakeCaseStrategy.class) -public record SignRequestDto( +public record SignInRequestDto( @Schema(description = "ID", example = "somemore") String accountId, @Schema(description = "PW", example = "password1234") From eaf0190ebb43dad6f31c0ecf462e0f5a1a51d84b 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, 13 Jan 2025 21:04:13 +0900 Subject: [PATCH 07/34] =?UTF-8?q?feat(sign-out):=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=95=84=EC=9B=83=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99,=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/{controller => sign/out}/SignOutController.java | 3 +-- .../auth/{signout/service => sign/out}/SignOutService.java | 5 +---- .../auth/{signout/usecase => sign/out}/SignOutUseCase.java | 2 +- .../global/auth/sign/SignOutVolunteerServiceTest.java | 4 ++-- 4 files changed, 5 insertions(+), 9 deletions(-) rename src/main/java/com/somemore/global/auth/{controller => sign/out}/SignOutController.java (89%) rename src/main/java/com/somemore/global/auth/{signout/service => sign/out}/SignOutService.java (76%) rename src/main/java/com/somemore/global/auth/{signout/usecase => sign/out}/SignOutUseCase.java (77%) diff --git a/src/main/java/com/somemore/global/auth/controller/SignOutController.java b/src/main/java/com/somemore/global/auth/sign/out/SignOutController.java similarity index 89% rename from src/main/java/com/somemore/global/auth/controller/SignOutController.java rename to src/main/java/com/somemore/global/auth/sign/out/SignOutController.java index f0b018904..b7a07c45f 100644 --- a/src/main/java/com/somemore/global/auth/controller/SignOutController.java +++ b/src/main/java/com/somemore/global/auth/sign/out/SignOutController.java @@ -1,7 +1,6 @@ -package com.somemore.global.auth.controller; +package com.somemore.global.auth.sign.out; import com.somemore.global.auth.annotation.CurrentUser; -import com.somemore.global.auth.signout.usecase.SignOutUseCase; import com.somemore.global.common.response.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletResponse; diff --git a/src/main/java/com/somemore/global/auth/signout/service/SignOutService.java b/src/main/java/com/somemore/global/auth/sign/out/SignOutService.java similarity index 76% rename from src/main/java/com/somemore/global/auth/signout/service/SignOutService.java rename to src/main/java/com/somemore/global/auth/sign/out/SignOutService.java index 04af3bf86..3e02134d2 100644 --- a/src/main/java/com/somemore/global/auth/signout/service/SignOutService.java +++ b/src/main/java/com/somemore/global/auth/sign/out/SignOutService.java @@ -1,8 +1,6 @@ -package com.somemore.global.auth.signout.service; +package com.somemore.global.auth.sign.out; -import com.somemore.global.auth.cookie.CookieUseCase; import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; -import com.somemore.global.auth.signout.usecase.SignOutUseCase; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -17,7 +15,6 @@ @Transactional public class SignOutService implements SignOutUseCase { - private final CookieUseCase cookieUseCase; private final RefreshTokenManager refreshTokenManager; @Override diff --git a/src/main/java/com/somemore/global/auth/signout/usecase/SignOutUseCase.java b/src/main/java/com/somemore/global/auth/sign/out/SignOutUseCase.java similarity index 77% rename from src/main/java/com/somemore/global/auth/signout/usecase/SignOutUseCase.java rename to src/main/java/com/somemore/global/auth/sign/out/SignOutUseCase.java index a6ec99e7a..4a5ca4821 100644 --- a/src/main/java/com/somemore/global/auth/signout/usecase/SignOutUseCase.java +++ b/src/main/java/com/somemore/global/auth/sign/out/SignOutUseCase.java @@ -1,4 +1,4 @@ -package com.somemore.global.auth.signout.usecase; +package com.somemore.global.auth.sign.out; import jakarta.servlet.http.HttpServletResponse; diff --git a/src/test/java/com/somemore/global/auth/sign/SignOutVolunteerServiceTest.java b/src/test/java/com/somemore/global/auth/sign/SignOutVolunteerServiceTest.java index 867f653e5..daa2fb081 100644 --- a/src/test/java/com/somemore/global/auth/sign/SignOutVolunteerServiceTest.java +++ b/src/test/java/com/somemore/global/auth/sign/SignOutVolunteerServiceTest.java @@ -7,7 +7,7 @@ import com.somemore.global.auth.jwt.generator.JwtGenerator; import com.somemore.global.auth.jwt.refresh.domain.RefreshToken; import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; -import com.somemore.global.auth.signout.service.SignOutService; +import com.somemore.global.auth.sign.out.SignOutService; import com.somemore.support.IntegrationTestSupport; import com.somemore.user.domain.UserRole; import org.junit.jupiter.api.AfterEach; @@ -69,7 +69,7 @@ void signOutDeletesTokens() { signOutVolunteerService.signOut(response, userId); // Then - assertThatThrownBy(() -> refreshTokenManager.findRefreshTokenByAccessToken(accessToken)) + assertThatThrownBy(() -> refreshTokenManager.getRefreshTokenByAccessToken(accessToken)) .isInstanceOf(JwtException.class) .hasMessage(JwtErrorType.EXPIRED_TOKEN.getMessage()); } From 189732b42e24db70f34822fd37f84cb6e929a1de 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, 13 Jan 2025 21:04:41 +0900 Subject: [PATCH 08/34] =?UTF-8?q?feat:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EB=A1=9C=EC=A7=81=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/auth/dto/UserInfoResponseDto.java | 22 ---------------- .../global/auth/usecase/AuthQueryService.java | 26 ------------------- .../global/auth/usecase/AuthQueryUseCase.java | 10 ------- 3 files changed, 58 deletions(-) delete mode 100644 src/main/java/com/somemore/global/auth/dto/UserInfoResponseDto.java delete mode 100644 src/main/java/com/somemore/global/auth/usecase/AuthQueryService.java delete mode 100644 src/main/java/com/somemore/global/auth/usecase/AuthQueryUseCase.java diff --git a/src/main/java/com/somemore/global/auth/dto/UserInfoResponseDto.java b/src/main/java/com/somemore/global/auth/dto/UserInfoResponseDto.java deleted file mode 100644 index 3e2ccbd81..000000000 --- a/src/main/java/com/somemore/global/auth/dto/UserInfoResponseDto.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.somemore.global.auth.dto; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.somemore.user.domain.UserRole; -import io.swagger.v3.oas.annotations.media.Schema; - -import java.util.UUID; - -@Schema(description = "유저 정보 DTO") -public record UserInfoResponseDto( - @JsonProperty("USER_ID") - @Schema(description = "유저 ID") - String userId, - - @JsonProperty("ROLE") - @Schema(description = "유저 ROLE") - String role -) { - public static UserInfoResponseDto of(UUID userId, UserRole role) { - return new UserInfoResponseDto(userId.toString(), role.getAuthority()); - } -} diff --git a/src/main/java/com/somemore/global/auth/usecase/AuthQueryService.java b/src/main/java/com/somemore/global/auth/usecase/AuthQueryService.java deleted file mode 100644 index 328bef0a9..000000000 --- a/src/main/java/com/somemore/global/auth/usecase/AuthQueryService.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.somemore.global.auth.usecase; - -import com.somemore.global.auth.jwt.domain.EncodedToken; -import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; -import com.somemore.user.domain.UserRole; -import com.somemore.user.usecase.UserQueryUseCase; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.UUID; - -@Service -@RequiredArgsConstructor -@Transactional(readOnly = true) -public class AuthQueryService implements AuthQueryUseCase { - - private final RefreshTokenManager refreshTokenManager; - - @Override - public EncodedToken getAccessTokenByUserId(UUID userId) { - return new EncodedToken( - refreshTokenManager.findRefreshTokenByUserId(userId) - .getAccessToken()); - } -} diff --git a/src/main/java/com/somemore/global/auth/usecase/AuthQueryUseCase.java b/src/main/java/com/somemore/global/auth/usecase/AuthQueryUseCase.java deleted file mode 100644 index b01397d2f..000000000 --- a/src/main/java/com/somemore/global/auth/usecase/AuthQueryUseCase.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.somemore.global.auth.usecase; - -import com.somemore.global.auth.jwt.domain.EncodedToken; -import com.somemore.user.domain.UserRole; - -import java.util.UUID; - -public interface AuthQueryUseCase { - EncodedToken getAccessTokenByUserId(UUID userId); -} From b2c20304ac03f4fcefd70ad232d702ed254b4ece 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, 13 Jan 2025 21:16:37 +0900 Subject: [PATCH 09/34] =?UTF-8?q?feat(token):=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=EB=A1=9C=EC=A7=81=20=EA=B0=9C=EC=84=A0,?= =?UTF-8?q?=20=EB=AA=85=EB=AA=85=20=EA=B5=AC=EC=B2=B4=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TokenExchangeController.java} | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) rename src/main/java/com/somemore/global/auth/{controller/AuthController.java => jwt/controller/TokenExchangeController.java} (57%) diff --git a/src/main/java/com/somemore/global/auth/controller/AuthController.java b/src/main/java/com/somemore/global/auth/jwt/controller/TokenExchangeController.java similarity index 57% rename from src/main/java/com/somemore/global/auth/controller/AuthController.java rename to src/main/java/com/somemore/global/auth/jwt/controller/TokenExchangeController.java index bf2180e7a..1adc89f43 100644 --- a/src/main/java/com/somemore/global/auth/controller/AuthController.java +++ b/src/main/java/com/somemore/global/auth/jwt/controller/TokenExchangeController.java @@ -1,11 +1,10 @@ -package com.somemore.global.auth.controller; +package com.somemore.global.auth.jwt.controller; import com.somemore.global.auth.annotation.CurrentUser; -import com.somemore.global.auth.dto.UserInfoResponseDto; import com.somemore.global.auth.jwt.domain.EncodedToken; -import com.somemore.global.auth.usecase.AuthQueryUseCase; +import com.somemore.global.auth.jwt.manager.TokenManager; import com.somemore.global.common.response.ApiResponse; -import com.somemore.user.domain.UserRole; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; @@ -16,16 +15,17 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/auth") -public class AuthController { +@RequestMapping("/api/auth/token") +@Tag(name = "Token Exchange API", description = "SignInToken을 AccessToken으로 교환하는 API") +public class TokenExchangeController { - private final AuthQueryUseCase authQueryUseCase; + private final TokenManager tokenManager; - @GetMapping("/token") - public ApiResponse getToken( + @GetMapping("/exchange") + public ApiResponse exchangeToken( @CurrentUser UUID userId ) { - EncodedToken accessToken = authQueryUseCase.getAccessTokenByUserId(userId); + EncodedToken accessToken = tokenManager.getAccessTokenByUserId(userId); return ApiResponse.ok(HttpStatus.OK.value(), accessToken.getValueWithPrefix(), From 4d4b3f5a7b97ca70b386361e551b6e352345fd32 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, 13 Jan 2025 21:23:54 +0900 Subject: [PATCH 10/34] =?UTF-8?q?refactor(token):=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0,=20=EB=AA=85=EB=AA=85=20=EC=88=98=EC=A0=95,?= =?UTF-8?q?=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/auth/jwt/domain/EncodedToken.java | 4 +++ .../{refresh => }/domain/RefreshToken.java | 3 +-- .../global/auth/jwt/filter/JwtAuthFilter.java | 2 +- .../auth/jwt/generator/HmacJwtGenerator.java | 16 ++++++------ .../RedisTokenManager.java} | 16 ++++++------ .../global/auth/jwt/manager/TokenManager.java | 16 ++++++++++++ .../refresh/manager/RefreshTokenManager.java | 16 ------------ .../refresher/DefaultJwtRefresher.java | 16 ++++++------ .../{refresh => }/refresher/JwtRefresher.java | 2 +- .../repository/RefreshTokenRepository.java | 4 +-- .../service/GenerateTokensOnLoginService.java | 8 +++--- .../global/auth/jwt/service/JwtService.java | 2 +- .../global/auth/sign/out/SignOutService.java | 6 ++--- .../auth/jwt/service/JwtServiceTest.java | 25 ++++++++++--------- .../sign/SignOutVolunteerServiceTest.java | 10 ++++---- 15 files changed, 77 insertions(+), 69 deletions(-) rename src/main/java/com/somemore/global/auth/jwt/{refresh => }/domain/RefreshToken.java (89%) rename src/main/java/com/somemore/global/auth/jwt/{refresh/manager/RedisRefreshTokenManager.java => manager/RedisTokenManager.java} (64%) create mode 100644 src/main/java/com/somemore/global/auth/jwt/manager/TokenManager.java delete mode 100644 src/main/java/com/somemore/global/auth/jwt/refresh/manager/RefreshTokenManager.java rename src/main/java/com/somemore/global/auth/jwt/{refresh => }/refresher/DefaultJwtRefresher.java (68%) rename src/main/java/com/somemore/global/auth/jwt/{refresh => }/refresher/JwtRefresher.java (73%) rename src/main/java/com/somemore/global/auth/jwt/{refresh => }/repository/RefreshTokenRepository.java (74%) 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 311d37170..beeda1f09 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 @@ -5,6 +5,10 @@ public record EncodedToken(String value) { private static final String UNINITIALIZED = "UNINITIALIZED"; private static final String PREFIX = "Bearer "; + public static EncodedToken from(String value) { + return new EncodedToken(value); + } + public String getValueWithPrefix() { return PREFIX + this.value; } diff --git a/src/main/java/com/somemore/global/auth/jwt/refresh/domain/RefreshToken.java b/src/main/java/com/somemore/global/auth/jwt/domain/RefreshToken.java similarity index 89% rename from src/main/java/com/somemore/global/auth/jwt/refresh/domain/RefreshToken.java rename to src/main/java/com/somemore/global/auth/jwt/domain/RefreshToken.java index e1368c9d9..fcc436a07 100644 --- a/src/main/java/com/somemore/global/auth/jwt/refresh/domain/RefreshToken.java +++ b/src/main/java/com/somemore/global/auth/jwt/domain/RefreshToken.java @@ -1,6 +1,5 @@ -package com.somemore.global.auth.jwt.refresh.domain; +package com.somemore.global.auth.jwt.domain; -import com.somemore.global.auth.jwt.domain.EncodedToken; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/somemore/global/auth/jwt/filter/JwtAuthFilter.java b/src/main/java/com/somemore/global/auth/jwt/filter/JwtAuthFilter.java index 18f0ce917..8bd75bf94 100644 --- a/src/main/java/com/somemore/global/auth/jwt/filter/JwtAuthFilter.java +++ b/src/main/java/com/somemore/global/auth/jwt/filter/JwtAuthFilter.java @@ -76,7 +76,7 @@ private static EncodedToken findAccessTokenFromHeader(HttpServletRequest request return EncodedToken.createUninitialized(); } - return new EncodedToken(authorizationHeader); + return EncodedToken.from(authorizationHeader); } private EncodedToken findAccessTokenFromCookie(HttpServletRequest request) { diff --git a/src/main/java/com/somemore/global/auth/jwt/generator/HmacJwtGenerator.java b/src/main/java/com/somemore/global/auth/jwt/generator/HmacJwtGenerator.java index 6d00476c4..a1ecf53f1 100644 --- a/src/main/java/com/somemore/global/auth/jwt/generator/HmacJwtGenerator.java +++ b/src/main/java/com/somemore/global/auth/jwt/generator/HmacJwtGenerator.java @@ -26,13 +26,15 @@ public EncodedToken generateToken(String userId, String role, TokenType tokenTyp Instant expiration = now.plusMillis(tokenType.getPeriodInMillis()); String uniqueId = UUID.randomUUID().toString(); // JTI - return new EncodedToken(Jwts.builder() - .claims(claims) - .id(uniqueId) - .issuedAt(Date.from(now)) - .expiration(Date.from(expiration)) - .signWith(secretKey, ALGORITHM) - .compact()); + return EncodedToken.from( + Jwts.builder() + .claims(claims) + .id(uniqueId) + .issuedAt(Date.from(now)) + .expiration(Date.from(expiration)) + .signWith(secretKey, ALGORITHM) + .compact() + ); } private static Claims buildClaims(String userId, String role) { diff --git a/src/main/java/com/somemore/global/auth/jwt/refresh/manager/RedisRefreshTokenManager.java b/src/main/java/com/somemore/global/auth/jwt/manager/RedisTokenManager.java similarity index 64% rename from src/main/java/com/somemore/global/auth/jwt/refresh/manager/RedisRefreshTokenManager.java rename to src/main/java/com/somemore/global/auth/jwt/manager/RedisTokenManager.java index 1185a3fde..f0536ce6f 100644 --- a/src/main/java/com/somemore/global/auth/jwt/refresh/manager/RedisRefreshTokenManager.java +++ b/src/main/java/com/somemore/global/auth/jwt/manager/RedisTokenManager.java @@ -1,10 +1,10 @@ -package com.somemore.global.auth.jwt.refresh.manager; +package com.somemore.global.auth.jwt.manager; import com.somemore.global.auth.jwt.domain.EncodedToken; 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.repository.RefreshTokenRepository; +import com.somemore.global.auth.jwt.domain.RefreshToken; +import com.somemore.global.auth.jwt.repository.RefreshTokenRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -12,20 +12,22 @@ @Service @RequiredArgsConstructor -public class RedisRefreshTokenManager implements RefreshTokenManager { +public class RedisTokenManager implements TokenManager { private final RefreshTokenRepository refreshTokenRepository; @Override - public RefreshToken findRefreshTokenByAccessToken(EncodedToken accessToken) { + public RefreshToken getRefreshTokenByAccessToken(EncodedToken accessToken) { return refreshTokenRepository.findByAccessToken(accessToken.value()) .orElseThrow(() -> new JwtException(JwtErrorType.EXPIRED_TOKEN)); } @Override - public RefreshToken findRefreshTokenByUserId(UUID userId) { - return refreshTokenRepository.findByUserId(userId.toString()) + public EncodedToken getAccessTokenByUserId(UUID userId) { + RefreshToken refreshToken = refreshTokenRepository.findByUserId(userId.toString()) .orElseThrow(() -> new JwtException(JwtErrorType.EXPIRED_TOKEN)); + + return EncodedToken.from(refreshToken.getAccessToken()); } @Override diff --git a/src/main/java/com/somemore/global/auth/jwt/manager/TokenManager.java b/src/main/java/com/somemore/global/auth/jwt/manager/TokenManager.java new file mode 100644 index 000000000..edec9be15 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/jwt/manager/TokenManager.java @@ -0,0 +1,16 @@ +package com.somemore.global.auth.jwt.manager; + +import com.somemore.global.auth.jwt.domain.EncodedToken; +import com.somemore.global.auth.jwt.domain.RefreshToken; + +import java.util.UUID; + +public interface TokenManager { + RefreshToken getRefreshTokenByAccessToken(EncodedToken accessToken); + + EncodedToken getAccessTokenByUserId(UUID userId); + + void save(RefreshToken refreshToken); + + void removeRefreshToken(String userId); +} diff --git a/src/main/java/com/somemore/global/auth/jwt/refresh/manager/RefreshTokenManager.java b/src/main/java/com/somemore/global/auth/jwt/refresh/manager/RefreshTokenManager.java deleted file mode 100644 index d4598d14c..000000000 --- a/src/main/java/com/somemore/global/auth/jwt/refresh/manager/RefreshTokenManager.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.somemore.global.auth.jwt.refresh.manager; - -import com.somemore.global.auth.jwt.domain.EncodedToken; -import com.somemore.global.auth.jwt.refresh.domain.RefreshToken; - -import java.util.UUID; - -public interface RefreshTokenManager { - RefreshToken findRefreshTokenByAccessToken(EncodedToken accessToken); - - RefreshToken findRefreshTokenByUserId(UUID userId); - - void save(RefreshToken refreshToken); - - void removeRefreshToken(String userId); -} diff --git a/src/main/java/com/somemore/global/auth/jwt/refresh/refresher/DefaultJwtRefresher.java b/src/main/java/com/somemore/global/auth/jwt/refresher/DefaultJwtRefresher.java similarity index 68% rename from src/main/java/com/somemore/global/auth/jwt/refresh/refresher/DefaultJwtRefresher.java rename to src/main/java/com/somemore/global/auth/jwt/refresher/DefaultJwtRefresher.java index 86430634e..73cffbd3a 100644 --- a/src/main/java/com/somemore/global/auth/jwt/refresh/refresher/DefaultJwtRefresher.java +++ b/src/main/java/com/somemore/global/auth/jwt/refresher/DefaultJwtRefresher.java @@ -1,11 +1,11 @@ -package com.somemore.global.auth.jwt.refresh.refresher; +package com.somemore.global.auth.jwt.refresher; import com.somemore.global.auth.jwt.domain.EncodedToken; import com.somemore.global.auth.jwt.domain.TokenType; import com.somemore.global.auth.jwt.generator.JwtGenerator; import com.somemore.global.auth.jwt.parser.JwtParser; -import com.somemore.global.auth.jwt.refresh.domain.RefreshToken; -import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; +import com.somemore.global.auth.jwt.domain.RefreshToken; +import com.somemore.global.auth.jwt.manager.TokenManager; import com.somemore.global.auth.jwt.validator.JwtValidator; import io.jsonwebtoken.Claims; import lombok.RequiredArgsConstructor; @@ -17,22 +17,22 @@ @Slf4j public class DefaultJwtRefresher implements JwtRefresher { - private final RefreshTokenManager refreshTokenManager; + private final TokenManager tokenManager; private final JwtValidator jwtValidator; private final JwtParser jwtParser; private final JwtGenerator jwtGenerator; @Override public EncodedToken refreshAccessToken(EncodedToken accessToken) { - RefreshToken refreshToken = refreshTokenManager.findRefreshTokenByAccessToken(accessToken); - EncodedToken refreshTokenValue = new EncodedToken(refreshToken.getRefreshToken()); + RefreshToken refreshToken = tokenManager.getRefreshTokenByAccessToken(accessToken); + EncodedToken refreshTokenValue = EncodedToken.from(refreshToken.getRefreshToken()); jwtValidator.validateToken(refreshTokenValue); Claims claims = jwtParser.parseToken(refreshTokenValue); refreshToken.updateAccessToken(generateAccessToken(claims)); - refreshTokenManager.save(refreshToken); + tokenManager.save(refreshToken); - return new EncodedToken(refreshToken.getAccessToken()); + return EncodedToken.from(refreshToken.getAccessToken()); } private EncodedToken generateAccessToken(Claims claims) { diff --git a/src/main/java/com/somemore/global/auth/jwt/refresh/refresher/JwtRefresher.java b/src/main/java/com/somemore/global/auth/jwt/refresher/JwtRefresher.java similarity index 73% rename from src/main/java/com/somemore/global/auth/jwt/refresh/refresher/JwtRefresher.java rename to src/main/java/com/somemore/global/auth/jwt/refresher/JwtRefresher.java index 962deb2a9..cc3e4cec2 100644 --- a/src/main/java/com/somemore/global/auth/jwt/refresh/refresher/JwtRefresher.java +++ b/src/main/java/com/somemore/global/auth/jwt/refresher/JwtRefresher.java @@ -1,4 +1,4 @@ -package com.somemore.global.auth.jwt.refresh.refresher; +package com.somemore.global.auth.jwt.refresher; import com.somemore.global.auth.jwt.domain.EncodedToken; diff --git a/src/main/java/com/somemore/global/auth/jwt/refresh/repository/RefreshTokenRepository.java b/src/main/java/com/somemore/global/auth/jwt/repository/RefreshTokenRepository.java similarity index 74% rename from src/main/java/com/somemore/global/auth/jwt/refresh/repository/RefreshTokenRepository.java rename to src/main/java/com/somemore/global/auth/jwt/repository/RefreshTokenRepository.java index 289ac501b..562778aae 100644 --- a/src/main/java/com/somemore/global/auth/jwt/refresh/repository/RefreshTokenRepository.java +++ b/src/main/java/com/somemore/global/auth/jwt/repository/RefreshTokenRepository.java @@ -1,6 +1,6 @@ -package com.somemore.global.auth.jwt.refresh.repository; +package com.somemore.global.auth.jwt.repository; -import com.somemore.global.auth.jwt.refresh.domain.RefreshToken; +import com.somemore.global.auth.jwt.domain.RefreshToken; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; 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 fc62ddc4d..455689fd2 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 @@ -4,8 +4,8 @@ import com.somemore.global.auth.jwt.domain.EncodedToken; import com.somemore.global.auth.jwt.domain.TokenType; import com.somemore.global.auth.jwt.generator.JwtGenerator; -import com.somemore.global.auth.jwt.refresh.domain.RefreshToken; -import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; +import com.somemore.global.auth.jwt.domain.RefreshToken; +import com.somemore.global.auth.jwt.manager.TokenManager; import com.somemore.global.auth.jwt.usecase.GenerateTokensOnLoginUseCase; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -21,7 +21,7 @@ public class GenerateTokensOnLoginService implements GenerateTokensOnLoginUseCase { private final JwtGenerator jwtGenerator; - private final RefreshTokenManager refreshTokenManager; + private final TokenManager tokenManager; @Override public EncodedToken generateLoginToken(UUID userId, UserRole role) { @@ -54,6 +54,6 @@ private RefreshToken generateRefreshTokenWithAccessToken(UUID userId, UserRole r } private void saveRefreshToken(RefreshToken refreshToken) { - refreshTokenManager.save(refreshToken); + tokenManager.save(refreshToken); } } diff --git a/src/main/java/com/somemore/global/auth/jwt/service/JwtService.java b/src/main/java/com/somemore/global/auth/jwt/service/JwtService.java index 43600e8d3..302cd9d06 100644 --- a/src/main/java/com/somemore/global/auth/jwt/service/JwtService.java +++ b/src/main/java/com/somemore/global/auth/jwt/service/JwtService.java @@ -7,7 +7,7 @@ import com.somemore.global.auth.jwt.exception.JwtException; import com.somemore.global.auth.jwt.generator.JwtGenerator; import com.somemore.global.auth.jwt.parser.JwtParser; -import com.somemore.global.auth.jwt.refresh.refresher.JwtRefresher; +import com.somemore.global.auth.jwt.refresher.JwtRefresher; import com.somemore.global.auth.jwt.usecase.JwtUseCase; import com.somemore.global.auth.jwt.validator.JwtValidator; import io.jsonwebtoken.Claims; diff --git a/src/main/java/com/somemore/global/auth/sign/out/SignOutService.java b/src/main/java/com/somemore/global/auth/sign/out/SignOutService.java index 3e02134d2..1a12ec668 100644 --- a/src/main/java/com/somemore/global/auth/sign/out/SignOutService.java +++ b/src/main/java/com/somemore/global/auth/sign/out/SignOutService.java @@ -1,6 +1,6 @@ package com.somemore.global.auth.sign.out; -import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; +import com.somemore.global.auth.jwt.manager.TokenManager; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -15,13 +15,13 @@ @Transactional public class SignOutService implements SignOutUseCase { - private final RefreshTokenManager refreshTokenManager; + private final TokenManager tokenManager; @Override public void signOut( HttpServletResponse response, UUID userId) { - refreshTokenManager.removeRefreshToken(userId.toString()); + tokenManager.removeRefreshToken(userId.toString()); } } 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 568f3aa16..6d53f31a2 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 @@ -1,14 +1,14 @@ package com.somemore.global.auth.jwt.service; -import com.somemore.support.IntegrationTestSupport; import com.somemore.global.auth.jwt.domain.EncodedToken; +import com.somemore.global.auth.jwt.domain.RefreshToken; import com.somemore.global.auth.jwt.domain.TokenType; -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.manager.TokenManager; import com.somemore.global.auth.jwt.validator.JwtValidator; +import com.somemore.support.IntegrationTestSupport; +import com.somemore.user.domain.UserRole; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import org.junit.jupiter.api.AfterEach; @@ -23,7 +23,8 @@ import java.util.Date; import java.util.UUID; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; class JwtServiceTest extends IntegrationTestSupport { @@ -35,7 +36,7 @@ class JwtServiceTest extends IntegrationTestSupport { @Autowired private SecretKey secretKey; @Autowired - private RefreshTokenManager refreshTokenManager; + private TokenManager tokenManager; @Autowired private RedisTemplate redisTemplate; @@ -128,7 +129,7 @@ void throwExceptionWhenRefreshTokenIsInvalid() { EncodedToken expiredRefreshToken = createExpiredToken(userId, role); RefreshToken refreshToken = new RefreshToken(userId, expiredAccessToken, expiredRefreshToken); - refreshTokenManager.save(refreshToken); + tokenManager.save(refreshToken); // when // then @@ -193,7 +194,7 @@ void refreshTokenIsUpdated() { // when // then - assertThatThrownBy(() -> refreshTokenManager.findRefreshTokenByAccessToken(expiredAccessToken)) + assertThatThrownBy(() -> tokenManager.getRefreshTokenByAccessToken(expiredAccessToken)) .isInstanceOf(JwtException.class) .hasMessage(JwtErrorType.EXPIRED_TOKEN.getMessage()); @@ -207,7 +208,7 @@ void refreshTokenIsUpdated() { void invalidTokenThrowsJwtException() { // given String invalidToken = "invalid.token.value"; - EncodedToken encodedToken = new EncodedToken(invalidToken); + EncodedToken encodedToken = EncodedToken.from(invalidToken); // when // then @@ -252,7 +253,7 @@ private EncodedToken createExpiredToken(String userId, UserRole role) { Instant now = Instant.now(); Instant expiration = now.plusMillis(-1); // 과거 - return new EncodedToken(Jwts.builder() + return EncodedToken.from(Jwts.builder() .claims(claims) .issuedAt(Date.from(now)) .expiration(Date.from(expiration)) @@ -268,7 +269,7 @@ private RefreshToken createAndSaveRefreshToken(String userId, EncodedToken acces RefreshToken refreshToken = new RefreshToken( userId, accessToken, - new EncodedToken(Jwts.builder() + EncodedToken.from(Jwts.builder() .claims(claims) .id(uniqueId) .issuedAt(Date.from(now)) @@ -276,7 +277,7 @@ private RefreshToken createAndSaveRefreshToken(String userId, EncodedToken acces .signWith(secretKey, Jwts.SIG.HS256) .compact())); - refreshTokenManager.save(refreshToken); + tokenManager.save(refreshToken); return refreshToken; } diff --git a/src/test/java/com/somemore/global/auth/sign/SignOutVolunteerServiceTest.java b/src/test/java/com/somemore/global/auth/sign/SignOutVolunteerServiceTest.java index daa2fb081..625291c77 100644 --- a/src/test/java/com/somemore/global/auth/sign/SignOutVolunteerServiceTest.java +++ b/src/test/java/com/somemore/global/auth/sign/SignOutVolunteerServiceTest.java @@ -5,8 +5,8 @@ import com.somemore.global.auth.jwt.exception.JwtErrorType; import com.somemore.global.auth.jwt.exception.JwtException; import com.somemore.global.auth.jwt.generator.JwtGenerator; -import com.somemore.global.auth.jwt.refresh.domain.RefreshToken; -import com.somemore.global.auth.jwt.refresh.manager.RefreshTokenManager; +import com.somemore.global.auth.jwt.domain.RefreshToken; +import com.somemore.global.auth.jwt.manager.TokenManager; import com.somemore.global.auth.sign.out.SignOutService; import com.somemore.support.IntegrationTestSupport; import com.somemore.user.domain.UserRole; @@ -28,7 +28,7 @@ class SignOutServiceTest extends IntegrationTestSupport { @Autowired private SignOutService signOutVolunteerService; @Autowired - private RefreshTokenManager refreshTokenManager; + private TokenManager tokenManager; @Autowired private JwtGenerator jwtGenerator; @Autowired @@ -63,13 +63,13 @@ void signOutDeletesTokens() { accessToken, jwtGenerator.generateToken(userId.toString(), role.getAuthority(), TokenType.REFRESH)); - refreshTokenManager.save(refreshToken); + tokenManager.save(refreshToken); // When signOutVolunteerService.signOut(response, userId); // Then - assertThatThrownBy(() -> refreshTokenManager.getRefreshTokenByAccessToken(accessToken)) + assertThatThrownBy(() -> tokenManager.getRefreshTokenByAccessToken(accessToken)) .isInstanceOf(JwtException.class) .hasMessage(JwtErrorType.EXPIRED_TOKEN.getMessage()); } From 846edfb148f91a7cecf3582c31f3e05f6f7b6754 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, 13 Jan 2025 21:26:03 +0900 Subject: [PATCH 11/34] =?UTF-8?q?feat(token):=20=EB=A7=8C=EB=A3=8C?= =?UTF-8?q?=EB=90=9C=20=EC=95=A1=EC=84=B8=EC=8A=A4=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존 쿠키 방식에서 수정됨으로 해당 로직의 변경이 필요함, 협의 필요. --- .../java/com/somemore/global/auth/jwt/service/JwtService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/somemore/global/auth/jwt/service/JwtService.java b/src/main/java/com/somemore/global/auth/jwt/service/JwtService.java index 302cd9d06..d4ddb48f1 100644 --- a/src/main/java/com/somemore/global/auth/jwt/service/JwtService.java +++ b/src/main/java/com/somemore/global/auth/jwt/service/JwtService.java @@ -24,7 +24,6 @@ public class JwtService implements JwtUseCase { private final JwtParser jwtParser; private final JwtValidator jwtValidator; private final JwtRefresher jwtRefresher; - private final CookieUseCase cookieUseCase; @Override public EncodedToken generateToken(String userId, String role, TokenType tokenType) { @@ -48,7 +47,7 @@ public Claims getClaims(EncodedToken token) { private void handleJwtExpiredException(JwtException e, EncodedToken accessToken, HttpServletResponse response) { if (e.getErrorType() == JwtErrorType.EXPIRED_TOKEN) { EncodedToken refreshedToken = jwtRefresher.refreshAccessToken(accessToken); - cookieUseCase.setToken(response, refreshedToken.value(), TokenType.ACCESS); + // TODO 프론트엔드와 협의 : 만료된 액세스 토큰 관리 방법 return; } throw e; From d41de3eaa8a3b68d613630696711831533c3b7e4 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, 13 Jan 2025 21:59:26 +0900 Subject: [PATCH 12/34] =?UTF-8?q?feat(user):=20password=20=EB=A5=BC=20acco?= =?UTF-8?q?untPassword=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 명명 일관성 유지 --- .../idpw/provider/CustomAuthenticationProvider.java | 2 +- src/main/java/com/somemore/user/domain/User.java | 10 +++++----- src/main/java/com/somemore/user/dto/UserAuthInfo.java | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) 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 9720a703e..d81f9031b 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 @@ -32,7 +32,7 @@ public Authentication authenticate(Authentication authentication) throws Authent User user = userQueryUseCase.getByAccountId(accountId); - validatePassword(rawAccountPassword, user.getPassword()); + validatePassword(rawAccountPassword, user.getAccountPassword()); EncodedToken accessToken = generateAccessToken(user); diff --git a/src/main/java/com/somemore/user/domain/User.java b/src/main/java/com/somemore/user/domain/User.java index 2746f5702..04a4ed6d1 100644 --- a/src/main/java/com/somemore/user/domain/User.java +++ b/src/main/java/com/somemore/user/domain/User.java @@ -31,8 +31,8 @@ public class User extends BaseEntity { @Column(name = "account_id", nullable = false) private String accountId; - @Column(name = "password", nullable = false) - private String password; + @Column(name = "account_password", nullable = false) + private String accountPassword; @Enumerated(EnumType.STRING) @Column(name = "role", nullable = false) @@ -42,15 +42,15 @@ public class User extends BaseEntity { public static User from(UserAuthInfo userAuthInfo, UserRole role) { return User.builder() .accountId(userAuthInfo.accountId()) - .password(userAuthInfo.password()) + .accountPassword(userAuthInfo.accountPassword()) .role(role) .build(); } @Builder - private User(String accountId, String password, UserRole role) { + private User(String accountId, String accountPassword, UserRole role) { this.accountId = accountId; - this.password = password; + this.accountPassword = accountPassword; this.role = role; } } diff --git a/src/main/java/com/somemore/user/dto/UserAuthInfo.java b/src/main/java/com/somemore/user/dto/UserAuthInfo.java index b210496f0..2d2d9a28a 100644 --- a/src/main/java/com/somemore/user/dto/UserAuthInfo.java +++ b/src/main/java/com/somemore/user/dto/UserAuthInfo.java @@ -5,11 +5,11 @@ import java.util.UUID; public record UserAuthInfo(String accountId, - String password) { + String accountPassword) { public static UserAuthInfo createForOAuth(OAuthProvider provider) { String accountId = provider.getProviderName() + UUID.randomUUID(); - String password = String.valueOf(UUID.randomUUID()); - return new UserAuthInfo(accountId, password); + String accountPassword = String.valueOf(UUID.randomUUID()); + return new UserAuthInfo(accountId, accountPassword); } } From 2043cd09d36e454c1024b67d25fefc85e4079d63 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, 14 Jan 2025 20:03:19 +0900 Subject: [PATCH 13/34] =?UTF-8?q?refactor:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9D=BC=EA=B4=80=EC=84=B1=EC=9D=84=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?=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 --- .../global/auth/sign/in/SignInController.java | 4 ++-- src/main/java/com/somemore/user/domain/User.java | 2 +- .../java/com/somemore/user/dto/UserAuthInfo.java | 4 ++++ .../somemore/user/service/RegisterUserService.java | 2 +- .../repository/user/UserRepositoryImplTest.java | 14 +++++++------- .../user/service/UserQueryServiceTest.java | 2 +- .../user/service/ValidateBasicInfoServiceTest.java | 2 +- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/somemore/global/auth/sign/in/SignInController.java b/src/main/java/com/somemore/global/auth/sign/in/SignInController.java index 7b603fb43..822b4665e 100644 --- a/src/main/java/com/somemore/global/auth/sign/in/SignInController.java +++ b/src/main/java/com/somemore/global/auth/sign/in/SignInController.java @@ -8,8 +8,8 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -31,7 +31,7 @@ public class SignInController { */ @PostMapping("/api/sign-in/id-pw") public ApiResponse signIn( - @RequestParam SignInRequestDto signInRequestDto) { + @RequestBody SignInRequestDto signInRequestDto) { return ApiResponse.ok("로그인되었습니다."); } diff --git a/src/main/java/com/somemore/user/domain/User.java b/src/main/java/com/somemore/user/domain/User.java index 04a4ed6d1..acebfaa13 100644 --- a/src/main/java/com/somemore/user/domain/User.java +++ b/src/main/java/com/somemore/user/domain/User.java @@ -39,7 +39,7 @@ public class User extends BaseEntity { private UserRole role; - public static User from(UserAuthInfo userAuthInfo, UserRole role) { + public static User of(UserAuthInfo userAuthInfo, UserRole role) { return User.builder() .accountId(userAuthInfo.accountId()) .accountPassword(userAuthInfo.accountPassword()) diff --git a/src/main/java/com/somemore/user/dto/UserAuthInfo.java b/src/main/java/com/somemore/user/dto/UserAuthInfo.java index 2d2d9a28a..674dc26a6 100644 --- a/src/main/java/com/somemore/user/dto/UserAuthInfo.java +++ b/src/main/java/com/somemore/user/dto/UserAuthInfo.java @@ -7,6 +7,10 @@ public record UserAuthInfo(String accountId, String accountPassword) { + public static UserAuthInfo of(String accountId, String accountPassword) { + return new UserAuthInfo(accountId, accountPassword); + } + public static UserAuthInfo createForOAuth(OAuthProvider provider) { String accountId = provider.getProviderName() + UUID.randomUUID(); String accountPassword = String.valueOf(UUID.randomUUID()); diff --git a/src/main/java/com/somemore/user/service/RegisterUserService.java b/src/main/java/com/somemore/user/service/RegisterUserService.java index 18b988194..acbb13b35 100644 --- a/src/main/java/com/somemore/user/service/RegisterUserService.java +++ b/src/main/java/com/somemore/user/service/RegisterUserService.java @@ -39,7 +39,7 @@ public User registerLocalUser(UserAuthInfo userAuthInfo, UserRole role) { } private User createAndRegisterUser(UserRole role, UserAuthInfo userAuthInfo) { - User user = User.from(userAuthInfo, role); + User user = User.of(userAuthInfo, role); userRepository.save(user); UUID userId = user.getId(); diff --git a/src/test/java/com/somemore/user/repository/user/UserRepositoryImplTest.java b/src/test/java/com/somemore/user/repository/user/UserRepositoryImplTest.java index 40d44270b..2cc00310d 100644 --- a/src/test/java/com/somemore/user/repository/user/UserRepositoryImplTest.java +++ b/src/test/java/com/somemore/user/repository/user/UserRepositoryImplTest.java @@ -26,7 +26,7 @@ class UserRepositoryImplTest extends IntegrationTestSupport { void saveOAuthVolunteerUser() { // given UserAuthInfo userAuthInfo = UserAuthInfo.createForOAuth(OAuthProvider.NAVER); - User user = User.from(userAuthInfo, UserRole.VOLUNTEER); + User user = User.of(userAuthInfo, UserRole.VOLUNTEER); // when User savedUser = userRepository.save(user); @@ -42,7 +42,7 @@ void saveOAuthVolunteerUser() { void saveOAuthCenterUser() { // given UserAuthInfo userAuthInfo = UserAuthInfo.createForOAuth(OAuthProvider.NAVER); - User user = User.from(userAuthInfo, UserRole.CENTER); + User user = User.of(userAuthInfo, UserRole.CENTER); // when User savedUser = userRepository.save(user); @@ -58,7 +58,7 @@ void saveOAuthCenterUser() { void saveLocalCenterUser() { // given UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.test", "test"); - User user = User.from(userAuthInfo, UserRole.CENTER); + User user = User.of(userAuthInfo, UserRole.CENTER); // when User savedUser = userRepository.save(user); @@ -74,7 +74,7 @@ void saveLocalCenterUser() { void findById() { // given UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.test", "test"); - User user = User.from(userAuthInfo, UserRole.CENTER); + User user = User.of(userAuthInfo, UserRole.CENTER); User savedUser = userRepository.save(user); // when @@ -90,7 +90,7 @@ void findById() { void findByInvalidId() { // given UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.test", "test"); - User user = User.from(userAuthInfo, UserRole.CENTER); + User user = User.of(userAuthInfo, UserRole.CENTER); userRepository.save(user); UUID invalidUserId = UUID.randomUUID(); @@ -106,7 +106,7 @@ void findByInvalidId() { void findRoleById() { // given UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.test", "test"); - User user = User.from(userAuthInfo, UserRole.CENTER); + User user = User.of(userAuthInfo, UserRole.CENTER); User savedUser = userRepository.save(user); // when @@ -122,7 +122,7 @@ void findRoleById() { void findByAccountId() { // given UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.test", "test"); - User user = User.from(userAuthInfo, UserRole.CENTER); + User user = User.of(userAuthInfo, UserRole.CENTER); User savedUser = userRepository.save(user); // when diff --git a/src/test/java/com/somemore/user/service/UserQueryServiceTest.java b/src/test/java/com/somemore/user/service/UserQueryServiceTest.java index 87c39279d..3dd165367 100644 --- a/src/test/java/com/somemore/user/service/UserQueryServiceTest.java +++ b/src/test/java/com/somemore/user/service/UserQueryServiceTest.java @@ -35,7 +35,7 @@ class UserQueryServiceTest extends IntegrationTestSupport { void setup() { UserAuthInfo userAuthInfo = UserAuthInfo.createForOAuth(OAuthProvider.NAVER); - user = userRepository.save(User.from(userAuthInfo, UserRole.VOLUNTEER)); + user = userRepository.save(User.of(userAuthInfo, UserRole.VOLUNTEER)); userCommonAttribute = userCommonAttributeRepository.save(UserCommonAttribute.createDefault(user.getId())); } diff --git a/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java b/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java index a4e76036b..db1de3761 100644 --- a/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java +++ b/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java @@ -32,7 +32,7 @@ class ValidateBasicInfoServiceTest extends IntegrationTestSupport { @BeforeEach void setup() { UserAuthInfo userAuthInfo = new UserAuthInfo("test@test.com", "Test User"); - user = userRepository.save(User.from(userAuthInfo, UserRole.VOLUNTEER)); + user = userRepository.save(User.of(userAuthInfo, UserRole.VOLUNTEER)); } @DisplayName("필수 입력 정보가 입력되었다면, true를 반환한다.") From 8b6090170aefa551249a2449ddee326c390c3e1c 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, 14 Jan 2025 20:04:22 +0900 Subject: [PATCH 14/34] =?UTF-8?q?feat(volunteer):=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=EB=93=A4=20old=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 당장 삭제하면 문제 발생할 것 같아서 우선 구현 후 삭제 예정. --- .../java/com/somemore/domains/volunteer/domain/Volunteer.java | 2 +- .../com/somemore/domains/volunteer/domain/VolunteerDetail.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 49b004787..d15ce300b 100644 --- a/src/main/java/com/somemore/domains/volunteer/domain/Volunteer.java +++ b/src/main/java/com/somemore/domains/volunteer/domain/Volunteer.java @@ -11,7 +11,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "volunteer") +@Table(name = "volunteer_old") // TODO 삭제될 엔티티(테이블) public class Volunteer extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.UUID) diff --git a/src/main/java/com/somemore/domains/volunteer/domain/VolunteerDetail.java b/src/main/java/com/somemore/domains/volunteer/domain/VolunteerDetail.java index d85dae750..59b3404d2 100644 --- a/src/main/java/com/somemore/domains/volunteer/domain/VolunteerDetail.java +++ b/src/main/java/com/somemore/domains/volunteer/domain/VolunteerDetail.java @@ -13,7 +13,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "volunteer_detail") +@Table(name = "volunteer_detail_old") // TODO 삭제될 엔티티(테이블) public class VolunteerDetail extends BaseEntity { @Id From 9229f086859fc2b6a278af54b610fdc540618d84 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, 14 Jan 2025 20:19:50 +0900 Subject: [PATCH 15/34] =?UTF-8?q?feat(center):=20=EC=84=BC=ED=84=B0?= =?UTF-8?q?=EC=9D=98=20id,=20pw=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 유저로 책임이 넘어갔음. --- .../somemore/domains/center/domain/Center.java | 16 ++-------------- .../domains/center/domain/CenterTest.java | 8 +------- .../center/repository/CenterRepositoryTest.java | 6 +----- 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/somemore/domains/center/domain/Center.java b/src/main/java/com/somemore/domains/center/domain/Center.java index 5fbc62910..c4ca6a219 100644 --- a/src/main/java/com/somemore/domains/center/domain/Center.java +++ b/src/main/java/com/somemore/domains/center/domain/Center.java @@ -33,34 +33,22 @@ public class Center extends BaseEntity { @Column(name = "homepage_link", nullable = false) private String homepageLink; - @Column(name = "account_id", nullable = false) - private String accountId; - - @Column(name = "account_pw", nullable = false) - private String accountPw; - - @Builder - private Center(String name, String contactNumber, String imgUrl, String introduce, String homepageLink, String accountId, String accountPw) { - + private Center(String name, String contactNumber, String imgUrl, String introduce, String homepageLink) { this.name = name; this.contactNumber = contactNumber; this.imgUrl = imgUrl; this.introduce = introduce; this.homepageLink = homepageLink; - this.accountId = accountId; - this.accountPw = accountPw; } - public static Center create(String name, String contactNumber, String imgUrl, String introduce, String homepageLink, String accountId, String accountPw) { + public static Center create(String name, String contactNumber, String imgUrl, String introduce, String homepageLink) { return Center.builder() .name(name) .contactNumber(contactNumber) .imgUrl(imgUrl) .introduce(introduce) .homepageLink(homepageLink) - .accountId(accountId) - .accountPw(accountPw) .build(); } diff --git a/src/test/java/com/somemore/domains/center/domain/CenterTest.java b/src/test/java/com/somemore/domains/center/domain/CenterTest.java index b7b9bf808..37d552488 100644 --- a/src/test/java/com/somemore/domains/center/domain/CenterTest.java +++ b/src/test/java/com/somemore/domains/center/domain/CenterTest.java @@ -13,8 +13,6 @@ class CenterTest { private static final String IMG_URL = "http://example.com/image.jpg"; private static final String INTRODUCE = "우리는 서울 도서관입니다."; private static final String HOMEPAGE_LINK = "http://testcenter.com"; - private static final String ACCOUNT_ID = "testId"; - private static final String ACCOUNT_PW = "testPw"; @DisplayName("Center 엔티티를 생성할 수 있다.") @Test @@ -25,9 +23,7 @@ void create() { CONTACT_NUMBER, IMG_URL, INTRODUCE, - HOMEPAGE_LINK, - ACCOUNT_ID, - ACCOUNT_PW + HOMEPAGE_LINK ); //then @@ -37,8 +33,6 @@ void create() { () -> assertThat(center.getImgUrl()).isEqualTo(IMG_URL), () -> assertThat(center.getIntroduce()).isEqualTo(INTRODUCE), () -> assertThat(center.getHomepageLink()).isEqualTo(HOMEPAGE_LINK), - () -> assertThat(center.getAccountId()).isEqualTo(ACCOUNT_ID), - () -> assertThat(center.getAccountPw()).isEqualTo(ACCOUNT_PW) ); } diff --git a/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java b/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java index 557f8520c..df6d24a3d 100644 --- a/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java +++ b/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java @@ -36,8 +36,6 @@ void findById() { assertThat(foundCenter.get().getImgUrl()).isEqualTo("http://example.com/image.jpg"); assertThat(foundCenter.get().getIntroduce()).isEqualTo("기관 소개 내용"); assertThat(foundCenter.get().getHomepageLink()).isEqualTo("http://example.com"); - assertThat(foundCenter.get().getAccountId()).isEqualTo("account123"); - assertThat(foundCenter.get().getAccountPw()).isEqualTo("password123"); } @DisplayName("기관 id로 기관이 존재하는지 확인할 수 있다.") @@ -129,9 +127,7 @@ private static Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); } } From eab21665a04c54075b11f0887e4098f0a0f28059 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, 14 Jan 2025 20:26:18 +0900 Subject: [PATCH 16/34] =?UTF-8?q?feat(user):=20=EC=9C=A0=EC=A0=80=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=BB=97=EC=96=B4=EB=82=98=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EC=83=88=EB=A1=9C=EC=9A=B4=20=EB=B4=89=EC=82=AC=EC=9E=90,=20?= =?UTF-8?q?=EA=B8=B0=EA=B4=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - new suffix 는 삭제 예정 - 봉사자와 기관에 겹치는 속성인 연락처는 공통 속성에 추가. --- .../domains/center/domain/Center_NEW.java | 52 ++++++++++++++ .../volunteer/domain/Volunteer_NEW.java | 67 +++++++++++++++++++ .../user/domain/UserCommonAttribute.java | 7 +- 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/somemore/domains/center/domain/Center_NEW.java create mode 100644 src/main/java/com/somemore/domains/volunteer/domain/Volunteer_NEW.java diff --git a/src/main/java/com/somemore/domains/center/domain/Center_NEW.java b/src/main/java/com/somemore/domains/center/domain/Center_NEW.java new file mode 100644 index 000000000..786beb668 --- /dev/null +++ b/src/main/java/com/somemore/domains/center/domain/Center_NEW.java @@ -0,0 +1,52 @@ +package com.somemore.domains.center.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 = "center_new") // TODO suffix 삭제 +public class Center_NEW { + + @Id + @GeneratedValue(strategy = GenerationType.UUID) + @Column(name = "id", nullable = false, columnDefinition = "BINARY(16)") + private UUID id; + + @Column(name = "user_id", nullable = false, columnDefinition = "BINARY(16)") + private UUID userId; + + @Column(name = "name", nullable = false) + private String name; + + @Column(name = "homepage_url", nullable = false) + private String homepageUrl; + + @Builder + private Center_NEW(UUID userId, String name, String homepageUrl) { + this.userId = userId; + this.name = name; + this.homepageUrl = homepageUrl; + } + + public static Center_NEW create(UUID userId, + String name, + String homepageUrl) { + return Center_NEW.builder() + .userId(userId) + .name(name) + .homepageUrl(homepageUrl) + .build(); + } +} diff --git a/src/main/java/com/somemore/domains/volunteer/domain/Volunteer_NEW.java b/src/main/java/com/somemore/domains/volunteer/domain/Volunteer_NEW.java new file mode 100644 index 000000000..80a791d2d --- /dev/null +++ b/src/main/java/com/somemore/domains/volunteer/domain/Volunteer_NEW.java @@ -0,0 +1,67 @@ +package com.somemore.domains.volunteer.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 = "volunteer_new") // TODO suffix 삭제 +public class Volunteer_NEW { + + @Id + @GeneratedValue(strategy = GenerationType.UUID) + @Column(name = "id", nullable = false, columnDefinition = "BINARY(16)") + private UUID id; + + @Column(name = "user_id", nullable = false, columnDefinition = "BINARY(16)") + private UUID userId; + + @Column(name = "name", nullable = false) + private String name; + + @Enumerated(EnumType.STRING) + @Column(name = "gender", nullable = false, length = 10) + private Gender gender; + + @Enumerated(EnumType.STRING) + @Column(name = "tier", nullable = false, length = 20) + private Tier tier; + + @Builder + private Volunteer_NEW( + UUID userId, + String name, + Gender gender, + Tier tier + ) { + this.userId = userId; + this.name = name; + this.gender = gender; + this.tier = tier; + } + + public static Volunteer_NEW create(UUID userId, + String name, + Gender gender, + Tier tier) { + return Volunteer_NEW.builder() + .userId(userId) + .name(name) + .gender(gender) + .tier(tier) + .build(); + } +} diff --git a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java index b23e49a44..e5c596b70 100644 --- a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java +++ b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java @@ -33,6 +33,9 @@ public class UserCommonAttribute extends BaseEntity { @Column(name = "nickname", nullable = false) private String nickname; + @Column(name = "contact_number", nullable = false) + private String contactNumber; + @Column(name = "img_url", nullable = false) private String imgUrl; @@ -51,6 +54,7 @@ public static UserCommonAttribute createDefault(UUID userId) { return UserCommonAttribute.builder() .userId(userId) .nickname(String.valueOf(UUID.randomUUID()).substring(0, 8)) + .contactNumber("") .imgUrl(ImageUploadService.DEFAULT_IMAGE_URL) .introduce("") .isCustomized(false) @@ -58,9 +62,10 @@ public static UserCommonAttribute createDefault(UUID userId) { } @Builder - private UserCommonAttribute(UUID userId, String nickname, String imgUrl, String introduce, boolean isCustomized) { + private UserCommonAttribute(UUID userId, String nickname, String contactNumber, String imgUrl, String introduce, boolean isCustomized) { this.userId = userId; this.nickname = nickname; + this.contactNumber = contactNumber; this.imgUrl = imgUrl; this.introduce = introduce; this.isCustomized = isCustomized; From 5a8f3caf308d511928c81cd802ab5c4115af96bd 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, 14 Jan 2025 21:51:28 +0900 Subject: [PATCH 17/34] =?UTF-8?q?feat(center):=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20sign=20=EB=A1=9C=EC=A7=81=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/center/CenterRepository.java | 3 - .../center/CenterRepositoryImpl.java | 22 -------- .../service/query/CenterSignService.java | 40 ------------- .../usecase/query/CenterSignUseCase.java | 9 --- .../repository/CenterRepositoryTest.java | 56 ------------------- .../repository/NoteRepositoryImplTest.java | 4 +- .../note/service/NoteQueryServiceTest.java | 4 +- 7 files changed, 2 insertions(+), 136 deletions(-) delete mode 100644 src/main/java/com/somemore/domains/center/service/query/CenterSignService.java delete mode 100644 src/main/java/com/somemore/domains/center/usecase/query/CenterSignUseCase.java diff --git a/src/main/java/com/somemore/domains/center/repository/center/CenterRepository.java b/src/main/java/com/somemore/domains/center/repository/center/CenterRepository.java index 1d6af166a..9cffc8d5a 100644 --- a/src/main/java/com/somemore/domains/center/repository/center/CenterRepository.java +++ b/src/main/java/com/somemore/domains/center/repository/center/CenterRepository.java @@ -17,8 +17,5 @@ default boolean doesNotExistById(UUID id) { } Optional

findCenterById(UUID id); List findCenterOverviewsByIds(List ids); - UUID findIdByAccountId(String accountId); - String findPasswordByAccountId(String accountId); void deleteAllInBatch(); - } diff --git a/src/main/java/com/somemore/domains/center/repository/center/CenterRepositoryImpl.java b/src/main/java/com/somemore/domains/center/repository/center/CenterRepositoryImpl.java index c8d03b148..f398c15e9 100644 --- a/src/main/java/com/somemore/domains/center/repository/center/CenterRepositoryImpl.java +++ b/src/main/java/com/somemore/domains/center/repository/center/CenterRepositoryImpl.java @@ -61,28 +61,6 @@ public List findCenterOverviewsByIds(List ids) { .fetch(); } - @Override - public UUID findIdByAccountId(String accountId) { - - return queryFactory - .select(center.id) - .from(center) - .where(center.accountId.eq(accountId) - .and(isNotDeleted())) - .fetchOne(); - } - - @Override - public String findPasswordByAccountId(String accountId) { - - return queryFactory - .select(center.accountPw) - .from(center) - .where(center.accountId.eq(accountId) - .and(isNotDeleted())) - .fetchOne(); - } - @Override public void deleteAllInBatch() { centerJpaRepository.deleteAllInBatch(); diff --git a/src/main/java/com/somemore/domains/center/service/query/CenterSignService.java b/src/main/java/com/somemore/domains/center/service/query/CenterSignService.java deleted file mode 100644 index 3221e09c6..000000000 --- a/src/main/java/com/somemore/domains/center/service/query/CenterSignService.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.somemore.domains.center.service.query; - -import com.somemore.domains.center.repository.center.CenterRepository; -import com.somemore.domains.center.usecase.query.CenterSignUseCase; -import com.somemore.global.exception.BadRequestException; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.UUID; - -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_CENTER; - -@Service -@Transactional -@RequiredArgsConstructor -public class CenterSignService implements CenterSignUseCase { - - private final CenterRepository centerRepository; - - @Override - public UUID getIdByAccountId(String accountId) { - UUID centerId = centerRepository.findIdByAccountId(accountId); - if (centerId == null) { - throw new BadRequestException(NOT_EXISTS_CENTER); - } - - return centerId; - } - - @Override - public String getPasswordByAccountId(String accountId) { - String password = centerRepository.findPasswordByAccountId(accountId); - if (password == null) { - throw new BadRequestException(NOT_EXISTS_CENTER); - } - - return password; - } -} diff --git a/src/main/java/com/somemore/domains/center/usecase/query/CenterSignUseCase.java b/src/main/java/com/somemore/domains/center/usecase/query/CenterSignUseCase.java deleted file mode 100644 index d572cabe5..000000000 --- a/src/main/java/com/somemore/domains/center/usecase/query/CenterSignUseCase.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.somemore.domains.center.usecase.query; - -import java.util.UUID; - -public interface CenterSignUseCase { - - UUID getIdByAccountId(String accountId); - String getPasswordByAccountId(String accountId); -} diff --git a/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java b/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java index df6d24a3d..5bc879a2b 100644 --- a/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java +++ b/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java @@ -65,62 +65,6 @@ void notExistsById() { assertThat(isExist).isFalse(); } - @DisplayName("기관 계정 ID로 기관 ID를 조회할 수 있다.") - @Test - void findIdByAccountId() { - //given - Center center = createCenter(); - centerRepository.save(center); - - //when - UUID foundId = centerRepository.findIdByAccountId("account123"); - - //then - assertThat(foundId).isNotNull(); - assertThat(foundId).isEqualTo(center.getId()); - } - - @DisplayName("기관 계정 ID로 비밀번호를 조회할 수 있다.") - @Test - void findPasswordByAccountId() { - //given - Center center = createCenter(); - centerRepository.save(center); - - //when - String foundPassword = centerRepository.findPasswordByAccountId("account123"); - - //then - assertThat(foundPassword).isNotNull(); - assertThat(foundPassword).isEqualTo("password123"); - } - - @DisplayName("존재하지 않는 계정 ID로 기관 ID 조회 시 null을 반환한다.") - @Test - void findIdByNonExistentAccountId() { - //given - String nonExistentAccountId = "nonExistentAccount123"; - - //when - UUID foundId = centerRepository.findIdByAccountId(nonExistentAccountId); - - //then - assertThat(foundId).isNull(); - } - - @DisplayName("존재하지 않는 계정 ID로 비밀번호 조회 시 null을 반환한다.") - @Test - void findPasswordByNonExistentAccountId() { - //given - String nonExistentAccountId = "nonExistentAccount123"; - - //when - String foundPassword = centerRepository.findPasswordByAccountId(nonExistentAccountId); - - //then - assertThat(foundPassword).isNull(); - } - private static Center createCenter() { return Center.create( "기본 기관 이름", 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 64bd9cb50..6a1085d2c 100644 --- a/src/test/java/com/somemore/domains/note/repository/NoteRepositoryImplTest.java +++ b/src/test/java/com/somemore/domains/note/repository/NoteRepositoryImplTest.java @@ -143,9 +143,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); centerJpaRepository.save(center); 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 e1cbb26a6..059d42bea 100644 --- a/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java @@ -181,9 +181,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); centerJpaRepository.save(center); From 5391a02102dad6cfafd795515d7ad45f9933c5c7 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, 14 Jan 2025 22:47:56 +0900 Subject: [PATCH 18/34] =?UTF-8?q?rollback:=20=EC=82=AD=EC=A0=9C=EA=B0=80?= =?UTF-8?q?=20=EB=84=88=EB=AC=B4=20=ED=9E=98=EB=93=A4=EB=8B=A4...=20?= =?UTF-8?q?=EB=AF=B8=EB=A4=84=EC=95=BC=ED=95=A0=20=EA=B2=83=20=EA=B0=99?= =?UTF-8?q?=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../volunteer/domain/Volunteer_NEW.java | 3 +- .../service/RegisterVolunteerService.java | 4 +- .../service/UpdateVolunteerLockService.java | 2 +- .../UpdateVolunteerProfileService.java | 2 +- .../usecase/RegisterVolunteerUseCase.java | 2 +- .../VolunteerApplyQueryFacadeService.java | 1 - .../domains/center/domain/CenterTest.java | 2 +- .../command/CreatePreferItemServiceTest.java | 4 +- .../command/DeletePreferItemServiceTest.java | 4 +- .../service/query/CenterQueryServiceTest.java | 8 +- .../service/query/CenterSignServiceTest.java | 106 ------------------ .../CommunityBoardRepositoryTest.java | 2 +- .../CommunityCommentRepositoryTest.java | 2 +- .../board/CommunityBoardQueryServiceTest.java | 2 +- .../CommunityCommentQueryServiceTest.java | 2 +- .../CancelInterestCenterServiceTest.java | 4 +- .../InterestCenterQueryServiceTest.java | 7 +- .../RegisterInterestCenterServiceTest.java | 4 +- .../repository/NoteRepositoryImplTest.java | 2 +- .../note/service/NoteQueryServiceTest.java | 2 +- .../service/SendNoteToCenterServiceTest.java | 4 +- .../SendNoteToVolunteerServiceTest.java | 2 +- .../repository/ReviewRepositoryImplTest.java | 2 +- .../service/ReviewQueryServiceTest.java | 2 +- .../service/RegisterVolunteerServiceTest.java | 74 ------------ .../UpdateVolunteerLockServiceTest.java | 2 +- .../UpdateVolunteerProfileServiceTest.java | 2 +- ...SettleVolunteerApplyFacadeServiceTest.java | 2 +- .../auth/jwt/service/JwtServiceTest.java | 22 ---- .../support/fixture/CenterFixture.java | 4 - 30 files changed, 28 insertions(+), 253 deletions(-) delete mode 100644 src/test/java/com/somemore/domains/center/service/query/CenterSignServiceTest.java delete mode 100644 src/test/java/com/somemore/domains/volunteer/service/RegisterVolunteerServiceTest.java diff --git a/src/main/java/com/somemore/domains/volunteer/domain/Volunteer_NEW.java b/src/main/java/com/somemore/domains/volunteer/domain/Volunteer_NEW.java index 80a791d2d..57d7d99c1 100644 --- a/src/main/java/com/somemore/domains/volunteer/domain/Volunteer_NEW.java +++ b/src/main/java/com/somemore/domains/volunteer/domain/Volunteer_NEW.java @@ -1,5 +1,6 @@ package com.somemore.domains.volunteer.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 = "volunteer_new") // TODO suffix 삭제 -public class Volunteer_NEW { +public class Volunteer_NEW extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.UUID) diff --git a/src/main/java/com/somemore/domains/volunteer/service/RegisterVolunteerService.java b/src/main/java/com/somemore/domains/volunteer/service/RegisterVolunteerService.java index fe0948a53..406b91606 100644 --- a/src/main/java/com/somemore/domains/volunteer/service/RegisterVolunteerService.java +++ b/src/main/java/com/somemore/domains/volunteer/service/RegisterVolunteerService.java @@ -2,10 +2,10 @@ import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.domain.VolunteerDetail; -import com.somemore.domains.volunteer.usecase.RegisterVolunteerUseCase; 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.domains.volunteer.repository.old.VolunteerRepository; +import com.somemore.domains.volunteer.usecase.RegisterVolunteerUseCase; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockService.java b/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockService.java index 33d130b4e..039cee980 100644 --- a/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockService.java +++ b/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockService.java @@ -5,7 +5,7 @@ import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.usecase.UpdateVolunteerUseCase; import com.somemore.global.exception.BadRequestException; -import com.somemore.domains.volunteer.repository.VolunteerRepository; +import com.somemore.domains.volunteer.repository.old.VolunteerRepository; import java.util.UUID; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileService.java b/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileService.java index c9ca42897..7a56fe428 100644 --- a/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileService.java +++ b/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileService.java @@ -3,7 +3,7 @@ import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.global.exception.BadRequestException; import com.somemore.domains.volunteer.dto.request.VolunteerProfileUpdateRequestDto; -import com.somemore.domains.volunteer.repository.VolunteerRepository; +import com.somemore.domains.volunteer.repository.old.VolunteerRepository; import com.somemore.domains.volunteer.usecase.UpdateVolunteerProfileUseCase; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/somemore/domains/volunteer/usecase/RegisterVolunteerUseCase.java b/src/main/java/com/somemore/domains/volunteer/usecase/RegisterVolunteerUseCase.java index 75d0028eb..3cf9236e1 100644 --- a/src/main/java/com/somemore/domains/volunteer/usecase/RegisterVolunteerUseCase.java +++ b/src/main/java/com/somemore/domains/volunteer/usecase/RegisterVolunteerUseCase.java @@ -3,5 +3,5 @@ import com.somemore.domains.volunteer.dto.request.VolunteerRegisterRequestDto; public interface RegisterVolunteerUseCase { - void registerVolunteer(VolunteerRegisterRequestDto dto); + void registerVolunteer(VolunteerRegisterRequestDto userId); } diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java index 80e9eea25..775c8049b 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java @@ -4,7 +4,6 @@ import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator; import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; import com.somemore.domains.review.usecase.ReviewQueryUseCase; -import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition; diff --git a/src/test/java/com/somemore/domains/center/domain/CenterTest.java b/src/test/java/com/somemore/domains/center/domain/CenterTest.java index 37d552488..6a9f84d53 100644 --- a/src/test/java/com/somemore/domains/center/domain/CenterTest.java +++ b/src/test/java/com/somemore/domains/center/domain/CenterTest.java @@ -32,7 +32,7 @@ void create() { () -> assertThat(center.getContactNumber()).isEqualTo(CONTACT_NUMBER), () -> assertThat(center.getImgUrl()).isEqualTo(IMG_URL), () -> assertThat(center.getIntroduce()).isEqualTo(INTRODUCE), - () -> assertThat(center.getHomepageLink()).isEqualTo(HOMEPAGE_LINK), + () -> assertThat(center.getHomepageLink()).isEqualTo(HOMEPAGE_LINK) ); } diff --git a/src/test/java/com/somemore/domains/center/service/command/CreatePreferItemServiceTest.java b/src/test/java/com/somemore/domains/center/service/command/CreatePreferItemServiceTest.java index f8bcef244..fb949e9b0 100644 --- a/src/test/java/com/somemore/domains/center/service/command/CreatePreferItemServiceTest.java +++ b/src/test/java/com/somemore/domains/center/service/command/CreatePreferItemServiceTest.java @@ -82,9 +82,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); centerRepository.save(center); diff --git a/src/test/java/com/somemore/domains/center/service/command/DeletePreferItemServiceTest.java b/src/test/java/com/somemore/domains/center/service/command/DeletePreferItemServiceTest.java index dc427f1d7..7148f09e0 100644 --- a/src/test/java/com/somemore/domains/center/service/command/DeletePreferItemServiceTest.java +++ b/src/test/java/com/somemore/domains/center/service/command/DeletePreferItemServiceTest.java @@ -92,9 +92,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); centerRepository.save(center); diff --git a/src/test/java/com/somemore/domains/center/service/query/CenterQueryServiceTest.java b/src/test/java/com/somemore/domains/center/service/query/CenterQueryServiceTest.java index 4b8c509f0..058077268 100644 --- a/src/test/java/com/somemore/domains/center/service/query/CenterQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/center/service/query/CenterQueryServiceTest.java @@ -125,9 +125,7 @@ void validateExistingCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); Center savedCenter = centerRepository.save(center); @@ -144,9 +142,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); } } diff --git a/src/test/java/com/somemore/domains/center/service/query/CenterSignServiceTest.java b/src/test/java/com/somemore/domains/center/service/query/CenterSignServiceTest.java deleted file mode 100644 index cd3b3342c..000000000 --- a/src/test/java/com/somemore/domains/center/service/query/CenterSignServiceTest.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.somemore.domains.center.service.query; - -import com.somemore.domains.center.domain.Center; -import com.somemore.domains.center.repository.center.CenterJpaRepository; -import com.somemore.domains.center.repository.center.CenterRepository; -import com.somemore.global.exception.BadRequestException; -import com.somemore.support.IntegrationTestSupport; -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 com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_CENTER; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -@Transactional -class CenterSignServiceTest extends IntegrationTestSupport { - - @Autowired - private CenterSignService centerSignService; - - @Autowired - private CenterRepository centerRepository; - - @Autowired - private CenterJpaRepository centerJpaRepository; - - @BeforeEach - void cleanUp() { - centerJpaRepository.deleteAll(); - } - - @DisplayName("계정 ID로 센터 ID를 조회할 수 있다.") - @Test - void getIdByAccountId() { - //given - Center center = createCenter(); - centerRepository.save(center); - - //when - UUID centerId = centerSignService.getIdByAccountId("account123"); - - //then - assertThat(centerId) - .isNotNull() - .isEqualTo(center.getId()); - } - - @DisplayName("존재하지 않는 계정 ID로 센터 ID를 조회하면 예외가 발생한다.") - @Test - void getIdByNonExistentAccountId() { - //given - String nonExistentAccountId = "nonExistentAccount123"; - - //when - //then - assertThatThrownBy(() -> centerSignService.getIdByAccountId(nonExistentAccountId)) - .isInstanceOf(BadRequestException.class) - .hasMessage(NOT_EXISTS_CENTER.getMessage()); - } - - @DisplayName("계정 ID로 비밀번호를 조회할 수 있다.") - @Test - void getPasswordByAccountId() { - //given - Center center = createCenter(); - centerRepository.save(center); - - //when - String password = centerSignService.getPasswordByAccountId("account123"); - - //then - assertThat(password) - .isNotNull() - .isEqualTo("password123"); - } - - @DisplayName("존재하지 않는 계정 ID로 비밀번호를 조회하면 예외가 발생한다.") - @Test - void getPasswordByNonExistentAccountId() { - //given - String nonExistentAccountId = "nonExistentAccount123"; - - //when - //then - assertThatThrownBy(() -> centerSignService.getPasswordByAccountId(nonExistentAccountId)) - .isInstanceOf(BadRequestException.class) - .hasMessage(NOT_EXISTS_CENTER.getMessage()); - } - - private static Center createCenter() { - return Center.create( - "기본 기관 이름", - "010-1234-5678", - "http://example.com/image.jpg", - "기관 소개 내용", - "http://example.com", - "account123", - "password123" - ); - } -} 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 ca635bcb0..cc5467217 100644 --- a/src/test/java/com/somemore/domains/community/repository/CommunityBoardRepositoryTest.java +++ b/src/test/java/com/somemore/domains/community/repository/CommunityBoardRepositoryTest.java @@ -4,7 +4,7 @@ import com.somemore.domains.community.repository.board.CommunityBoardRepository; 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.domains.volunteer.repository.old.VolunteerRepository; import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.BeforeEach; 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 ca36b22a9..dfe176094 100644 --- a/src/test/java/com/somemore/domains/community/repository/CommunityCommentRepositoryTest.java +++ b/src/test/java/com/somemore/domains/community/repository/CommunityCommentRepositoryTest.java @@ -6,7 +6,7 @@ import com.somemore.domains.community.repository.comment.CommunityCommentRepository; 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.domains.volunteer.repository.old.VolunteerRepository; import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.BeforeEach; 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 07e1f6363..c7707fbc0 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 @@ -8,7 +8,7 @@ import com.somemore.domains.community.usecase.board.CreateCommunityBoardUseCase; 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.domains.volunteer.repository.old.VolunteerRepository; import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.global.exception.BadRequestException; import com.somemore.global.exception.ExceptionMessage; 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 8d58d371d..d3b0a0e4e 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 @@ -7,7 +7,7 @@ import com.somemore.domains.community.repository.comment.CommunityCommentRepository; 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.domains.volunteer.repository.old.VolunteerRepository; import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.AfterEach; diff --git a/src/test/java/com/somemore/domains/interestcenter/service/CancelInterestCenterServiceTest.java b/src/test/java/com/somemore/domains/interestcenter/service/CancelInterestCenterServiceTest.java index 7f3b56d00..61b9c3b94 100644 --- a/src/test/java/com/somemore/domains/interestcenter/service/CancelInterestCenterServiceTest.java +++ b/src/test/java/com/somemore/domains/interestcenter/service/CancelInterestCenterServiceTest.java @@ -84,9 +84,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); centerRepository.save(center); diff --git a/src/test/java/com/somemore/domains/interestcenter/service/InterestCenterQueryServiceTest.java b/src/test/java/com/somemore/domains/interestcenter/service/InterestCenterQueryServiceTest.java index ebba619b9..2bde83904 100644 --- a/src/test/java/com/somemore/domains/interestcenter/service/InterestCenterQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/interestcenter/service/InterestCenterQueryServiceTest.java @@ -125,18 +125,13 @@ void getVolunteerIdsByCenterId_ReturnsEmptyList_WhenNoVolunteers() { assertThat(result).isEmpty(); } - - - private Center createCenter() { return Center.create( "기본 기관 이름", "010-1234-5678", "http://image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); } diff --git a/src/test/java/com/somemore/domains/interestcenter/service/RegisterInterestCenterServiceTest.java b/src/test/java/com/somemore/domains/interestcenter/service/RegisterInterestCenterServiceTest.java index 2c84a7246..611b8b640 100644 --- a/src/test/java/com/somemore/domains/interestcenter/service/RegisterInterestCenterServiceTest.java +++ b/src/test/java/com/somemore/domains/interestcenter/service/RegisterInterestCenterServiceTest.java @@ -96,9 +96,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); centerRepository.save(center); 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 6a1085d2c..a5bbba34c 100644 --- a/src/test/java/com/somemore/domains/note/repository/NoteRepositoryImplTest.java +++ b/src/test/java/com/somemore/domains/note/repository/NoteRepositoryImplTest.java @@ -8,7 +8,7 @@ import com.somemore.domains.note.repository.mapper.NoteReceiverViewForCenter; import com.somemore.domains.note.repository.mapper.NoteReceiverViewForVolunteer; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.VolunteerJpaRepository; +import com.somemore.domains.volunteer.repository.old.VolunteerJpaRepository; 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/note/service/NoteQueryServiceTest.java b/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java index 059d42bea..8e743841e 100644 --- a/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java @@ -9,7 +9,7 @@ import com.somemore.domains.note.repository.mapper.NoteReceiverViewForCenter; import com.somemore.domains.note.repository.mapper.NoteReceiverViewForVolunteer; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.VolunteerJpaRepository; +import com.somemore.domains.volunteer.repository.old.VolunteerJpaRepository; import com.somemore.global.exception.NoSuchElementException; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.DisplayName; diff --git a/src/test/java/com/somemore/domains/note/service/SendNoteToCenterServiceTest.java b/src/test/java/com/somemore/domains/note/service/SendNoteToCenterServiceTest.java index 23ab4a795..0d6445159 100644 --- a/src/test/java/com/somemore/domains/note/service/SendNoteToCenterServiceTest.java +++ b/src/test/java/com/somemore/domains/note/service/SendNoteToCenterServiceTest.java @@ -80,9 +80,7 @@ private Center createCenter() { "010-1234-5678", "http://example.com/image.jpg", "기관 소개 내용", - "http://example.com", - "account123", - "password123" + "http://example.com" ); centerRepository.save(center); 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 514e4d6c6..fb2ed8c42 100644 --- a/src/test/java/com/somemore/domains/note/service/SendNoteToVolunteerServiceTest.java +++ b/src/test/java/com/somemore/domains/note/service/SendNoteToVolunteerServiceTest.java @@ -4,7 +4,7 @@ import com.somemore.domains.note.dto.SendNoteToVolunteerRequestDto; import com.somemore.domains.note.repository.NoteJpaRepository; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.VolunteerJpaRepository; +import com.somemore.domains.volunteer.repository.old.VolunteerJpaRepository; 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/review/repository/ReviewRepositoryImplTest.java b/src/test/java/com/somemore/domains/review/repository/ReviewRepositoryImplTest.java index 2882fc1d1..c30ab81cd 100644 --- a/src/test/java/com/somemore/domains/review/repository/ReviewRepositoryImplTest.java +++ b/src/test/java/com/somemore/domains/review/repository/ReviewRepositoryImplTest.java @@ -8,7 +8,7 @@ import com.somemore.domains.review.domain.Review; import com.somemore.domains.review.dto.condition.ReviewSearchCondition; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.VolunteerRepository; +import com.somemore.domains.volunteer.repository.old.VolunteerRepository; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository; import com.somemore.support.IntegrationTestSupport; 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 b63212956..6696b0b4b 100644 --- a/src/test/java/com/somemore/domains/review/service/ReviewQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/review/service/ReviewQueryServiceTest.java @@ -11,7 +11,7 @@ import com.somemore.domains.review.dto.response.ReviewDetailWithNicknameResponseDto; import com.somemore.domains.review.repository.ReviewRepository; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.VolunteerRepository; +import com.somemore.domains.volunteer.repository.old.VolunteerRepository; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository; import com.somemore.global.exception.NoSuchElementException; diff --git a/src/test/java/com/somemore/domains/volunteer/service/RegisterVolunteerServiceTest.java b/src/test/java/com/somemore/domains/volunteer/service/RegisterVolunteerServiceTest.java deleted file mode 100644 index 148f75022..000000000 --- a/src/test/java/com/somemore/domains/volunteer/service/RegisterVolunteerServiceTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.somemore.domains.volunteer.service; - -import com.somemore.domains.volunteer.domain.Gender; -import com.somemore.domains.volunteer.domain.Tier; -import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.domain.VolunteerDetail; -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.domain.OAuthProvider; -import com.somemore.support.IntegrationTestSupport; -import jakarta.persistence.EntityNotFoundException; -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 RegisterVolunteerServiceTest extends IntegrationTestSupport { - - @Autowired - private RegisterVolunteerService registerVolunteerService; - - @Autowired - private VolunteerRepository volunteerRepository; - - @Autowired - private VolunteerDetailRepository volunteerDetailRepository; - - @DisplayName("봉사자와 상세 정보를 저장한다") - @Test - void registerVolunteer() { - // given - VolunteerRegisterRequestDto dto = new VolunteerRegisterRequestDto( - OAuthProvider.NAVER, - "oauth-id-example", - "making", - "making@example.com", - "M", - "06-08", - "1998", - "010-1234-5678" - ); - - // when - registerVolunteerService.registerVolunteer(dto); - - // then - Volunteer volunteer = volunteerRepository.findByOauthId("oauth-id-example") - .orElseThrow(EntityNotFoundException::new); - VolunteerDetail volunteerDetail = volunteerDetailRepository.findByVolunteerId(volunteer.getId()) - .orElseThrow(EntityNotFoundException::new); - - // Volunteer - assertThat(volunteer.getOauthProvider()).isEqualTo(OAuthProvider.NAVER); - assertThat(volunteer.getOauthId()).isEqualTo("oauth-id-example"); - assertThat(volunteer.getNickname()).hasSize(8); // 8자리 default UUID - assertThat(volunteer.getImgUrl()).isEqualTo(""); // default - assertThat(volunteer.getIntroduce()).isEqualTo(""); // default - assertThat(volunteer.getTier()).isEqualTo(Tier.RED); // default - assertThat(volunteer.getTotalVolunteerHours()).isEqualTo(0); // default - assertThat(volunteer.getTotalVolunteerCount()).isEqualTo(0); // default - - // VolunteerDetail - assertThat(volunteerDetail.getVolunteerId()).isEqualTo(volunteer.getId()); - assertThat(volunteerDetail.getName()).isEqualTo("making"); - assertThat(volunteerDetail.getEmail()).isEqualTo("making@example.com"); - assertThat(volunteerDetail.getGender()).isEqualTo(Gender.MALE); - assertThat(volunteerDetail.getBirthDate()).isEqualTo("1998-06-08"); - assertThat(volunteerDetail.getContactNumber()).isEqualTo("010-1234-5678"); - } -} 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 00aaa82b4..1135ece68 100644 --- a/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockServiceTest.java @@ -1,7 +1,7 @@ package com.somemore.domains.volunteer.service; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.VolunteerRepository; +import com.somemore.domains.volunteer.repository.old.VolunteerRepository; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; 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 a5492dee3..0112ccbdf 100644 --- a/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileServiceTest.java @@ -2,7 +2,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.domains.volunteer.repository.old.VolunteerRepository; import com.somemore.global.auth.oauth.domain.OAuthProvider; 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 33a5f0a08..19f5ea976 100644 --- a/src/test/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeServiceTest.java @@ -3,7 +3,7 @@ import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.VolunteerRepository; +import com.somemore.domains.volunteer.repository.old.VolunteerRepository; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.dto.request.VolunteerApplySettleRequestDto; import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository; 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 6d53f31a2..393bc3e13 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 @@ -157,28 +157,6 @@ void throwExceptionWhenRefreshTokenIsMissing() { .hasMessage(JwtErrorType.EXPIRED_TOKEN.getMessage()); } - @DisplayName("리프레시된 AccessToken은 쿠키에 올바르게 저장된다") - @Test - void refreshedAccessTokenIsSetInCookie() { - // given - String userId = UUID.randomUUID().toString(); - UserRole role = UserRole.VOLUNTEER; - - EncodedToken expiredAccessToken = createExpiredToken(userId, role); - createAndSaveRefreshToken(userId, expiredAccessToken, Instant.now().plusMillis(TokenType.REFRESH.getPeriodInMillis())); - - MockHttpServletResponse mockResponse = new MockHttpServletResponse(); - - // when - jwtService.processAccessToken(expiredAccessToken, mockResponse); - - // then - String cookieHeader = mockResponse.getHeader("Set-Cookie"); - assertThat(cookieHeader).contains("ACCESS_TOKEN="); - assertThat(cookieHeader).contains("HttpOnly"); - assertThat(cookieHeader).contains("Secure"); - } - @DisplayName("기존 RefreshToken이 갱신된다") @Test void refreshTokenIsUpdated() { diff --git a/src/test/java/com/somemore/support/fixture/CenterFixture.java b/src/test/java/com/somemore/support/fixture/CenterFixture.java index 4be307ac1..a28af198e 100644 --- a/src/test/java/com/somemore/support/fixture/CenterFixture.java +++ b/src/test/java/com/somemore/support/fixture/CenterFixture.java @@ -14,8 +14,6 @@ public static Center createCenter() { .imgUrl("https://image.domain.com/center-img") .introduce("센터 소개") .homepageLink("https://www.centerhomepage.com") - .accountId("center_account") - .accountPw("password123") .build(); } @@ -26,8 +24,6 @@ public static Center createCenter(String name) { .imgUrl("https://image.domain.com/center-img") .introduce("센터 소개") .homepageLink("https://www.centerhomepage.com") - .accountId("center_account") - .accountPw("password123") .build(); } From e827dfb0ee17db17d18bd1ebd4e01f373085817b 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, 14 Jan 2025 23:11:53 +0900 Subject: [PATCH 19/34] =?UTF-8?q?feat(user):=20=EB=B4=89=EC=82=AC=EC=9E=90?= =?UTF-8?q?/=EA=B8=B0=EA=B4=80=20=EC=97=94=ED=8B=B0=ED=8B=B0,=20=EB=A6=AC?= =?UTF-8?q?=ED=8F=AC=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 - 저장 기능 추가 --- .../center/domain/Center_NEW.java | 2 +- .../repository/CenterJpaRepository.java | 9 +++++++++ .../center/repository/CenterRepository.java | 8 ++++++++ .../repository/CenterRepositoryImpl.java | 19 +++++++++++++++++++ .../volunteer/domain/Volunteer_NEW.java | 4 +++- .../repository/VolunteerJpaRepository.java | 9 +++++++++ .../repository/VolunteerRepository.java | 8 ++++++++ .../repository/VolunteerRepositoryImpl.java | 19 +++++++++++++++++++ 8 files changed, 76 insertions(+), 2 deletions(-) rename src/main/java/com/somemore/{domains => }/center/domain/Center_NEW.java (97%) create mode 100644 src/main/java/com/somemore/center/repository/CenterJpaRepository.java create mode 100644 src/main/java/com/somemore/center/repository/CenterRepository.java create mode 100644 src/main/java/com/somemore/center/repository/CenterRepositoryImpl.java rename src/main/java/com/somemore/{domains => }/volunteer/domain/Volunteer_NEW.java (92%) create mode 100644 src/main/java/com/somemore/volunteer/repository/VolunteerJpaRepository.java create mode 100644 src/main/java/com/somemore/volunteer/repository/VolunteerRepository.java create mode 100644 src/main/java/com/somemore/volunteer/repository/VolunteerRepositoryImpl.java diff --git a/src/main/java/com/somemore/domains/center/domain/Center_NEW.java b/src/main/java/com/somemore/center/domain/Center_NEW.java similarity index 97% rename from src/main/java/com/somemore/domains/center/domain/Center_NEW.java rename to src/main/java/com/somemore/center/domain/Center_NEW.java index 786beb668..6da4c19e9 100644 --- a/src/main/java/com/somemore/domains/center/domain/Center_NEW.java +++ b/src/main/java/com/somemore/center/domain/Center_NEW.java @@ -1,4 +1,4 @@ -package com.somemore.domains.center.domain; +package com.somemore.center.domain; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/src/main/java/com/somemore/center/repository/CenterJpaRepository.java b/src/main/java/com/somemore/center/repository/CenterJpaRepository.java new file mode 100644 index 000000000..716090178 --- /dev/null +++ b/src/main/java/com/somemore/center/repository/CenterJpaRepository.java @@ -0,0 +1,9 @@ +package com.somemore.center.repository; + +import com.somemore.center.domain.Center_NEW; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.UUID; + +public interface CenterJpaRepository extends JpaRepository { +} diff --git a/src/main/java/com/somemore/center/repository/CenterRepository.java b/src/main/java/com/somemore/center/repository/CenterRepository.java new file mode 100644 index 000000000..8a730e903 --- /dev/null +++ b/src/main/java/com/somemore/center/repository/CenterRepository.java @@ -0,0 +1,8 @@ +package com.somemore.center.repository; + +import com.somemore.center.domain.Center_NEW; + +public interface CenterRepository { + + Center_NEW save(Center_NEW center); +} diff --git a/src/main/java/com/somemore/center/repository/CenterRepositoryImpl.java b/src/main/java/com/somemore/center/repository/CenterRepositoryImpl.java new file mode 100644 index 000000000..3b27dbddc --- /dev/null +++ b/src/main/java/com/somemore/center/repository/CenterRepositoryImpl.java @@ -0,0 +1,19 @@ +package com.somemore.center.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.somemore.center.domain.Center_NEW; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class CenterRepositoryImpl implements CenterRepository { + + private final CenterJpaRepository centerJpaRepository; + private final JPAQueryFactory queryFactory; + + @Override + public Center_NEW save(Center_NEW center) { + return center; + } +} diff --git a/src/main/java/com/somemore/domains/volunteer/domain/Volunteer_NEW.java b/src/main/java/com/somemore/volunteer/domain/Volunteer_NEW.java similarity index 92% rename from src/main/java/com/somemore/domains/volunteer/domain/Volunteer_NEW.java rename to src/main/java/com/somemore/volunteer/domain/Volunteer_NEW.java index 57d7d99c1..d0db7b1a6 100644 --- a/src/main/java/com/somemore/domains/volunteer/domain/Volunteer_NEW.java +++ b/src/main/java/com/somemore/volunteer/domain/Volunteer_NEW.java @@ -1,5 +1,7 @@ -package com.somemore.domains.volunteer.domain; +package com.somemore.volunteer.domain; +import com.somemore.domains.volunteer.domain.Gender; +import com.somemore.domains.volunteer.domain.Tier; import com.somemore.global.common.entity.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/src/main/java/com/somemore/volunteer/repository/VolunteerJpaRepository.java b/src/main/java/com/somemore/volunteer/repository/VolunteerJpaRepository.java new file mode 100644 index 000000000..994bf0884 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/repository/VolunteerJpaRepository.java @@ -0,0 +1,9 @@ +package com.somemore.volunteer.repository; + +import com.somemore.volunteer.domain.Volunteer_NEW; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.UUID; + +public interface VolunteerJpaRepository extends JpaRepository { +} diff --git a/src/main/java/com/somemore/volunteer/repository/VolunteerRepository.java b/src/main/java/com/somemore/volunteer/repository/VolunteerRepository.java new file mode 100644 index 000000000..27066a6f5 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/repository/VolunteerRepository.java @@ -0,0 +1,8 @@ +package com.somemore.volunteer.repository; + +import com.somemore.volunteer.domain.Volunteer_NEW; + +public interface VolunteerRepository { + + Volunteer_NEW save(Volunteer_NEW volunteer); +} diff --git a/src/main/java/com/somemore/volunteer/repository/VolunteerRepositoryImpl.java b/src/main/java/com/somemore/volunteer/repository/VolunteerRepositoryImpl.java new file mode 100644 index 000000000..e1abcde5b --- /dev/null +++ b/src/main/java/com/somemore/volunteer/repository/VolunteerRepositoryImpl.java @@ -0,0 +1,19 @@ +package com.somemore.volunteer.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.somemore.volunteer.domain.Volunteer_NEW; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class VolunteerRepositoryImpl implements VolunteerRepository { + + private final VolunteerJpaRepository volunteerJpaRepository; + private final JPAQueryFactory queryFactory; + + @Override + public Volunteer_NEW save(Volunteer_NEW volunteer) { + return volunteerJpaRepository.save(volunteer); + } +} From d1e50f115a2089781f3de4d9460bbae63958b182 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, 14 Jan 2025 23:15:11 +0900 Subject: [PATCH 20/34] rollback --- .../volunteerapply/service/VolunteerApplyQueryFacadeService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java index 775c8049b..80e9eea25 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java @@ -4,6 +4,7 @@ import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator; import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; import com.somemore.domains.review.usecase.ReviewQueryUseCase; +import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition; From fd86a1f3a90e1977897387fe8fd490fe672d2eed 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, 15 Jan 2025 15:18:29 +0900 Subject: [PATCH 21/34] =?UTF-8?q?feat(user):=20volunteer,=20center=20?= =?UTF-8?q?=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EC=A0=95=EC=A0=81=20=ED=8C=A9=ED=86=A0=EB=A6=AC=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20ENUM=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/somemore/center/domain/Center_NEW.java | 9 ++++----- .../somemore/domains/volunteer/domain/Gender.java | 4 ++++ .../com/somemore/domains/volunteer/domain/Tier.java | 5 +++++ .../com/somemore/volunteer/domain/Volunteer_NEW.java | 12 +++++------- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/somemore/center/domain/Center_NEW.java b/src/main/java/com/somemore/center/domain/Center_NEW.java index 6da4c19e9..c07115451 100644 --- a/src/main/java/com/somemore/center/domain/Center_NEW.java +++ b/src/main/java/com/somemore/center/domain/Center_NEW.java @@ -19,6 +19,7 @@ @Table(name = "center_new") // TODO suffix 삭제 public class Center_NEW { + public static final String DEFAULT_NAME = "기관"; @Id @GeneratedValue(strategy = GenerationType.UUID) @Column(name = "id", nullable = false, columnDefinition = "BINARY(16)") @@ -40,13 +41,11 @@ private Center_NEW(UUID userId, String name, String homepageUrl) { this.homepageUrl = homepageUrl; } - public static Center_NEW create(UUID userId, - String name, - String homepageUrl) { + public static Center_NEW createDefault(UUID userId) { return Center_NEW.builder() .userId(userId) - .name(name) - .homepageUrl(homepageUrl) + .name(DEFAULT_NAME + userId.toString().substring(0, 8)) + .homepageUrl("") .build(); } } diff --git a/src/main/java/com/somemore/domains/volunteer/domain/Gender.java b/src/main/java/com/somemore/domains/volunteer/domain/Gender.java index 8b7f81b66..de8889065 100644 --- a/src/main/java/com/somemore/domains/volunteer/domain/Gender.java +++ b/src/main/java/com/somemore/domains/volunteer/domain/Gender.java @@ -14,6 +14,10 @@ public enum Gender { this.code = code; } + public static Gender getDefault() { + return UNDEFINED; + } + public static Gender from(String code) { for (Gender gender : Gender.values()) { if (gender.code.equalsIgnoreCase(code)) { diff --git a/src/main/java/com/somemore/domains/volunteer/domain/Tier.java b/src/main/java/com/somemore/domains/volunteer/domain/Tier.java index 6af0204d0..9caad73b8 100644 --- a/src/main/java/com/somemore/domains/volunteer/domain/Tier.java +++ b/src/main/java/com/somemore/domains/volunteer/domain/Tier.java @@ -12,4 +12,9 @@ public enum Tier { INDIGO, VIOLET, RAINBOW + ; + + public static Tier getDefault() { + return RED; + } } diff --git a/src/main/java/com/somemore/volunteer/domain/Volunteer_NEW.java b/src/main/java/com/somemore/volunteer/domain/Volunteer_NEW.java index d0db7b1a6..60a2a41bd 100644 --- a/src/main/java/com/somemore/volunteer/domain/Volunteer_NEW.java +++ b/src/main/java/com/somemore/volunteer/domain/Volunteer_NEW.java @@ -24,6 +24,7 @@ @Table(name = "volunteer_new") // TODO suffix 삭제 public class Volunteer_NEW extends BaseEntity { + public static final String DEFAULT_NAME = "봉사자"; @Id @GeneratedValue(strategy = GenerationType.UUID) @Column(name = "id", nullable = false, columnDefinition = "BINARY(16)") @@ -56,15 +57,12 @@ private Volunteer_NEW( this.tier = tier; } - public static Volunteer_NEW create(UUID userId, - String name, - Gender gender, - Tier tier) { + public static Volunteer_NEW createDefault(UUID userId) { return Volunteer_NEW.builder() .userId(userId) - .name(name) - .gender(gender) - .tier(tier) + .name(DEFAULT_NAME + userId.toString().substring(0, 8)) + .gender(Gender.getDefault()) + .tier(Tier.getDefault()) .build(); } } From 62075757cd31fbaf3ca2f857b742cdea50f9cbf6 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, 15 Jan 2025 15:19:09 +0900 Subject: [PATCH 22/34] =?UTF-8?q?feat(user):=20volunteer,=20center=20?= =?UTF-8?q?=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - center repository 구현체 수정 --- .../repository/CenterRepositoryImpl.java | 2 +- .../center/service/registerCenterService.java | 23 ++++++++++++++++++ .../center/service/registerCenterUseCase.java | 10 ++++++++ .../service/registerVolunteerService.java | 24 +++++++++++++++++++ .../service/registerVolunteerUseCase.java | 10 ++++++++ 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/somemore/center/service/registerCenterService.java create mode 100644 src/main/java/com/somemore/center/service/registerCenterUseCase.java create mode 100644 src/main/java/com/somemore/volunteer/service/registerVolunteerService.java create mode 100644 src/main/java/com/somemore/volunteer/service/registerVolunteerUseCase.java diff --git a/src/main/java/com/somemore/center/repository/CenterRepositoryImpl.java b/src/main/java/com/somemore/center/repository/CenterRepositoryImpl.java index 3b27dbddc..b4edf1de6 100644 --- a/src/main/java/com/somemore/center/repository/CenterRepositoryImpl.java +++ b/src/main/java/com/somemore/center/repository/CenterRepositoryImpl.java @@ -14,6 +14,6 @@ public class CenterRepositoryImpl implements CenterRepository { @Override public Center_NEW save(Center_NEW center) { - return center; + return centerJpaRepository.save(center); } } diff --git a/src/main/java/com/somemore/center/service/registerCenterService.java b/src/main/java/com/somemore/center/service/registerCenterService.java new file mode 100644 index 000000000..cbd6c7765 --- /dev/null +++ b/src/main/java/com/somemore/center/service/registerCenterService.java @@ -0,0 +1,23 @@ +package com.somemore.center.service; + +import com.somemore.center.domain.Center_NEW; +import com.somemore.center.repository.CenterRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@RequiredArgsConstructor +@Transactional +public class registerCenterService implements registerCenterUseCase { + + private final CenterRepository centerRepository; + + @Override + public Center_NEW register(UUID userId) { + Center_NEW center = Center_NEW.createDefault(userId); + return centerRepository.save(center); + } +} diff --git a/src/main/java/com/somemore/center/service/registerCenterUseCase.java b/src/main/java/com/somemore/center/service/registerCenterUseCase.java new file mode 100644 index 000000000..469c175db --- /dev/null +++ b/src/main/java/com/somemore/center/service/registerCenterUseCase.java @@ -0,0 +1,10 @@ +package com.somemore.center.service; + +import com.somemore.center.domain.Center_NEW; + +import java.util.UUID; + +public interface registerCenterUseCase { + + Center_NEW register(UUID userId); +} diff --git a/src/main/java/com/somemore/volunteer/service/registerVolunteerService.java b/src/main/java/com/somemore/volunteer/service/registerVolunteerService.java new file mode 100644 index 000000000..b48941696 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/service/registerVolunteerService.java @@ -0,0 +1,24 @@ +package com.somemore.volunteer.service; + +import com.somemore.volunteer.domain.Volunteer_NEW; +import com.somemore.volunteer.repository.VolunteerRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@RequiredArgsConstructor +@Transactional +public class registerVolunteerService implements registerVolunteerUseCase { + + private final VolunteerRepository volunteerRepository; + + @Override + public Volunteer_NEW register(UUID userId) { + Volunteer_NEW volunteer = Volunteer_NEW.createDefault(userId); + + return volunteerRepository.save(volunteer); + } +} diff --git a/src/main/java/com/somemore/volunteer/service/registerVolunteerUseCase.java b/src/main/java/com/somemore/volunteer/service/registerVolunteerUseCase.java new file mode 100644 index 000000000..e6a1c1203 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/service/registerVolunteerUseCase.java @@ -0,0 +1,10 @@ +package com.somemore.volunteer.service; + +import com.somemore.volunteer.domain.Volunteer_NEW; + +import java.util.UUID; + +public interface registerVolunteerUseCase { + + Volunteer_NEW register(UUID userId); +} From e3d4cd8744406943e5c7b22249ef36738385d7d9 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, 15 Jan 2025 15:20:33 +0900 Subject: [PATCH 23/34] rollback --- .../old/VolunteerJpaRepository.java | 13 +++ .../repository/old/VolunteerRepository.java | 33 ++++++ .../old/VolunteerRepositoryImpl.java | 110 ++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerJpaRepository.java create mode 100644 src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepository.java create mode 100644 src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepositoryImpl.java diff --git a/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerJpaRepository.java b/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerJpaRepository.java new file mode 100644 index 000000000..408f2b835 --- /dev/null +++ b/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerJpaRepository.java @@ -0,0 +1,13 @@ +package com.somemore.domains.volunteer.repository.old; + +import com.somemore.domains.volunteer.domain.Volunteer; + +import java.util.List; +import java.util.UUID; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface VolunteerJpaRepository extends JpaRepository { + + List findAllByIdInAndDeletedFalse(List ids); + boolean existsByIdAndDeletedIsFalse(UUID id); +} diff --git a/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepository.java b/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepository.java new file mode 100644 index 000000000..cc6622b2f --- /dev/null +++ b/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepository.java @@ -0,0 +1,33 @@ +package com.somemore.domains.volunteer.repository.old; + +import com.somemore.domains.volunteer.domain.Volunteer; +import com.somemore.domains.volunteer.repository.mapper.VolunteerOverviewForRankingByHours; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +public interface VolunteerRepository { + + Volunteer save(Volunteer volunteer); + + Optional findById(UUID id); + + Optional findByOauthId(String oauthId); + + String findNicknameById(UUID id); + + List findRankingByVolunteerHours(); + + void deleteAllInBatch(); + + List findAllByIds(List volunteerIds); + + boolean existsByVolunteerId(UUID volunteerId); + + default boolean doesNotExistsByVolunteerId(UUID volunteerId) { + return !existsByVolunteerId(volunteerId); + } +} diff --git a/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepositoryImpl.java b/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepositoryImpl.java new file mode 100644 index 000000000..e10ad713c --- /dev/null +++ b/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepositoryImpl.java @@ -0,0 +1,110 @@ +package com.somemore.domains.volunteer.repository.old; + +import com.querydsl.core.types.Path; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.somemore.domains.volunteer.domain.QVolunteer; +import com.somemore.domains.volunteer.domain.Volunteer; +import com.somemore.domains.volunteer.repository.mapper.VolunteerOverviewForRankingByHours; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@RequiredArgsConstructor +@Repository +public class VolunteerRepositoryImpl implements VolunteerRepository { + + private final VolunteerJpaRepository volunteerJpaRepository; + private final JPAQueryFactory queryFactory; + + private static final QVolunteer volunteer = QVolunteer.volunteer; + + @Override + public Volunteer save(Volunteer volunteer) { + return volunteerJpaRepository.save(volunteer); + } + + @Override + public Optional findById(UUID id) { + return findOne(volunteer.id.eq(id)); + } + + @Override + public Optional findByOauthId(String oauthId) { + return findOne(volunteer.oauthId.eq(oauthId)); + } + + @Override + public String findNicknameById(UUID id) { + return findDynamicField(id, volunteer.nickname) + .orElse(null); + } + + @Override + public List findRankingByVolunteerHours() { + return queryFactory + .select(Projections.constructor(VolunteerOverviewForRankingByHours.class, + volunteer.id, + volunteer.nickname, + volunteer.imgUrl, + volunteer.introduce, + volunteer.tier, + volunteer.totalVolunteerHours + )) + .from(volunteer) + .where(isNotDeleted()) + .orderBy(volunteer.totalVolunteerHours.desc()) + .limit(4) + .fetch(); + } + + @Override + public void deleteAllInBatch() { + volunteerJpaRepository.deleteAllInBatch(); + } + + @Override + public List findAllByIds(List volunteerIds) { + return volunteerJpaRepository.findAllByIdInAndDeletedFalse(volunteerIds); + } + + private Optional findOne(BooleanExpression condition) { + + return Optional.ofNullable( + queryFactory + .selectFrom(volunteer) + .where( + condition, + isNotDeleted() + ) + .fetchOne() + ); + } + + private Optional findDynamicField(UUID id, Path field) { + + return Optional.ofNullable( + queryFactory + .select(field) + .from(volunteer) + .where( + volunteer.id.eq(id), + isNotDeleted() + ) + .fetchOne() + ); + } + + @Override + public boolean existsByVolunteerId(UUID volunteerId) { + return volunteerJpaRepository.existsByIdAndDeletedIsFalse(volunteerId); + } + + private BooleanExpression isNotDeleted() { + return volunteer.deleted.isFalse(); + } +} From bab7483f8aacdda3682b359e9253a814df3973dc 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, 15 Jan 2025 15:31:30 +0900 Subject: [PATCH 24/34] =?UTF-8?q?refactor:=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=20=EB=AA=85=20=ED=8C=8C=EC=8A=A4=EC=B9=BC=20=EC=BC=80=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...sterCenterService.java => RegisterCenterService.java} | 3 ++- .../RegisterCenterUseCase.java} | 4 ++-- ...RegisterUserService.java => RegisterUserUseCase.java} | 3 +-- ...lunteerService.java => RegisterVolunteerService.java} | 3 ++- .../RegisterVolunteerUseCase.java} | 4 ++-- ...UserServiceTest.java => RegisterUserUseCaseTest.java} | 9 ++++----- 6 files changed, 13 insertions(+), 13 deletions(-) rename src/main/java/com/somemore/center/service/{registerCenterService.java => RegisterCenterService.java} (83%) rename src/main/java/com/somemore/center/{service/registerCenterUseCase.java => usecase/RegisterCenterUseCase.java} (59%) rename src/main/java/com/somemore/user/service/{RegisterUserService.java => RegisterUserUseCase.java} (94%) rename src/main/java/com/somemore/volunteer/service/{registerVolunteerService.java => RegisterVolunteerService.java} (83%) rename src/main/java/com/somemore/volunteer/{service/registerVolunteerUseCase.java => usecase/RegisterVolunteerUseCase.java} (59%) rename src/test/java/com/somemore/user/service/{RegisterUserServiceTest.java => RegisterUserUseCaseTest.java} (94%) diff --git a/src/main/java/com/somemore/center/service/registerCenterService.java b/src/main/java/com/somemore/center/service/RegisterCenterService.java similarity index 83% rename from src/main/java/com/somemore/center/service/registerCenterService.java rename to src/main/java/com/somemore/center/service/RegisterCenterService.java index cbd6c7765..6e1a9652d 100644 --- a/src/main/java/com/somemore/center/service/registerCenterService.java +++ b/src/main/java/com/somemore/center/service/RegisterCenterService.java @@ -2,6 +2,7 @@ import com.somemore.center.domain.Center_NEW; import com.somemore.center.repository.CenterRepository; +import com.somemore.center.usecase.RegisterCenterUseCase; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -11,7 +12,7 @@ @Service @RequiredArgsConstructor @Transactional -public class registerCenterService implements registerCenterUseCase { +public class RegisterCenterService implements RegisterCenterUseCase { private final CenterRepository centerRepository; diff --git a/src/main/java/com/somemore/center/service/registerCenterUseCase.java b/src/main/java/com/somemore/center/usecase/RegisterCenterUseCase.java similarity index 59% rename from src/main/java/com/somemore/center/service/registerCenterUseCase.java rename to src/main/java/com/somemore/center/usecase/RegisterCenterUseCase.java index 469c175db..7e7eb5b7b 100644 --- a/src/main/java/com/somemore/center/service/registerCenterUseCase.java +++ b/src/main/java/com/somemore/center/usecase/RegisterCenterUseCase.java @@ -1,10 +1,10 @@ -package com.somemore.center.service; +package com.somemore.center.usecase; import com.somemore.center.domain.Center_NEW; import java.util.UUID; -public interface registerCenterUseCase { +public interface RegisterCenterUseCase { Center_NEW register(UUID userId); } diff --git a/src/main/java/com/somemore/user/service/RegisterUserService.java b/src/main/java/com/somemore/user/service/RegisterUserUseCase.java similarity index 94% rename from src/main/java/com/somemore/user/service/RegisterUserService.java rename to src/main/java/com/somemore/user/service/RegisterUserUseCase.java index acbb13b35..a30766772 100644 --- a/src/main/java/com/somemore/user/service/RegisterUserService.java +++ b/src/main/java/com/somemore/user/service/RegisterUserUseCase.java @@ -9,7 +9,6 @@ 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; @@ -21,7 +20,7 @@ @Slf4j @RequiredArgsConstructor @Transactional -public class RegisterUserService implements RegisterUserUseCase { +public class RegisterUserUseCase implements com.somemore.user.usecase.RegisterUserUseCase { private final UserRepository userRepository; private final UserSettingRepository userSettingRepository; diff --git a/src/main/java/com/somemore/volunteer/service/registerVolunteerService.java b/src/main/java/com/somemore/volunteer/service/RegisterVolunteerService.java similarity index 83% rename from src/main/java/com/somemore/volunteer/service/registerVolunteerService.java rename to src/main/java/com/somemore/volunteer/service/RegisterVolunteerService.java index b48941696..85c30f8e1 100644 --- a/src/main/java/com/somemore/volunteer/service/registerVolunteerService.java +++ b/src/main/java/com/somemore/volunteer/service/RegisterVolunteerService.java @@ -2,6 +2,7 @@ import com.somemore.volunteer.domain.Volunteer_NEW; import com.somemore.volunteer.repository.VolunteerRepository; +import com.somemore.volunteer.usecase.RegisterVolunteerUseCase; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -11,7 +12,7 @@ @Service @RequiredArgsConstructor @Transactional -public class registerVolunteerService implements registerVolunteerUseCase { +public class RegisterVolunteerService implements RegisterVolunteerUseCase { private final VolunteerRepository volunteerRepository; diff --git a/src/main/java/com/somemore/volunteer/service/registerVolunteerUseCase.java b/src/main/java/com/somemore/volunteer/usecase/RegisterVolunteerUseCase.java similarity index 59% rename from src/main/java/com/somemore/volunteer/service/registerVolunteerUseCase.java rename to src/main/java/com/somemore/volunteer/usecase/RegisterVolunteerUseCase.java index e6a1c1203..4c82f07e0 100644 --- a/src/main/java/com/somemore/volunteer/service/registerVolunteerUseCase.java +++ b/src/main/java/com/somemore/volunteer/usecase/RegisterVolunteerUseCase.java @@ -1,10 +1,10 @@ -package com.somemore.volunteer.service; +package com.somemore.volunteer.usecase; import com.somemore.volunteer.domain.Volunteer_NEW; import java.util.UUID; -public interface registerVolunteerUseCase { +public interface RegisterVolunteerUseCase { Volunteer_NEW register(UUID userId); } diff --git a/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java b/src/test/java/com/somemore/user/service/RegisterUserUseCaseTest.java similarity index 94% rename from src/test/java/com/somemore/user/service/RegisterUserServiceTest.java rename to src/test/java/com/somemore/user/service/RegisterUserUseCaseTest.java index 7e6eb7cb4..8f90123fb 100644 --- a/src/test/java/com/somemore/user/service/RegisterUserServiceTest.java +++ b/src/test/java/com/somemore/user/service/RegisterUserUseCaseTest.java @@ -12,7 +12,6 @@ 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; @@ -23,10 +22,10 @@ import static org.assertj.core.api.Assertions.assertThat; @Transactional -class RegisterUserServiceTest extends IntegrationTestSupport { +class RegisterUserUseCaseTest extends IntegrationTestSupport { @Autowired - private RegisterUserService registerUserService; + private RegisterUserUseCase registerUserUseCase; @Autowired private UserRepository userRepository; @@ -45,7 +44,7 @@ void registerOAuthUser() { CommonOAuthInfo commonOAuthInfo = new CommonOAuthInfo(provider, "test"); // when - User registeredUser = registerUserService.registerOAuthUser(commonOAuthInfo, UserRole.getOAuthUserDefaultRole()); + User registeredUser = registerUserUseCase.registerOAuthUser(commonOAuthInfo, UserRole.getOAuthUserDefaultRole()); // then User savedUser = userRepository.findById(registeredUser.getId()).orElseThrow(); @@ -79,7 +78,7 @@ void registerLocalUser() { UserRole role = UserRole.CENTER; // when - User registeredUser = registerUserService.registerLocalUser(userAuthInfo, role); + User registeredUser = registerUserUseCase.registerLocalUser(userAuthInfo, role); // then User savedUser = userRepository.findById(registeredUser.getId()).orElseThrow(); From 698d84406b04e2de9bc0864958f7fabd2212c8c6 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, 15 Jan 2025 15:35:30 +0900 Subject: [PATCH 25/34] =?UTF-8?q?feat(register):=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20=EB=A1=9C=EC=A7=81=20(=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EA=B0=80=20=EC=83=9D=EC=84=B1=EB=90=9C=20=ED=9B=84,=20?= =?UTF-8?q?=EB=B4=89=EC=82=AC=EC=9E=90=EB=82=98=20=EA=B8=B0=EA=B4=80?= =?UTF-8?q?=EC=9D=B4=20=EC=83=9D=EC=84=B1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/auth/sign/up/SignUpController.java | 27 +++++++++++ .../global/auth/sign/up/SignUpRequestDto.java | 23 ++++++++++ .../global/auth/sign/up/SignUpService.java | 46 +++++++++++++++++++ .../global/auth/sign/up/SignUpUseCase.java | 6 +++ 4 files changed, 102 insertions(+) create mode 100644 src/main/java/com/somemore/global/auth/sign/up/SignUpController.java create mode 100644 src/main/java/com/somemore/global/auth/sign/up/SignUpRequestDto.java create mode 100644 src/main/java/com/somemore/global/auth/sign/up/SignUpService.java create mode 100644 src/main/java/com/somemore/global/auth/sign/up/SignUpUseCase.java diff --git a/src/main/java/com/somemore/global/auth/sign/up/SignUpController.java b/src/main/java/com/somemore/global/auth/sign/up/SignUpController.java new file mode 100644 index 000000000..0b278ba2a --- /dev/null +++ b/src/main/java/com/somemore/global/auth/sign/up/SignUpController.java @@ -0,0 +1,27 @@ +package com.somemore.global.auth.sign.up; + +import com.somemore.global.common.response.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api") +@Tag(name = "SignUp API", description = "유저 회원가입") +public class SignUpController { + + private final SignUpUseCase signUpUseCase; + + @PostMapping("/sign-up") + public ApiResponse signUp( + @RequestBody SignUpRequestDto signUpRequestDto + ) { + signUpUseCase.signUp(signUpRequestDto); + + return ApiResponse.ok("회원가입 되었습니다"); + } +} diff --git a/src/main/java/com/somemore/global/auth/sign/up/SignUpRequestDto.java b/src/main/java/com/somemore/global/auth/sign/up/SignUpRequestDto.java new file mode 100644 index 000000000..34c8f2460 --- /dev/null +++ b/src/main/java/com/somemore/global/auth/sign/up/SignUpRequestDto.java @@ -0,0 +1,23 @@ +package com.somemore.global.auth.sign.up; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; + +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public record SignUpRequestDto( + + @Schema(description = "계정 ID", example = "making") + @NotBlank(message = "계정 ID는 필수 값이며 비어 있을 수 없습니다.") + String accountId, + + @Schema(description = "계정 비밀번호", example = "password") + @NotBlank(message = "계정 비밀번호는 필수 값이며 비어 있을 수 없습니다.") + String accountPassword, + + @Schema(description = "유저 역할", example = "VOLUNTEER", allowableValues = {"VOLUNTEER", "CENTER"}) + @NotBlank(message = "유저 역할은 필수 값이며 비어 있을 수 없습니다.") + String userRole +) { +} \ No newline at end of file diff --git a/src/main/java/com/somemore/global/auth/sign/up/SignUpService.java b/src/main/java/com/somemore/global/auth/sign/up/SignUpService.java new file mode 100644 index 000000000..400f992de --- /dev/null +++ b/src/main/java/com/somemore/global/auth/sign/up/SignUpService.java @@ -0,0 +1,46 @@ +package com.somemore.global.auth.sign.up; + +import com.somemore.center.usecase.RegisterCenterUseCase; +import com.somemore.user.domain.User; +import com.somemore.user.domain.UserRole; +import com.somemore.user.dto.UserAuthInfo; +import com.somemore.user.service.RegisterUserUseCase; +import com.somemore.volunteer.usecase.RegisterVolunteerUseCase; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@RequiredArgsConstructor +@Transactional +public class SignUpService implements SignUpUseCase { + + private final RegisterUserUseCase registerUserUseCase; + private final RegisterVolunteerUseCase registerVolunteerUseCase; + private final RegisterCenterUseCase registerCenterUseCase; + + @Override + public void signUp(SignUpRequestDto signUpRequestDto) { + User user = registerUserUseCase.registerLocalUser( + UserAuthInfo.of(signUpRequestDto.accountId(), signUpRequestDto.accountPassword()), + UserRole.from(signUpRequestDto.userRole())); + + // TODO 회원가입 이벤트 발행으로 변경 (봉사자 혹은 기관 등록) + // 임시 로직 + registerVolunteerOrCenter(user); + } + + private void registerVolunteerOrCenter(User user) { + UUID userId = user.getId(); + UserRole role = user.getRole(); + + if (role == UserRole.VOLUNTEER) { + registerVolunteerUseCase.register(userId); + return; + } + + registerCenterUseCase.register(userId); + } +} diff --git a/src/main/java/com/somemore/global/auth/sign/up/SignUpUseCase.java b/src/main/java/com/somemore/global/auth/sign/up/SignUpUseCase.java new file mode 100644 index 000000000..44e71b39e --- /dev/null +++ b/src/main/java/com/somemore/global/auth/sign/up/SignUpUseCase.java @@ -0,0 +1,6 @@ +package com.somemore.global.auth.sign.up; + +public interface SignUpUseCase { + + void signUp(SignUpRequestDto signUpRequestDto); +} From 4cdbd25fa31870449ddb275a166ef90362b84d17 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, 15 Jan 2025 16:48:27 +0900 Subject: [PATCH 26/34] =?UTF-8?q?feat(user):=20accountId=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20=ED=99=95=EC=9D=B8=20=EA=B8=B0=EB=8A=A5=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/controller/UserQueryController.java | 31 +++++++++++++++++++ .../user/repository/user/UserRepository.java | 2 ++ .../repository/user/UserRepositoryImpl.java | 10 ++++++ .../user/service/UserQueryService.java | 5 +++ .../user/usecase/UserQueryUseCase.java | 6 ++++ 5 files changed, 54 insertions(+) create mode 100644 src/main/java/com/somemore/user/controller/UserQueryController.java diff --git a/src/main/java/com/somemore/user/controller/UserQueryController.java b/src/main/java/com/somemore/user/controller/UserQueryController.java new file mode 100644 index 000000000..e72c2d18f --- /dev/null +++ b/src/main/java/com/somemore/user/controller/UserQueryController.java @@ -0,0 +1,31 @@ +package com.somemore.user.controller; + +import com.somemore.global.common.response.ApiResponse; +import com.somemore.user.usecase.UserQueryUseCase; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "User Query API", description = "유저 조회 관련 API") +@RestController +@Slf4j +@RequiredArgsConstructor +@RequestMapping("/api/user") +public class UserQueryController { + + private final UserQueryUseCase userQueryUseCase; + + @GetMapping("/exists/") + @Operation(summary = "아이디 중복 확인", description = "입력한 아이디가 중복되었는지 확인합니다.") + public ApiResponse checkUserExists( + @RequestParam String accountId + ) { + boolean isAccountIdDuplicate = userQueryUseCase.isDuplicateAccountId(accountId); + return ApiResponse.ok(isAccountIdDuplicate, "중복 조회 완료"); + } +} 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 238ffddb1..a9b6b5a7e 100644 --- a/src/main/java/com/somemore/user/repository/user/UserRepository.java +++ b/src/main/java/com/somemore/user/repository/user/UserRepository.java @@ -15,4 +15,6 @@ public interface UserRepository { Optional findByAccountId(String accountId); User save(User user); + + boolean existsByAccountId(String accountId); } 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 f08d4e3e2..1f56208de 100644 --- a/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java +++ b/src/main/java/com/somemore/user/repository/user/UserRepositoryImpl.java @@ -56,6 +56,16 @@ public User save(User user) { return userJpaRepository.save(user); } + @Override + public boolean existsByAccountId(String accountId) { + return queryFactory.select(user.accountId) + .from(user) + .where( + user.accountId.eq(accountId), + isNotDeleted()) + .fetchFirst() != null; + } + private static BooleanExpression isNotDeleted() { return user.deleted.eq(false); } diff --git a/src/main/java/com/somemore/user/service/UserQueryService.java b/src/main/java/com/somemore/user/service/UserQueryService.java index 9f026c420..2ce9ebf30 100644 --- a/src/main/java/com/somemore/user/service/UserQueryService.java +++ b/src/main/java/com/somemore/user/service/UserQueryService.java @@ -55,4 +55,9 @@ public boolean getIsCustomizedByUserId(UUID userId) { .orElseThrow(() -> new NoSuchElementException(NOT_EXIST_USER)); } + @Override + public boolean isDuplicateAccountId(String accountId) { + return userRepository.existsByAccountId(accountId); + } + } diff --git a/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java b/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java index 75339fab1..f41056b07 100644 --- a/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java +++ b/src/main/java/com/somemore/user/usecase/UserQueryUseCase.java @@ -9,8 +9,14 @@ public interface UserQueryUseCase { User getById(UUID id); + UserRole getRoleById(UUID userId); + User getByAccountId(String accountId); + UserCommonAttribute getCommonAttributeByUserId(UUID userId); + boolean getIsCustomizedByUserId(UUID userId); + + boolean isDuplicateAccountId(String accountId); } From 769ba1bbc963c22d555e239bf65acd9577fa2fee 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, 15 Jan 2025 17:28:13 +0900 Subject: [PATCH 27/34] =?UTF-8?q?fix:=20bean=20name=20conflict=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 --- .../{Center_NEW.java => NEWCenter.java} | 10 +++---- .../repository/CenterJpaRepository.java | 9 ------- .../center/repository/CenterRepository.java | 8 ------ .../repository/CenterRepositoryImpl.java | 19 ------------- .../repository/NEWCenterJpaRepository.java | 11 ++++++++ .../repository/NEWCenterRepository.java | 8 ++++++ .../repository/NEWImplCenterRepository.java | 21 +++++++++++++++ .../service/NEWRegisterCenterService.java | 26 ++++++++++++++++++ .../center/service/RegisterCenterService.java | 24 ----------------- .../usecase/NEWRegisterCenterUseCase.java | 10 +++++++ .../center/usecase/RegisterCenterUseCase.java | 10 ------- .../center/CenterJpaRepository.java | 6 +++++ .../repository/center/CenterRepository.java | 1 - .../center/CenterRepositoryImpl.java | 2 +- .../repository/VolunteerJpaRepository.java | 5 +++- .../repository/VolunteerRepository.java | 6 ++--- .../repository/VolunteerRepositoryImpl.java | 4 ++- .../global/auth/sign/up/SignUpService.java | 12 ++++----- .../{Volunteer_NEW.java => NEWVolunteer.java} | 10 +++---- .../repository/NEWVolunteerJpaRepository.java | 11 ++++++++ .../repository/NEWVolunteerRepository.java | 8 ++++++ .../NEWVolunteerRepositoryImpl.java | 21 +++++++++++++++ .../repository/VolunteerJpaRepository.java | 9 ------- .../repository/VolunteerRepository.java | 8 ------ .../repository/VolunteerRepositoryImpl.java | 19 ------------- .../service/NEWRegisterVolunteerService.java | 27 +++++++++++++++++++ .../service/RegisterVolunteerService.java | 25 ----------------- .../usecase/NEWRegisterVolunteerUseCase.java | 10 +++++++ .../usecase/RegisterVolunteerUseCase.java | 10 ------- ...Test.java => NEWCenterRepositoryTest.java} | 2 +- ... InterestNEWCenterRepositoryImplTest.java} | 2 +- ...t.java => NEWVolunteerRepositoryTest.java} | 2 +- 32 files changed, 189 insertions(+), 167 deletions(-) rename src/main/java/com/somemore/center/domain/{Center_NEW.java => NEWCenter.java} (83%) delete mode 100644 src/main/java/com/somemore/center/repository/CenterJpaRepository.java delete mode 100644 src/main/java/com/somemore/center/repository/CenterRepository.java delete mode 100644 src/main/java/com/somemore/center/repository/CenterRepositoryImpl.java create mode 100644 src/main/java/com/somemore/center/repository/NEWCenterJpaRepository.java create mode 100644 src/main/java/com/somemore/center/repository/NEWCenterRepository.java create mode 100644 src/main/java/com/somemore/center/repository/NEWImplCenterRepository.java create mode 100644 src/main/java/com/somemore/center/service/NEWRegisterCenterService.java delete mode 100644 src/main/java/com/somemore/center/service/RegisterCenterService.java create mode 100644 src/main/java/com/somemore/center/usecase/NEWRegisterCenterUseCase.java delete mode 100644 src/main/java/com/somemore/center/usecase/RegisterCenterUseCase.java rename src/main/java/com/somemore/volunteer/domain/{Volunteer_NEW.java => NEWVolunteer.java} (88%) create mode 100644 src/main/java/com/somemore/volunteer/repository/NEWVolunteerJpaRepository.java create mode 100644 src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java create mode 100644 src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java delete mode 100644 src/main/java/com/somemore/volunteer/repository/VolunteerJpaRepository.java delete mode 100644 src/main/java/com/somemore/volunteer/repository/VolunteerRepository.java delete mode 100644 src/main/java/com/somemore/volunteer/repository/VolunteerRepositoryImpl.java create mode 100644 src/main/java/com/somemore/volunteer/service/NEWRegisterVolunteerService.java delete mode 100644 src/main/java/com/somemore/volunteer/service/RegisterVolunteerService.java create mode 100644 src/main/java/com/somemore/volunteer/usecase/NEWRegisterVolunteerUseCase.java delete mode 100644 src/main/java/com/somemore/volunteer/usecase/RegisterVolunteerUseCase.java rename src/test/java/com/somemore/domains/center/repository/{CenterRepositoryTest.java => NEWCenterRepositoryTest.java} (97%) rename src/test/java/com/somemore/domains/interestcenter/repository/{InterestCenterRepositoryImplTest.java => InterestNEWCenterRepositoryImplTest.java} (94%) rename src/test/java/com/somemore/domains/volunteer/repository/{VolunteerRepositoryTest.java => NEWVolunteerRepositoryTest.java} (99%) diff --git a/src/main/java/com/somemore/center/domain/Center_NEW.java b/src/main/java/com/somemore/center/domain/NEWCenter.java similarity index 83% rename from src/main/java/com/somemore/center/domain/Center_NEW.java rename to src/main/java/com/somemore/center/domain/NEWCenter.java index c07115451..6d411ddce 100644 --- a/src/main/java/com/somemore/center/domain/Center_NEW.java +++ b/src/main/java/com/somemore/center/domain/NEWCenter.java @@ -16,8 +16,8 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "center_new") // TODO suffix 삭제 -public class Center_NEW { +@Table(name = "new_center") // TODO suffix 삭제 +public class NEWCenter { public static final String DEFAULT_NAME = "기관"; @Id @@ -35,14 +35,14 @@ public class Center_NEW { private String homepageUrl; @Builder - private Center_NEW(UUID userId, String name, String homepageUrl) { + private NEWCenter(UUID userId, String name, String homepageUrl) { this.userId = userId; this.name = name; this.homepageUrl = homepageUrl; } - public static Center_NEW createDefault(UUID userId) { - return Center_NEW.builder() + public static NEWCenter createDefault(UUID userId) { + return NEWCenter.builder() .userId(userId) .name(DEFAULT_NAME + userId.toString().substring(0, 8)) .homepageUrl("") diff --git a/src/main/java/com/somemore/center/repository/CenterJpaRepository.java b/src/main/java/com/somemore/center/repository/CenterJpaRepository.java deleted file mode 100644 index 716090178..000000000 --- a/src/main/java/com/somemore/center/repository/CenterJpaRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.somemore.center.repository; - -import com.somemore.center.domain.Center_NEW; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.UUID; - -public interface CenterJpaRepository extends JpaRepository { -} diff --git a/src/main/java/com/somemore/center/repository/CenterRepository.java b/src/main/java/com/somemore/center/repository/CenterRepository.java deleted file mode 100644 index 8a730e903..000000000 --- a/src/main/java/com/somemore/center/repository/CenterRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.somemore.center.repository; - -import com.somemore.center.domain.Center_NEW; - -public interface CenterRepository { - - Center_NEW save(Center_NEW center); -} diff --git a/src/main/java/com/somemore/center/repository/CenterRepositoryImpl.java b/src/main/java/com/somemore/center/repository/CenterRepositoryImpl.java deleted file mode 100644 index b4edf1de6..000000000 --- a/src/main/java/com/somemore/center/repository/CenterRepositoryImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.somemore.center.repository; - -import com.querydsl.jpa.impl.JPAQueryFactory; -import com.somemore.center.domain.Center_NEW; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Repository; - -@Repository -@RequiredArgsConstructor -public class CenterRepositoryImpl implements CenterRepository { - - private final CenterJpaRepository centerJpaRepository; - private final JPAQueryFactory queryFactory; - - @Override - public Center_NEW save(Center_NEW center) { - return centerJpaRepository.save(center); - } -} diff --git a/src/main/java/com/somemore/center/repository/NEWCenterJpaRepository.java b/src/main/java/com/somemore/center/repository/NEWCenterJpaRepository.java new file mode 100644 index 000000000..07a93c4f5 --- /dev/null +++ b/src/main/java/com/somemore/center/repository/NEWCenterJpaRepository.java @@ -0,0 +1,11 @@ +package com.somemore.center.repository; + +import com.somemore.center.domain.NEWCenter; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.UUID; + +@Repository("newCenterJpaRepository") +public interface NEWCenterJpaRepository extends JpaRepository { +} diff --git a/src/main/java/com/somemore/center/repository/NEWCenterRepository.java b/src/main/java/com/somemore/center/repository/NEWCenterRepository.java new file mode 100644 index 000000000..166f93fe8 --- /dev/null +++ b/src/main/java/com/somemore/center/repository/NEWCenterRepository.java @@ -0,0 +1,8 @@ +package com.somemore.center.repository; + +import com.somemore.center.domain.NEWCenter; + +public interface NEWCenterRepository { + + NEWCenter save(NEWCenter center); +} diff --git a/src/main/java/com/somemore/center/repository/NEWImplCenterRepository.java b/src/main/java/com/somemore/center/repository/NEWImplCenterRepository.java new file mode 100644 index 000000000..ff4161662 --- /dev/null +++ b/src/main/java/com/somemore/center/repository/NEWImplCenterRepository.java @@ -0,0 +1,21 @@ +package com.somemore.center.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.somemore.center.domain.NEWCenter; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Repository; + +@Repository("newCenterRepository") +@RequiredArgsConstructor +public class NEWImplCenterRepository implements NEWCenterRepository { + + @Qualifier("newCenterJpaRepository") + private final NEWCenterJpaRepository NEWCenterJpaRepository; + private final JPAQueryFactory queryFactory; + + @Override + public NEWCenter save(NEWCenter center) { + return NEWCenterJpaRepository.save(center); + } +} diff --git a/src/main/java/com/somemore/center/service/NEWRegisterCenterService.java b/src/main/java/com/somemore/center/service/NEWRegisterCenterService.java new file mode 100644 index 000000000..cf43c604d --- /dev/null +++ b/src/main/java/com/somemore/center/service/NEWRegisterCenterService.java @@ -0,0 +1,26 @@ +package com.somemore.center.service; + +import com.somemore.center.domain.NEWCenter; +import com.somemore.center.repository.NEWCenterRepository; +import com.somemore.center.usecase.NEWRegisterCenterUseCase; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@RequiredArgsConstructor +@Transactional +public class NEWRegisterCenterService implements NEWRegisterCenterUseCase { + + @Qualifier("newCenterRepository") + private final NEWCenterRepository NEWCenterRepository; + + @Override + public NEWCenter register(UUID userId) { + NEWCenter center = NEWCenter.createDefault(userId); + return NEWCenterRepository.save(center); + } +} diff --git a/src/main/java/com/somemore/center/service/RegisterCenterService.java b/src/main/java/com/somemore/center/service/RegisterCenterService.java deleted file mode 100644 index 6e1a9652d..000000000 --- a/src/main/java/com/somemore/center/service/RegisterCenterService.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.somemore.center.service; - -import com.somemore.center.domain.Center_NEW; -import com.somemore.center.repository.CenterRepository; -import com.somemore.center.usecase.RegisterCenterUseCase; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.UUID; - -@Service -@RequiredArgsConstructor -@Transactional -public class RegisterCenterService implements RegisterCenterUseCase { - - private final CenterRepository centerRepository; - - @Override - public Center_NEW register(UUID userId) { - Center_NEW center = Center_NEW.createDefault(userId); - return centerRepository.save(center); - } -} diff --git a/src/main/java/com/somemore/center/usecase/NEWRegisterCenterUseCase.java b/src/main/java/com/somemore/center/usecase/NEWRegisterCenterUseCase.java new file mode 100644 index 000000000..b56a8a1ee --- /dev/null +++ b/src/main/java/com/somemore/center/usecase/NEWRegisterCenterUseCase.java @@ -0,0 +1,10 @@ +package com.somemore.center.usecase; + +import com.somemore.center.domain.NEWCenter; + +import java.util.UUID; + +public interface NEWRegisterCenterUseCase { + + NEWCenter register(UUID userId); +} diff --git a/src/main/java/com/somemore/center/usecase/RegisterCenterUseCase.java b/src/main/java/com/somemore/center/usecase/RegisterCenterUseCase.java deleted file mode 100644 index 7e7eb5b7b..000000000 --- a/src/main/java/com/somemore/center/usecase/RegisterCenterUseCase.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.somemore.center.usecase; - -import com.somemore.center.domain.Center_NEW; - -import java.util.UUID; - -public interface RegisterCenterUseCase { - - Center_NEW register(UUID userId); -} diff --git a/src/main/java/com/somemore/domains/center/repository/center/CenterJpaRepository.java b/src/main/java/com/somemore/domains/center/repository/center/CenterJpaRepository.java index ef68ed2ea..0a0f7df70 100644 --- a/src/main/java/com/somemore/domains/center/repository/center/CenterJpaRepository.java +++ b/src/main/java/com/somemore/domains/center/repository/center/CenterJpaRepository.java @@ -2,13 +2,19 @@ import com.somemore.domains.center.domain.Center; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; import java.util.Optional; import java.util.UUID; +@Repository("centerJpaRepository") public interface CenterJpaRepository extends JpaRepository { + boolean existsById(UUID id); + Optional
findCenterById(UUID id); + Optional
findByName(String name); + boolean existsByIdAndDeletedIsFalse(UUID id); } diff --git a/src/main/java/com/somemore/domains/center/repository/center/CenterRepository.java b/src/main/java/com/somemore/domains/center/repository/center/CenterRepository.java index 9cffc8d5a..9fe091776 100644 --- a/src/main/java/com/somemore/domains/center/repository/center/CenterRepository.java +++ b/src/main/java/com/somemore/domains/center/repository/center/CenterRepository.java @@ -8,7 +8,6 @@ import java.util.Optional; import java.util.UUID; -@Repository public interface CenterRepository { Center save(Center center); boolean existsById(UUID id); diff --git a/src/main/java/com/somemore/domains/center/repository/center/CenterRepositoryImpl.java b/src/main/java/com/somemore/domains/center/repository/center/CenterRepositoryImpl.java index f398c15e9..99698f066 100644 --- a/src/main/java/com/somemore/domains/center/repository/center/CenterRepositoryImpl.java +++ b/src/main/java/com/somemore/domains/center/repository/center/CenterRepositoryImpl.java @@ -14,7 +14,7 @@ import java.util.UUID; @RequiredArgsConstructor -@Repository +@Repository("centerRepository") public class CenterRepositoryImpl implements CenterRepository { private final JPAQueryFactory queryFactory; diff --git a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerJpaRepository.java b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerJpaRepository.java index 621a9b503..d35bc9c08 100644 --- a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerJpaRepository.java +++ b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerJpaRepository.java @@ -1,13 +1,16 @@ package com.somemore.domains.volunteer.repository; import com.somemore.domains.volunteer.domain.Volunteer; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; import java.util.List; import java.util.UUID; -import org.springframework.data.jpa.repository.JpaRepository; +@Repository("oldVolunteerJpaRepository") public interface VolunteerJpaRepository extends JpaRepository { List findAllByIdInAndDeletedFalse(List ids); + boolean existsByIdAndDeletedIsFalse(UUID id); } diff --git a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepository.java b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepository.java index ee6ac42a8..35b7e24b4 100644 --- a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepository.java +++ b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepository.java @@ -7,9 +7,7 @@ import java.util.List; import java.util.Optional; import java.util.UUID; -import org.springframework.stereotype.Repository; -@Repository public interface VolunteerRepository { Volunteer save(Volunteer volunteer); @@ -30,5 +28,7 @@ public interface VolunteerRepository { boolean existsByVolunteerId(UUID volunteerId); - default boolean doesNotExistsByVolunteerId(UUID volunteerId) { return !existsByVolunteerId(volunteerId); } + default boolean doesNotExistsByVolunteerId(UUID volunteerId) { + return !existsByVolunteerId(volunteerId); + } } diff --git a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImpl.java b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImpl.java index a7a301f06..744c8f2b7 100644 --- a/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImpl.java +++ b/src/main/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImpl.java @@ -14,12 +14,14 @@ import java.util.Optional; import java.util.UUID; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; @RequiredArgsConstructor -@Repository +@Repository("oldVolunteerRepository") public class VolunteerRepositoryImpl implements VolunteerRepository { + @Qualifier("oldVolunteerJpaRepository") private final VolunteerJpaRepository volunteerJpaRepository; private final JPAQueryFactory queryFactory; diff --git a/src/main/java/com/somemore/global/auth/sign/up/SignUpService.java b/src/main/java/com/somemore/global/auth/sign/up/SignUpService.java index 400f992de..335fbf3c2 100644 --- a/src/main/java/com/somemore/global/auth/sign/up/SignUpService.java +++ b/src/main/java/com/somemore/global/auth/sign/up/SignUpService.java @@ -1,11 +1,11 @@ package com.somemore.global.auth.sign.up; -import com.somemore.center.usecase.RegisterCenterUseCase; +import com.somemore.center.usecase.NEWRegisterCenterUseCase; import com.somemore.user.domain.User; import com.somemore.user.domain.UserRole; import com.somemore.user.dto.UserAuthInfo; import com.somemore.user.service.RegisterUserUseCase; -import com.somemore.volunteer.usecase.RegisterVolunteerUseCase; +import com.somemore.volunteer.usecase.NEWRegisterVolunteerUseCase; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -18,8 +18,8 @@ public class SignUpService implements SignUpUseCase { private final RegisterUserUseCase registerUserUseCase; - private final RegisterVolunteerUseCase registerVolunteerUseCase; - private final RegisterCenterUseCase registerCenterUseCase; + private final NEWRegisterVolunteerUseCase NEWRegisterVolunteerUseCase; + private final NEWRegisterCenterUseCase NEWRegisterCenterUseCase; @Override public void signUp(SignUpRequestDto signUpRequestDto) { @@ -37,10 +37,10 @@ private void registerVolunteerOrCenter(User user) { UserRole role = user.getRole(); if (role == UserRole.VOLUNTEER) { - registerVolunteerUseCase.register(userId); + NEWRegisterVolunteerUseCase.register(userId); return; } - registerCenterUseCase.register(userId); + NEWRegisterCenterUseCase.register(userId); } } diff --git a/src/main/java/com/somemore/volunteer/domain/Volunteer_NEW.java b/src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java similarity index 88% rename from src/main/java/com/somemore/volunteer/domain/Volunteer_NEW.java rename to src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java index 60a2a41bd..fdb2ac139 100644 --- a/src/main/java/com/somemore/volunteer/domain/Volunteer_NEW.java +++ b/src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java @@ -21,8 +21,8 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "volunteer_new") // TODO suffix 삭제 -public class Volunteer_NEW extends BaseEntity { +@Table(name = "new_volunteer") // TODO suffix 삭제 +public class NEWVolunteer extends BaseEntity { public static final String DEFAULT_NAME = "봉사자"; @Id @@ -45,7 +45,7 @@ public class Volunteer_NEW extends BaseEntity { private Tier tier; @Builder - private Volunteer_NEW( + private NEWVolunteer( UUID userId, String name, Gender gender, @@ -57,8 +57,8 @@ private Volunteer_NEW( this.tier = tier; } - public static Volunteer_NEW createDefault(UUID userId) { - return Volunteer_NEW.builder() + public static NEWVolunteer createDefault(UUID userId) { + return NEWVolunteer.builder() .userId(userId) .name(DEFAULT_NAME + userId.toString().substring(0, 8)) .gender(Gender.getDefault()) diff --git a/src/main/java/com/somemore/volunteer/repository/NEWVolunteerJpaRepository.java b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerJpaRepository.java new file mode 100644 index 000000000..b5f5ae4ad --- /dev/null +++ b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerJpaRepository.java @@ -0,0 +1,11 @@ +package com.somemore.volunteer.repository; + +import com.somemore.volunteer.domain.NEWVolunteer; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.UUID; + +@Repository("newVolunteerJpaRepository") +public interface NEWVolunteerJpaRepository extends JpaRepository { +} diff --git a/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java new file mode 100644 index 000000000..1c3a7b0f6 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java @@ -0,0 +1,8 @@ +package com.somemore.volunteer.repository; + +import com.somemore.volunteer.domain.NEWVolunteer; + +public interface NEWVolunteerRepository { + + NEWVolunteer save(NEWVolunteer volunteer); +} diff --git a/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java new file mode 100644 index 000000000..ffc5d65c4 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java @@ -0,0 +1,21 @@ +package com.somemore.volunteer.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.somemore.volunteer.domain.NEWVolunteer; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Repository; + +@Repository("newVolunteerRepository") +@RequiredArgsConstructor +public class NEWVolunteerRepositoryImpl implements NEWVolunteerRepository { + + @Qualifier("newVolunteerJpaRepository") + private final NEWVolunteerJpaRepository NEWVolunteerJpaRepository; + private final JPAQueryFactory queryFactory; + + @Override + public NEWVolunteer save(NEWVolunteer volunteer) { + return NEWVolunteerJpaRepository.save(volunteer); + } +} diff --git a/src/main/java/com/somemore/volunteer/repository/VolunteerJpaRepository.java b/src/main/java/com/somemore/volunteer/repository/VolunteerJpaRepository.java deleted file mode 100644 index 994bf0884..000000000 --- a/src/main/java/com/somemore/volunteer/repository/VolunteerJpaRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.somemore.volunteer.repository; - -import com.somemore.volunteer.domain.Volunteer_NEW; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.UUID; - -public interface VolunteerJpaRepository extends JpaRepository { -} diff --git a/src/main/java/com/somemore/volunteer/repository/VolunteerRepository.java b/src/main/java/com/somemore/volunteer/repository/VolunteerRepository.java deleted file mode 100644 index 27066a6f5..000000000 --- a/src/main/java/com/somemore/volunteer/repository/VolunteerRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.somemore.volunteer.repository; - -import com.somemore.volunteer.domain.Volunteer_NEW; - -public interface VolunteerRepository { - - Volunteer_NEW save(Volunteer_NEW volunteer); -} diff --git a/src/main/java/com/somemore/volunteer/repository/VolunteerRepositoryImpl.java b/src/main/java/com/somemore/volunteer/repository/VolunteerRepositoryImpl.java deleted file mode 100644 index e1abcde5b..000000000 --- a/src/main/java/com/somemore/volunteer/repository/VolunteerRepositoryImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.somemore.volunteer.repository; - -import com.querydsl.jpa.impl.JPAQueryFactory; -import com.somemore.volunteer.domain.Volunteer_NEW; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Repository; - -@Repository -@RequiredArgsConstructor -public class VolunteerRepositoryImpl implements VolunteerRepository { - - private final VolunteerJpaRepository volunteerJpaRepository; - private final JPAQueryFactory queryFactory; - - @Override - public Volunteer_NEW save(Volunteer_NEW volunteer) { - return volunteerJpaRepository.save(volunteer); - } -} diff --git a/src/main/java/com/somemore/volunteer/service/NEWRegisterVolunteerService.java b/src/main/java/com/somemore/volunteer/service/NEWRegisterVolunteerService.java new file mode 100644 index 000000000..b2c5fa32d --- /dev/null +++ b/src/main/java/com/somemore/volunteer/service/NEWRegisterVolunteerService.java @@ -0,0 +1,27 @@ +package com.somemore.volunteer.service; + +import com.somemore.volunteer.domain.NEWVolunteer; +import com.somemore.volunteer.repository.NEWVolunteerRepository; +import com.somemore.volunteer.usecase.NEWRegisterVolunteerUseCase; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.UUID; + +@Service +@RequiredArgsConstructor +@Transactional +public class NEWRegisterVolunteerService implements NEWRegisterVolunteerUseCase { + + @Qualifier("newVolunteerRepository") + private final NEWVolunteerRepository NEWVolunteerRepository; + + @Override + public NEWVolunteer register(UUID userId) { + NEWVolunteer volunteer = NEWVolunteer.createDefault(userId); + + return NEWVolunteerRepository.save(volunteer); + } +} diff --git a/src/main/java/com/somemore/volunteer/service/RegisterVolunteerService.java b/src/main/java/com/somemore/volunteer/service/RegisterVolunteerService.java deleted file mode 100644 index 85c30f8e1..000000000 --- a/src/main/java/com/somemore/volunteer/service/RegisterVolunteerService.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.somemore.volunteer.service; - -import com.somemore.volunteer.domain.Volunteer_NEW; -import com.somemore.volunteer.repository.VolunteerRepository; -import com.somemore.volunteer.usecase.RegisterVolunteerUseCase; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.UUID; - -@Service -@RequiredArgsConstructor -@Transactional -public class RegisterVolunteerService implements RegisterVolunteerUseCase { - - private final VolunteerRepository volunteerRepository; - - @Override - public Volunteer_NEW register(UUID userId) { - Volunteer_NEW volunteer = Volunteer_NEW.createDefault(userId); - - return volunteerRepository.save(volunteer); - } -} diff --git a/src/main/java/com/somemore/volunteer/usecase/NEWRegisterVolunteerUseCase.java b/src/main/java/com/somemore/volunteer/usecase/NEWRegisterVolunteerUseCase.java new file mode 100644 index 000000000..ac7a842f9 --- /dev/null +++ b/src/main/java/com/somemore/volunteer/usecase/NEWRegisterVolunteerUseCase.java @@ -0,0 +1,10 @@ +package com.somemore.volunteer.usecase; + +import com.somemore.volunteer.domain.NEWVolunteer; + +import java.util.UUID; + +public interface NEWRegisterVolunteerUseCase { + + NEWVolunteer register(UUID userId); +} diff --git a/src/main/java/com/somemore/volunteer/usecase/RegisterVolunteerUseCase.java b/src/main/java/com/somemore/volunteer/usecase/RegisterVolunteerUseCase.java deleted file mode 100644 index 4c82f07e0..000000000 --- a/src/main/java/com/somemore/volunteer/usecase/RegisterVolunteerUseCase.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.somemore.volunteer.usecase; - -import com.somemore.volunteer.domain.Volunteer_NEW; - -import java.util.UUID; - -public interface RegisterVolunteerUseCase { - - Volunteer_NEW register(UUID userId); -} diff --git a/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java b/src/test/java/com/somemore/domains/center/repository/NEWCenterRepositoryTest.java similarity index 97% rename from src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java rename to src/test/java/com/somemore/domains/center/repository/NEWCenterRepositoryTest.java index 5bc879a2b..8657240ac 100644 --- a/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java +++ b/src/test/java/com/somemore/domains/center/repository/NEWCenterRepositoryTest.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @Transactional -class CenterRepositoryTest extends IntegrationTestSupport { +class NEWCenterRepositoryTest extends IntegrationTestSupport { @Autowired private CenterRepository centerRepository; diff --git a/src/test/java/com/somemore/domains/interestcenter/repository/InterestCenterRepositoryImplTest.java b/src/test/java/com/somemore/domains/interestcenter/repository/InterestNEWCenterRepositoryImplTest.java similarity index 94% rename from src/test/java/com/somemore/domains/interestcenter/repository/InterestCenterRepositoryImplTest.java rename to src/test/java/com/somemore/domains/interestcenter/repository/InterestNEWCenterRepositoryImplTest.java index 9b38dbaac..bc139697a 100644 --- a/src/test/java/com/somemore/domains/interestcenter/repository/InterestCenterRepositoryImplTest.java +++ b/src/test/java/com/somemore/domains/interestcenter/repository/InterestNEWCenterRepositoryImplTest.java @@ -13,7 +13,7 @@ import static org.assertj.core.api.Assertions.assertThat; @Transactional -class InterestCenterRepositoryImplTest extends IntegrationTestSupport { +class InterestNEWCenterRepositoryImplTest extends IntegrationTestSupport { @Autowired private InterestCenterRepository interestCenterRepository; diff --git a/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryTest.java b/src/test/java/com/somemore/domains/volunteer/repository/NEWVolunteerRepositoryTest.java similarity index 99% rename from src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryTest.java rename to src/test/java/com/somemore/domains/volunteer/repository/NEWVolunteerRepositoryTest.java index f68277087..6899cbf45 100644 --- a/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryTest.java +++ b/src/test/java/com/somemore/domains/volunteer/repository/NEWVolunteerRepositoryTest.java @@ -22,7 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat; @Transactional -class VolunteerRepositoryTest extends IntegrationTestSupport { +class NEWVolunteerRepositoryTest extends IntegrationTestSupport { @Autowired private VolunteerRepository volunteerRepository; From e22155496ccba6631beabcba3eaf206c9b110d6e 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, 15 Jan 2025 18:08:21 +0900 Subject: [PATCH 28/34] =?UTF-8?q?fix:=20rollback=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0,=20=ED=85=8C=EC=8A=A4=ED=8A=B8=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 --- .../old/VolunteerJpaRepository.java | 13 --- .../repository/old/VolunteerRepository.java | 33 ------ .../old/VolunteerRepositoryImpl.java | 110 ------------------ .../service/RegisterVolunteerService.java | 2 +- .../service/UpdateVolunteerLockService.java | 2 +- .../UpdateVolunteerProfileService.java | 2 +- ...oryTest.java => CenterRepositoryTest.java} | 2 +- .../CommunityBoardRepositoryTest.java | 2 +- .../CommunityCommentRepositoryTest.java | 2 +- .../board/CommunityBoardQueryServiceTest.java | 2 +- .../CommunityCommentQueryServiceTest.java | 2 +- .../repository/NoteRepositoryImplTest.java | 2 +- .../note/service/NoteQueryServiceTest.java | 2 +- .../SendNoteToVolunteerServiceTest.java | 2 +- .../repository/ReviewRepositoryImplTest.java | 2 +- .../service/ReviewQueryServiceTest.java | 2 +- .../VolunteerDetailRepositoryImplTest.java | 3 +- ....java => VolunteerRepositoryImplTest.java} | 9 +- .../service/RegisterVolunteerServiceTest.java | 74 ++++++++++++ .../UpdateVolunteerLockServiceTest.java | 2 +- .../UpdateVolunteerProfileServiceTest.java | 2 +- ...SettleVolunteerApplyFacadeServiceTest.java | 2 +- 22 files changed, 97 insertions(+), 177 deletions(-) delete mode 100644 src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerJpaRepository.java delete mode 100644 src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepository.java delete mode 100644 src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepositoryImpl.java rename src/test/java/com/somemore/domains/center/repository/{NEWCenterRepositoryTest.java => CenterRepositoryTest.java} (97%) rename src/test/java/com/somemore/domains/volunteer/repository/{NEWVolunteerRepositoryTest.java => VolunteerRepositoryImplTest.java} (95%) create mode 100644 src/test/java/com/somemore/domains/volunteer/service/RegisterVolunteerServiceTest.java diff --git a/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerJpaRepository.java b/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerJpaRepository.java deleted file mode 100644 index 408f2b835..000000000 --- a/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerJpaRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.somemore.domains.volunteer.repository.old; - -import com.somemore.domains.volunteer.domain.Volunteer; - -import java.util.List; -import java.util.UUID; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface VolunteerJpaRepository extends JpaRepository { - - List findAllByIdInAndDeletedFalse(List ids); - boolean existsByIdAndDeletedIsFalse(UUID id); -} diff --git a/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepository.java b/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepository.java deleted file mode 100644 index cc6622b2f..000000000 --- a/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepository.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.somemore.domains.volunteer.repository.old; - -import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.mapper.VolunteerOverviewForRankingByHours; -import org.springframework.stereotype.Repository; - -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -@Repository -public interface VolunteerRepository { - - Volunteer save(Volunteer volunteer); - - Optional findById(UUID id); - - Optional findByOauthId(String oauthId); - - String findNicknameById(UUID id); - - List findRankingByVolunteerHours(); - - void deleteAllInBatch(); - - List findAllByIds(List volunteerIds); - - boolean existsByVolunteerId(UUID volunteerId); - - default boolean doesNotExistsByVolunteerId(UUID volunteerId) { - return !existsByVolunteerId(volunteerId); - } -} diff --git a/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepositoryImpl.java b/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepositoryImpl.java deleted file mode 100644 index e10ad713c..000000000 --- a/src/main/java/com/somemore/domains/volunteer/repository/old/VolunteerRepositoryImpl.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.somemore.domains.volunteer.repository.old; - -import com.querydsl.core.types.Path; -import com.querydsl.core.types.Projections; -import com.querydsl.core.types.dsl.BooleanExpression; -import com.querydsl.jpa.impl.JPAQueryFactory; -import com.somemore.domains.volunteer.domain.QVolunteer; -import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.mapper.VolunteerOverviewForRankingByHours; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Repository; - -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -@RequiredArgsConstructor -@Repository -public class VolunteerRepositoryImpl implements VolunteerRepository { - - private final VolunteerJpaRepository volunteerJpaRepository; - private final JPAQueryFactory queryFactory; - - private static final QVolunteer volunteer = QVolunteer.volunteer; - - @Override - public Volunteer save(Volunteer volunteer) { - return volunteerJpaRepository.save(volunteer); - } - - @Override - public Optional findById(UUID id) { - return findOne(volunteer.id.eq(id)); - } - - @Override - public Optional findByOauthId(String oauthId) { - return findOne(volunteer.oauthId.eq(oauthId)); - } - - @Override - public String findNicknameById(UUID id) { - return findDynamicField(id, volunteer.nickname) - .orElse(null); - } - - @Override - public List findRankingByVolunteerHours() { - return queryFactory - .select(Projections.constructor(VolunteerOverviewForRankingByHours.class, - volunteer.id, - volunteer.nickname, - volunteer.imgUrl, - volunteer.introduce, - volunteer.tier, - volunteer.totalVolunteerHours - )) - .from(volunteer) - .where(isNotDeleted()) - .orderBy(volunteer.totalVolunteerHours.desc()) - .limit(4) - .fetch(); - } - - @Override - public void deleteAllInBatch() { - volunteerJpaRepository.deleteAllInBatch(); - } - - @Override - public List findAllByIds(List volunteerIds) { - return volunteerJpaRepository.findAllByIdInAndDeletedFalse(volunteerIds); - } - - private Optional findOne(BooleanExpression condition) { - - return Optional.ofNullable( - queryFactory - .selectFrom(volunteer) - .where( - condition, - isNotDeleted() - ) - .fetchOne() - ); - } - - private Optional findDynamicField(UUID id, Path field) { - - return Optional.ofNullable( - queryFactory - .select(field) - .from(volunteer) - .where( - volunteer.id.eq(id), - isNotDeleted() - ) - .fetchOne() - ); - } - - @Override - public boolean existsByVolunteerId(UUID volunteerId) { - return volunteerJpaRepository.existsByIdAndDeletedIsFalse(volunteerId); - } - - private BooleanExpression isNotDeleted() { - return volunteer.deleted.isFalse(); - } -} diff --git a/src/main/java/com/somemore/domains/volunteer/service/RegisterVolunteerService.java b/src/main/java/com/somemore/domains/volunteer/service/RegisterVolunteerService.java index 406b91606..587a6d33d 100644 --- a/src/main/java/com/somemore/domains/volunteer/service/RegisterVolunteerService.java +++ b/src/main/java/com/somemore/domains/volunteer/service/RegisterVolunteerService.java @@ -4,7 +4,7 @@ import com.somemore.domains.volunteer.domain.VolunteerDetail; import com.somemore.domains.volunteer.dto.request.VolunteerRegisterRequestDto; import com.somemore.domains.volunteer.repository.VolunteerDetailRepository; -import com.somemore.domains.volunteer.repository.old.VolunteerRepository; +import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.domains.volunteer.usecase.RegisterVolunteerUseCase; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockService.java b/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockService.java index 039cee980..33d130b4e 100644 --- a/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockService.java +++ b/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockService.java @@ -5,7 +5,7 @@ import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.usecase.UpdateVolunteerUseCase; import com.somemore.global.exception.BadRequestException; -import com.somemore.domains.volunteer.repository.old.VolunteerRepository; +import com.somemore.domains.volunteer.repository.VolunteerRepository; import java.util.UUID; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileService.java b/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileService.java index 7a56fe428..591e294e7 100644 --- a/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileService.java +++ b/src/main/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileService.java @@ -1,9 +1,9 @@ package com.somemore.domains.volunteer.service; import com.somemore.domains.volunteer.domain.Volunteer; +import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.global.exception.BadRequestException; import com.somemore.domains.volunteer.dto.request.VolunteerProfileUpdateRequestDto; -import com.somemore.domains.volunteer.repository.old.VolunteerRepository; import com.somemore.domains.volunteer.usecase.UpdateVolunteerProfileUseCase; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/test/java/com/somemore/domains/center/repository/NEWCenterRepositoryTest.java b/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java similarity index 97% rename from src/test/java/com/somemore/domains/center/repository/NEWCenterRepositoryTest.java rename to src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java index 8657240ac..5bc879a2b 100644 --- a/src/test/java/com/somemore/domains/center/repository/NEWCenterRepositoryTest.java +++ b/src/test/java/com/somemore/domains/center/repository/CenterRepositoryTest.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @Transactional -class NEWCenterRepositoryTest extends IntegrationTestSupport { +class CenterRepositoryTest extends IntegrationTestSupport { @Autowired private CenterRepository centerRepository; 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 cc5467217..ca635bcb0 100644 --- a/src/test/java/com/somemore/domains/community/repository/CommunityBoardRepositoryTest.java +++ b/src/test/java/com/somemore/domains/community/repository/CommunityBoardRepositoryTest.java @@ -4,7 +4,7 @@ import com.somemore.domains.community.repository.board.CommunityBoardRepository; import com.somemore.domains.community.repository.mapper.CommunityBoardView; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.old.VolunteerRepository; +import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.BeforeEach; 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 dfe176094..ca36b22a9 100644 --- a/src/test/java/com/somemore/domains/community/repository/CommunityCommentRepositoryTest.java +++ b/src/test/java/com/somemore/domains/community/repository/CommunityCommentRepositoryTest.java @@ -6,7 +6,7 @@ import com.somemore.domains.community.repository.comment.CommunityCommentRepository; import com.somemore.domains.community.repository.mapper.CommunityCommentView; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.old.VolunteerRepository; +import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.BeforeEach; 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 c7707fbc0..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 @@ -8,7 +8,7 @@ import com.somemore.domains.community.usecase.board.CreateCommunityBoardUseCase; import com.somemore.domains.community.usecase.board.DeleteCommunityBoardUseCase; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.old.VolunteerRepository; +import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.global.exception.BadRequestException; import com.somemore.global.exception.ExceptionMessage; 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 d3b0a0e4e..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 @@ -7,7 +7,7 @@ import com.somemore.domains.community.repository.comment.CommunityCommentRepository; import com.somemore.domains.community.usecase.comment.DeleteCommunityCommentUseCase; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.old.VolunteerRepository; +import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.global.auth.oauth.domain.OAuthProvider; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.AfterEach; 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 a5bbba34c..6a1085d2c 100644 --- a/src/test/java/com/somemore/domains/note/repository/NoteRepositoryImplTest.java +++ b/src/test/java/com/somemore/domains/note/repository/NoteRepositoryImplTest.java @@ -8,7 +8,7 @@ import com.somemore.domains.note.repository.mapper.NoteReceiverViewForCenter; import com.somemore.domains.note.repository.mapper.NoteReceiverViewForVolunteer; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.old.VolunteerJpaRepository; +import com.somemore.domains.volunteer.repository.VolunteerJpaRepository; 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/note/service/NoteQueryServiceTest.java b/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java index 8e743841e..059d42bea 100644 --- a/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/note/service/NoteQueryServiceTest.java @@ -9,7 +9,7 @@ import com.somemore.domains.note.repository.mapper.NoteReceiverViewForCenter; import com.somemore.domains.note.repository.mapper.NoteReceiverViewForVolunteer; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.old.VolunteerJpaRepository; +import com.somemore.domains.volunteer.repository.VolunteerJpaRepository; import com.somemore.global.exception.NoSuchElementException; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.DisplayName; 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 fb2ed8c42..514e4d6c6 100644 --- a/src/test/java/com/somemore/domains/note/service/SendNoteToVolunteerServiceTest.java +++ b/src/test/java/com/somemore/domains/note/service/SendNoteToVolunteerServiceTest.java @@ -4,7 +4,7 @@ import com.somemore.domains.note.dto.SendNoteToVolunteerRequestDto; import com.somemore.domains.note.repository.NoteJpaRepository; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.old.VolunteerJpaRepository; +import com.somemore.domains.volunteer.repository.VolunteerJpaRepository; 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/review/repository/ReviewRepositoryImplTest.java b/src/test/java/com/somemore/domains/review/repository/ReviewRepositoryImplTest.java index c30ab81cd..2882fc1d1 100644 --- a/src/test/java/com/somemore/domains/review/repository/ReviewRepositoryImplTest.java +++ b/src/test/java/com/somemore/domains/review/repository/ReviewRepositoryImplTest.java @@ -8,7 +8,7 @@ import com.somemore.domains.review.domain.Review; import com.somemore.domains.review.dto.condition.ReviewSearchCondition; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.old.VolunteerRepository; +import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository; import com.somemore.support.IntegrationTestSupport; 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 6696b0b4b..b63212956 100644 --- a/src/test/java/com/somemore/domains/review/service/ReviewQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/review/service/ReviewQueryServiceTest.java @@ -11,7 +11,7 @@ import com.somemore.domains.review.dto.response.ReviewDetailWithNicknameResponseDto; import com.somemore.domains.review.repository.ReviewRepository; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.old.VolunteerRepository; +import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository; import com.somemore.global.exception.NoSuchElementException; diff --git a/src/test/java/com/somemore/domains/volunteer/repository/VolunteerDetailRepositoryImplTest.java b/src/test/java/com/somemore/domains/volunteer/repository/VolunteerDetailRepositoryImplTest.java index a98ad50eb..e26e63492 100644 --- a/src/test/java/com/somemore/domains/volunteer/repository/VolunteerDetailRepositoryImplTest.java +++ b/src/test/java/com/somemore/domains/volunteer/repository/VolunteerDetailRepositoryImplTest.java @@ -2,6 +2,7 @@ import com.somemore.domains.volunteer.domain.Gender; import com.somemore.domains.volunteer.domain.VolunteerDetail; +import com.somemore.domains.volunteer.repository.VolunteerDetailRepository; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -14,7 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat; @Transactional -class VolunteerDetailRepositoryTest extends IntegrationTestSupport { +class VolunteerDetailRepositoryImplTest extends IntegrationTestSupport { @Autowired private VolunteerDetailRepository volunteerDetailRepository; diff --git a/src/test/java/com/somemore/domains/volunteer/repository/NEWVolunteerRepositoryTest.java b/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImplTest.java similarity index 95% rename from src/test/java/com/somemore/domains/volunteer/repository/NEWVolunteerRepositoryTest.java rename to src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImplTest.java index 6899cbf45..831d369c6 100644 --- a/src/test/java/com/somemore/domains/volunteer/repository/NEWVolunteerRepositoryTest.java +++ b/src/test/java/com/somemore/domains/volunteer/repository/VolunteerRepositoryImplTest.java @@ -3,6 +3,7 @@ import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.domain.VolunteerDetail; import com.somemore.domains.volunteer.dto.request.VolunteerRegisterRequestDto; +import com.somemore.domains.volunteer.repository.VolunteerDetailRepository; import com.somemore.domains.volunteer.repository.mapper.VolunteerOverviewForRankingByHours; import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; import com.somemore.support.IntegrationTestSupport; @@ -22,7 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat; @Transactional -class NEWVolunteerRepositoryTest extends IntegrationTestSupport { +class VolunteerRepositoryImplTest extends IntegrationTestSupport { @Autowired private VolunteerRepository volunteerRepository; @@ -210,9 +211,9 @@ void notExistsVolunteerById() { } private void createVolunteerAndUpdateVolunteerStats(int i) { - Volunteer newVolunteer = Volunteer.createDefault(NAVER, "oauth-id-" + i); - newVolunteer.updateVolunteerStats(i * 10, i); - volunteerRepository.save(newVolunteer); + Volunteer Volunteer = com.somemore.domains.volunteer.domain.Volunteer.createDefault(NAVER, "oauth-id-" + i); + Volunteer.updateVolunteerStats(i * 10, i); + volunteerRepository.save(Volunteer); } private static VolunteerRegisterRequestDto createVolunteerRegisterRequestDto(String name) { diff --git a/src/test/java/com/somemore/domains/volunteer/service/RegisterVolunteerServiceTest.java b/src/test/java/com/somemore/domains/volunteer/service/RegisterVolunteerServiceTest.java new file mode 100644 index 000000000..148f75022 --- /dev/null +++ b/src/test/java/com/somemore/domains/volunteer/service/RegisterVolunteerServiceTest.java @@ -0,0 +1,74 @@ +package com.somemore.domains.volunteer.service; + +import com.somemore.domains.volunteer.domain.Gender; +import com.somemore.domains.volunteer.domain.Tier; +import com.somemore.domains.volunteer.domain.Volunteer; +import com.somemore.domains.volunteer.domain.VolunteerDetail; +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.domain.OAuthProvider; +import com.somemore.support.IntegrationTestSupport; +import jakarta.persistence.EntityNotFoundException; +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 RegisterVolunteerServiceTest extends IntegrationTestSupport { + + @Autowired + private RegisterVolunteerService registerVolunteerService; + + @Autowired + private VolunteerRepository volunteerRepository; + + @Autowired + private VolunteerDetailRepository volunteerDetailRepository; + + @DisplayName("봉사자와 상세 정보를 저장한다") + @Test + void registerVolunteer() { + // given + VolunteerRegisterRequestDto dto = new VolunteerRegisterRequestDto( + OAuthProvider.NAVER, + "oauth-id-example", + "making", + "making@example.com", + "M", + "06-08", + "1998", + "010-1234-5678" + ); + + // when + registerVolunteerService.registerVolunteer(dto); + + // then + Volunteer volunteer = volunteerRepository.findByOauthId("oauth-id-example") + .orElseThrow(EntityNotFoundException::new); + VolunteerDetail volunteerDetail = volunteerDetailRepository.findByVolunteerId(volunteer.getId()) + .orElseThrow(EntityNotFoundException::new); + + // Volunteer + assertThat(volunteer.getOauthProvider()).isEqualTo(OAuthProvider.NAVER); + assertThat(volunteer.getOauthId()).isEqualTo("oauth-id-example"); + assertThat(volunteer.getNickname()).hasSize(8); // 8자리 default UUID + assertThat(volunteer.getImgUrl()).isEqualTo(""); // default + assertThat(volunteer.getIntroduce()).isEqualTo(""); // default + assertThat(volunteer.getTier()).isEqualTo(Tier.RED); // default + assertThat(volunteer.getTotalVolunteerHours()).isEqualTo(0); // default + assertThat(volunteer.getTotalVolunteerCount()).isEqualTo(0); // default + + // VolunteerDetail + assertThat(volunteerDetail.getVolunteerId()).isEqualTo(volunteer.getId()); + assertThat(volunteerDetail.getName()).isEqualTo("making"); + assertThat(volunteerDetail.getEmail()).isEqualTo("making@example.com"); + assertThat(volunteerDetail.getGender()).isEqualTo(Gender.MALE); + assertThat(volunteerDetail.getBirthDate()).isEqualTo("1998-06-08"); + assertThat(volunteerDetail.getContactNumber()).isEqualTo("010-1234-5678"); + } +} 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 1135ece68..00aaa82b4 100644 --- a/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerLockServiceTest.java @@ -1,7 +1,7 @@ package com.somemore.domains.volunteer.service; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.old.VolunteerRepository; +import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.support.IntegrationTestSupport; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; 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 0112ccbdf..a5492dee3 100644 --- a/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteer/service/UpdateVolunteerProfileServiceTest.java @@ -2,7 +2,7 @@ import com.somemore.domains.volunteer.domain.Volunteer; import com.somemore.domains.volunteer.dto.request.VolunteerProfileUpdateRequestDto; -import com.somemore.domains.volunteer.repository.old.VolunteerRepository; +import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.global.auth.oauth.domain.OAuthProvider; 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 19f5ea976..33a5f0a08 100644 --- a/src/test/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeServiceTest.java @@ -3,7 +3,7 @@ import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.repository.old.VolunteerRepository; +import com.somemore.domains.volunteer.repository.VolunteerRepository; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.dto.request.VolunteerApplySettleRequestDto; import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository; From 4cf63ce60cf938fc726b3556bab672a6f0de931d 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, 16 Jan 2025 14:34:16 +0900 Subject: [PATCH 29/34] =?UTF-8?q?feat:=20=EA=B8=B0=EA=B4=80=EC=9D=98=20?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=EC=83=81=EC=86=8D=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/center/domain/NEWCenter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/somemore/center/domain/NEWCenter.java b/src/main/java/com/somemore/center/domain/NEWCenter.java index 6d411ddce..35611cffe 100644 --- a/src/main/java/com/somemore/center/domain/NEWCenter.java +++ b/src/main/java/com/somemore/center/domain/NEWCenter.java @@ -1,5 +1,6 @@ package com.somemore.center.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 = "new_center") // TODO suffix 삭제 -public class NEWCenter { +public class NEWCenter extends BaseEntity { public static final String DEFAULT_NAME = "기관"; @Id From a3805a1cdfd4a9ca9284b64a211863e58f875390 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, 16 Jan 2025 14:34:49 +0900 Subject: [PATCH 30/34] =?UTF-8?q?feat(center):=20=EA=B8=B0=EA=B4=80=20?= =?UTF-8?q?=EC=95=84=EC=9D=B4=EB=94=94,=20=EC=9C=A0=EC=A0=80=20=EC=95=84?= =?UTF-8?q?=EC=9D=B4=EB=94=94=20=EA=B8=B0=EC=A4=80=20=EC=A1=B0=ED=9A=8C=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 --- .../repository/NEWCenterRepository.java | 7 +++ .../repository/NEWCenterRepositoryImpl.java | 50 +++++++++++++++++++ .../repository/NEWImplCenterRepository.java | 21 -------- 3 files changed, 57 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/somemore/center/repository/NEWCenterRepositoryImpl.java delete mode 100644 src/main/java/com/somemore/center/repository/NEWImplCenterRepository.java diff --git a/src/main/java/com/somemore/center/repository/NEWCenterRepository.java b/src/main/java/com/somemore/center/repository/NEWCenterRepository.java index 166f93fe8..4c0cb9d82 100644 --- a/src/main/java/com/somemore/center/repository/NEWCenterRepository.java +++ b/src/main/java/com/somemore/center/repository/NEWCenterRepository.java @@ -2,7 +2,14 @@ import com.somemore.center.domain.NEWCenter; +import java.util.Optional; +import java.util.UUID; + public interface NEWCenterRepository { NEWCenter save(NEWCenter center); + + Optional findById(UUID id); + + Optional findByUserId(UUID userId); } diff --git a/src/main/java/com/somemore/center/repository/NEWCenterRepositoryImpl.java b/src/main/java/com/somemore/center/repository/NEWCenterRepositoryImpl.java new file mode 100644 index 000000000..3022cbf4b --- /dev/null +++ b/src/main/java/com/somemore/center/repository/NEWCenterRepositoryImpl.java @@ -0,0 +1,50 @@ +package com.somemore.center.repository; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.somemore.center.domain.NEWCenter; +import com.somemore.center.domain.QNEWCenter; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Repository; + +import java.util.Optional; +import java.util.UUID; + +@Repository("newCenterRepository") +@RequiredArgsConstructor +public class NEWCenterRepositoryImpl implements NEWCenterRepository { + + @Qualifier("newCenterJpaRepository") + private final NEWCenterJpaRepository NEWCenterJpaRepository; + private final JPAQueryFactory queryFactory; + + private static final QNEWCenter center = QNEWCenter.nEWCenter; + + @Override + public NEWCenter save(NEWCenter center) { + return NEWCenterJpaRepository.save(center); + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable( + queryFactory.selectFrom(center) + .where( + center.id.eq(id), + center.deleted.eq(false)) + .fetchOne() + ); + } + + @Override + public Optional findByUserId(UUID userId) { + return Optional.ofNullable( + queryFactory.selectFrom(center) + .where( + center.userId.eq(userId), + center.deleted.eq(false)) + .fetchOne() + + ); + } +} diff --git a/src/main/java/com/somemore/center/repository/NEWImplCenterRepository.java b/src/main/java/com/somemore/center/repository/NEWImplCenterRepository.java deleted file mode 100644 index ff4161662..000000000 --- a/src/main/java/com/somemore/center/repository/NEWImplCenterRepository.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.somemore.center.repository; - -import com.querydsl.jpa.impl.JPAQueryFactory; -import com.somemore.center.domain.NEWCenter; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Repository; - -@Repository("newCenterRepository") -@RequiredArgsConstructor -public class NEWImplCenterRepository implements NEWCenterRepository { - - @Qualifier("newCenterJpaRepository") - private final NEWCenterJpaRepository NEWCenterJpaRepository; - private final JPAQueryFactory queryFactory; - - @Override - public NEWCenter save(NEWCenter center) { - return NEWCenterJpaRepository.save(center); - } -} From 7d552c75aa016579362d550ccf408d09b0e3daff 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, 16 Jan 2025 14:35:14 +0900 Subject: [PATCH 31/34] =?UTF-8?q?feat(volunteer):=20=EB=B4=89=EC=82=AC?= =?UTF-8?q?=EC=9E=90=20=EC=95=84=EC=9D=B4=EB=94=94,=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=20=EC=95=84=EC=9D=B4=EB=94=94=20=EA=B8=B0=EC=A4=80=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 --- .../repository/NEWVolunteerRepository.java | 7 ++++ .../NEWVolunteerRepositoryImpl.java | 34 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java index 1c3a7b0f6..4189070f0 100644 --- a/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java +++ b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepository.java @@ -2,7 +2,14 @@ import com.somemore.volunteer.domain.NEWVolunteer; +import java.util.Optional; +import java.util.UUID; + public interface NEWVolunteerRepository { NEWVolunteer save(NEWVolunteer volunteer); + + Optional findById(UUID id); + + Optional findByUserId(UUID userId); } diff --git a/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java index ffc5d65c4..94ff78d8b 100644 --- a/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java +++ b/src/main/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImpl.java @@ -1,11 +1,16 @@ package com.somemore.volunteer.repository; +import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import com.somemore.volunteer.domain.NEWVolunteer; +import com.somemore.volunteer.domain.QNEWVolunteer; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; +import java.util.Optional; +import java.util.UUID; + @Repository("newVolunteerRepository") @RequiredArgsConstructor public class NEWVolunteerRepositoryImpl implements NEWVolunteerRepository { @@ -14,8 +19,37 @@ public class NEWVolunteerRepositoryImpl implements NEWVolunteerRepository { private final NEWVolunteerJpaRepository NEWVolunteerJpaRepository; private final JPAQueryFactory queryFactory; + private static final QNEWVolunteer volunteer = QNEWVolunteer.nEWVolunteer; + @Override public NEWVolunteer save(NEWVolunteer volunteer) { return NEWVolunteerJpaRepository.save(volunteer); } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable( + queryFactory.selectFrom(volunteer) + .where( + volunteer.id.eq(id), + isNotDeleted() + ) + .fetchOne() + ); + } + + @Override + public Optional findByUserId(UUID userId) { + return Optional.ofNullable( + queryFactory.selectFrom(volunteer) + .where( + volunteer.userId.eq(userId), + isNotDeleted() + ) + .fetchOne() + ); } + + private static BooleanExpression isNotDeleted() { + return volunteer.deleted.eq(false); + } } From e6791d89a3b5286b9b55629d3870500d868ad663 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, 16 Jan 2025 14:35:32 +0900 Subject: [PATCH 32/34] =?UTF-8?q?test(center):=20=EA=B8=B0=EA=B4=80=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C,=20=EC=A0=80=EC=9E=A5=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 --- .../NEWCenterRepositoryImplTest.java | 39 +++++++++++++++++++ .../service/NEWRegisterCenterServiceTest.java | 38 ++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/test/java/com/somemore/center/repository/NEWCenterRepositoryImplTest.java create mode 100644 src/test/java/com/somemore/center/service/NEWRegisterCenterServiceTest.java diff --git a/src/test/java/com/somemore/center/repository/NEWCenterRepositoryImplTest.java b/src/test/java/com/somemore/center/repository/NEWCenterRepositoryImplTest.java new file mode 100644 index 000000000..e18244c5d --- /dev/null +++ b/src/test/java/com/somemore/center/repository/NEWCenterRepositoryImplTest.java @@ -0,0 +1,39 @@ +package com.somemore.center.repository; + +import com.somemore.center.domain.NEWCenter; +import com.somemore.support.IntegrationTestSupport; +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 NEWCenterRepositoryImplTest extends IntegrationTestSupport { + + @Autowired + private NEWCenterRepositoryImpl centerRepository; + + @DisplayName("유저 아이디로 기관을 등록할 수 있다.") + @Test + void saveVolunteerByUserId() { + // given + UUID userId = UUID.randomUUID(); + NEWCenter center = NEWCenter.createDefault(userId); + + // when + centerRepository.save(center); + + // then + NEWCenter centerByUserId = centerRepository.findByUserId(userId).orElseThrow(); + NEWCenter centerById = centerRepository.findById(center.getId()).orElseThrow(); + + assertThat(center) + .isEqualTo(centerByUserId) + .isEqualTo(centerById); + + } +} diff --git a/src/test/java/com/somemore/center/service/NEWRegisterCenterServiceTest.java b/src/test/java/com/somemore/center/service/NEWRegisterCenterServiceTest.java new file mode 100644 index 000000000..4ec9ff143 --- /dev/null +++ b/src/test/java/com/somemore/center/service/NEWRegisterCenterServiceTest.java @@ -0,0 +1,38 @@ +package com.somemore.center.service; + +import com.somemore.center.domain.NEWCenter; +import com.somemore.center.repository.NEWCenterRepository; +import com.somemore.support.IntegrationTestSupport; +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 NEWRegisterCenterServiceTest extends IntegrationTestSupport { + + @Autowired + private NEWRegisterCenterService registerCenterService; + + @Autowired + private NEWCenterRepository centerRepository; + + @Test + @DisplayName("유저 아이디로 센터가 등록될 수 있다.") + void registerByUserId() { + // given + UUID userId = UUID.randomUUID(); + + // when + NEWCenter savedCenter = registerCenterService.register(userId); + + // then + NEWCenter foundCenter = centerRepository.findByUserId(userId).orElseThrow(); + assertThat(savedCenter).isEqualTo(foundCenter); + } + +} \ No newline at end of file From 6ed46c620b7db8acc4efe16d41ec50d4901028f4 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, 16 Jan 2025 14:36:09 +0900 Subject: [PATCH 33/34] =?UTF-8?q?test(volunteer):=20=EB=B4=89=EC=82=AC?= =?UTF-8?q?=EC=9E=90=20=EC=A1=B0=ED=9A=8C,=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 --- .../NEWVolunteerRepositoryImplTest.java | 40 +++++++++++++++++++ .../NEWRegisterVolunteerServiceTest.java | 37 +++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/test/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImplTest.java create mode 100644 src/test/java/com/somemore/volunteer/service/NEWRegisterVolunteerServiceTest.java diff --git a/src/test/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImplTest.java b/src/test/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImplTest.java new file mode 100644 index 000000000..f4d49189d --- /dev/null +++ b/src/test/java/com/somemore/volunteer/repository/NEWVolunteerRepositoryImplTest.java @@ -0,0 +1,40 @@ +package com.somemore.volunteer.repository; + +import com.somemore.support.IntegrationTestSupport; +import com.somemore.volunteer.domain.NEWVolunteer; +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 NEWVolunteerRepositoryImplTest extends IntegrationTestSupport { + + @Autowired + private NEWVolunteerRepositoryImpl volunteerRepository; + + @DisplayName("유저 아이디로 봉사자를 등록할 수 있다.") + @Test + void saveVolunteerByUserId() { + // given + UUID userId = UUID.randomUUID(); + NEWVolunteer volunteer = NEWVolunteer.createDefault(userId); + + // when + volunteerRepository.save(volunteer); + + // then + NEWVolunteer volunteerByUserId = volunteerRepository.findByUserId(userId).orElseThrow(); + NEWVolunteer volunteerById = volunteerRepository.findById(volunteer.getId()).orElseThrow(); + + + assertThat(volunteer) + .isEqualTo(volunteerByUserId) + .isEqualTo(volunteerById); + + } +} diff --git a/src/test/java/com/somemore/volunteer/service/NEWRegisterVolunteerServiceTest.java b/src/test/java/com/somemore/volunteer/service/NEWRegisterVolunteerServiceTest.java new file mode 100644 index 000000000..1e121e6cb --- /dev/null +++ b/src/test/java/com/somemore/volunteer/service/NEWRegisterVolunteerServiceTest.java @@ -0,0 +1,37 @@ +package com.somemore.volunteer.service; + +import com.somemore.support.IntegrationTestSupport; +import com.somemore.volunteer.domain.NEWVolunteer; +import com.somemore.volunteer.repository.NEWVolunteerRepository; +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 NEWRegisterVolunteerServiceTest extends IntegrationTestSupport { + + @Autowired + private NEWRegisterVolunteerService registerVolunteerService; + + @Autowired + private NEWVolunteerRepository volunteerRepository; + + @Test + @DisplayName("유저 아이디로 봉사자가 등록될 수 있다.") + void registerByUserId() { + // given + UUID userId = UUID.randomUUID(); + + // when + NEWVolunteer savedVolunteer = registerVolunteerService.register(userId); + + // then + NEWVolunteer foundVolunteer = volunteerRepository.findByUserId(userId).orElseThrow(); + assertThat(savedVolunteer).isEqualTo(foundVolunteer); + } +} From b994d241d5d0f2a21fa8e16311f6f654c37330fe 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, 16 Jan 2025 14:46:55 +0900 Subject: [PATCH 34/34] refactor: suffix -> prefix --- src/main/java/com/somemore/center/domain/NEWCenter.java | 2 +- src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/somemore/center/domain/NEWCenter.java b/src/main/java/com/somemore/center/domain/NEWCenter.java index 35611cffe..9719e67b9 100644 --- a/src/main/java/com/somemore/center/domain/NEWCenter.java +++ b/src/main/java/com/somemore/center/domain/NEWCenter.java @@ -17,7 +17,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "new_center") // TODO suffix 삭제 +@Table(name = "new_center") // TODO prefix 삭제 public class NEWCenter extends BaseEntity { public static final String DEFAULT_NAME = "기관"; diff --git a/src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java b/src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java index fdb2ac139..1cddc21bc 100644 --- a/src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java +++ b/src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java @@ -21,7 +21,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "new_volunteer") // TODO suffix 삭제 +@Table(name = "new_volunteer") // TODO prefix 삭제 public class NEWVolunteer extends BaseEntity { public static final String DEFAULT_NAME = "봉사자";