From b56ce3e02af6ee51e04c527df41a9dc80df20fea Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 15:33:36 +0900 Subject: [PATCH 01/35] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{intro => version}/controller/IntroController.java | 4 ++-- .../controller/ProdIntroController.java | 6 +++--- .../controller/TestIntroController.java | 6 +++--- .../domain/{intro => version}/dto/IntroResponse.java | 2 +- .../dangjang/domain/{intro => version}/dto/Version.java | 2 +- .../domain/{intro => version}/service/IntroService.java | 6 +++--- .../controller/IntroControllerTest.java | 8 ++++---- .../{intro => version}/service/IntroServiceTest.java | 4 ++-- .../com/coniverse/dangjang/support/ControllerTest.java | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) rename src/main/java/com/coniverse/dangjang/domain/{intro => version}/controller/IntroController.java (77%) rename src/main/java/com/coniverse/dangjang/domain/{intro => version}/controller/ProdIntroController.java (82%) rename src/main/java/com/coniverse/dangjang/domain/{intro => version}/controller/TestIntroController.java (83%) rename src/main/java/com/coniverse/dangjang/domain/{intro => version}/dto/IntroResponse.java (86%) rename src/main/java/com/coniverse/dangjang/domain/{intro => version}/dto/Version.java (77%) rename src/main/java/com/coniverse/dangjang/domain/{intro => version}/service/IntroService.java (85%) rename src/test/java/com/coniverse/dangjang/domain/{intro => version}/controller/IntroControllerTest.java (91%) rename src/test/java/com/coniverse/dangjang/domain/{intro => version}/service/IntroServiceTest.java (91%) diff --git a/src/main/java/com/coniverse/dangjang/domain/intro/controller/IntroController.java b/src/main/java/com/coniverse/dangjang/domain/version/controller/IntroController.java similarity index 77% rename from src/main/java/com/coniverse/dangjang/domain/intro/controller/IntroController.java rename to src/main/java/com/coniverse/dangjang/domain/version/controller/IntroController.java index ddb5185a..619c0837 100644 --- a/src/main/java/com/coniverse/dangjang/domain/intro/controller/IntroController.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/controller/IntroController.java @@ -1,8 +1,8 @@ -package com.coniverse.dangjang.domain.intro.controller; +package com.coniverse.dangjang.domain.version.controller; import org.springframework.http.ResponseEntity; -import com.coniverse.dangjang.domain.intro.dto.IntroResponse; +import com.coniverse.dangjang.domain.version.dto.IntroResponse; import com.coniverse.dangjang.global.dto.SuccessSingleResponse; /** diff --git a/src/main/java/com/coniverse/dangjang/domain/intro/controller/ProdIntroController.java b/src/main/java/com/coniverse/dangjang/domain/version/controller/ProdIntroController.java similarity index 82% rename from src/main/java/com/coniverse/dangjang/domain/intro/controller/ProdIntroController.java rename to src/main/java/com/coniverse/dangjang/domain/version/controller/ProdIntroController.java index 7c6afa99..3b20e2ce 100644 --- a/src/main/java/com/coniverse/dangjang/domain/intro/controller/ProdIntroController.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/controller/ProdIntroController.java @@ -1,4 +1,4 @@ -package com.coniverse.dangjang.domain.intro.controller; +package com.coniverse.dangjang.domain.version.controller; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -6,8 +6,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.coniverse.dangjang.domain.intro.dto.IntroResponse; -import com.coniverse.dangjang.domain.intro.service.IntroService; +import com.coniverse.dangjang.domain.version.dto.IntroResponse; +import com.coniverse.dangjang.domain.version.service.IntroService; import com.coniverse.dangjang.global.dto.SuccessSingleResponse; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/coniverse/dangjang/domain/intro/controller/TestIntroController.java b/src/main/java/com/coniverse/dangjang/domain/version/controller/TestIntroController.java similarity index 83% rename from src/main/java/com/coniverse/dangjang/domain/intro/controller/TestIntroController.java rename to src/main/java/com/coniverse/dangjang/domain/version/controller/TestIntroController.java index 0dcb48bc..248a54f7 100644 --- a/src/main/java/com/coniverse/dangjang/domain/intro/controller/TestIntroController.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/controller/TestIntroController.java @@ -1,4 +1,4 @@ -package com.coniverse.dangjang.domain.intro.controller; +package com.coniverse.dangjang.domain.version.controller; import org.springframework.context.annotation.Profile; import org.springframework.http.HttpStatus; @@ -7,8 +7,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.coniverse.dangjang.domain.intro.dto.IntroResponse; -import com.coniverse.dangjang.domain.intro.service.IntroService; +import com.coniverse.dangjang.domain.version.dto.IntroResponse; +import com.coniverse.dangjang.domain.version.service.IntroService; import com.coniverse.dangjang.global.dto.SuccessSingleResponse; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/coniverse/dangjang/domain/intro/dto/IntroResponse.java b/src/main/java/com/coniverse/dangjang/domain/version/dto/IntroResponse.java similarity index 86% rename from src/main/java/com/coniverse/dangjang/domain/intro/dto/IntroResponse.java rename to src/main/java/com/coniverse/dangjang/domain/version/dto/IntroResponse.java index 7e1afbd0..480f351b 100644 --- a/src/main/java/com/coniverse/dangjang/domain/intro/dto/IntroResponse.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/dto/IntroResponse.java @@ -1,4 +1,4 @@ -package com.coniverse.dangjang.domain.intro.dto; +package com.coniverse.dangjang.domain.version.dto; import java.util.List; diff --git a/src/main/java/com/coniverse/dangjang/domain/intro/dto/Version.java b/src/main/java/com/coniverse/dangjang/domain/version/dto/Version.java similarity index 77% rename from src/main/java/com/coniverse/dangjang/domain/intro/dto/Version.java rename to src/main/java/com/coniverse/dangjang/domain/version/dto/Version.java index 9e849e7c..2d4ed86f 100644 --- a/src/main/java/com/coniverse/dangjang/domain/intro/dto/Version.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/dto/Version.java @@ -1,4 +1,4 @@ -package com.coniverse.dangjang.domain.intro.dto; +package com.coniverse.dangjang.domain.version.dto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/coniverse/dangjang/domain/intro/service/IntroService.java b/src/main/java/com/coniverse/dangjang/domain/version/service/IntroService.java similarity index 85% rename from src/main/java/com/coniverse/dangjang/domain/intro/service/IntroService.java rename to src/main/java/com/coniverse/dangjang/domain/version/service/IntroService.java index 0861db3a..bb59f39f 100644 --- a/src/main/java/com/coniverse/dangjang/domain/intro/service/IntroService.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/service/IntroService.java @@ -1,9 +1,9 @@ -package com.coniverse.dangjang.domain.intro.service; +package com.coniverse.dangjang.domain.version.service; import org.springframework.stereotype.Service; -import com.coniverse.dangjang.domain.intro.dto.IntroResponse; -import com.coniverse.dangjang.domain.intro.dto.Version; +import com.coniverse.dangjang.domain.version.dto.IntroResponse; +import com.coniverse.dangjang.domain.version.dto.Version; import com.coniverse.dangjang.global.exception.BadRequestException; import lombok.RequiredArgsConstructor; diff --git a/src/test/java/com/coniverse/dangjang/domain/intro/controller/IntroControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/version/controller/IntroControllerTest.java similarity index 91% rename from src/test/java/com/coniverse/dangjang/domain/intro/controller/IntroControllerTest.java rename to src/test/java/com/coniverse/dangjang/domain/version/controller/IntroControllerTest.java index c54b1586..c103290d 100644 --- a/src/test/java/com/coniverse/dangjang/domain/intro/controller/IntroControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/controller/IntroControllerTest.java @@ -1,4 +1,4 @@ -package com.coniverse.dangjang.domain.intro.controller; +package com.coniverse.dangjang.domain.version.controller; import static com.coniverse.dangjang.support.SimpleMockMvc.*; import static org.mockito.BDDMockito.*; @@ -10,9 +10,9 @@ import org.springframework.http.HttpStatus; import org.springframework.test.web.servlet.ResultActions; -import com.coniverse.dangjang.domain.intro.dto.IntroResponse; -import com.coniverse.dangjang.domain.intro.dto.Version; -import com.coniverse.dangjang.domain.intro.service.IntroService; +import com.coniverse.dangjang.domain.version.dto.IntroResponse; +import com.coniverse.dangjang.domain.version.dto.Version; +import com.coniverse.dangjang.domain.version.service.IntroService; import com.coniverse.dangjang.global.exception.BadRequestException; import com.coniverse.dangjang.support.ControllerTest; diff --git a/src/test/java/com/coniverse/dangjang/domain/intro/service/IntroServiceTest.java b/src/test/java/com/coniverse/dangjang/domain/version/service/IntroServiceTest.java similarity index 91% rename from src/test/java/com/coniverse/dangjang/domain/intro/service/IntroServiceTest.java rename to src/test/java/com/coniverse/dangjang/domain/version/service/IntroServiceTest.java index fb8733f7..94d5c26e 100644 --- a/src/test/java/com/coniverse/dangjang/domain/intro/service/IntroServiceTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/service/IntroServiceTest.java @@ -1,4 +1,4 @@ -package com.coniverse.dangjang.domain.intro.service; +package com.coniverse.dangjang.domain.version.service; import static org.assertj.core.api.Assertions.*; @@ -7,7 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import com.coniverse.dangjang.domain.intro.dto.IntroResponse; +import com.coniverse.dangjang.domain.version.dto.IntroResponse; import com.coniverse.dangjang.global.exception.BadRequestException; /** diff --git a/src/test/java/com/coniverse/dangjang/support/ControllerTest.java b/src/test/java/com/coniverse/dangjang/support/ControllerTest.java index aa08052e..87f5a57c 100644 --- a/src/test/java/com/coniverse/dangjang/support/ControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/support/ControllerTest.java @@ -25,8 +25,6 @@ import com.coniverse.dangjang.domain.healthmetric.service.HealthMetricChartSearchService; import com.coniverse.dangjang.domain.healthmetric.service.HealthMetricRegisterService; import com.coniverse.dangjang.domain.healthmetric.service.HealthMetricSearchService; -import com.coniverse.dangjang.domain.intro.controller.IntroController; -import com.coniverse.dangjang.domain.intro.service.IntroService; import com.coniverse.dangjang.domain.log.controller.AppLogController; import com.coniverse.dangjang.domain.log.service.LogService; import com.coniverse.dangjang.domain.notification.controller.NotificationController; @@ -39,6 +37,8 @@ import com.coniverse.dangjang.domain.user.service.MypageService; import com.coniverse.dangjang.domain.user.service.UserSignupService; import com.coniverse.dangjang.domain.user.service.UserWithdrawalService; +import com.coniverse.dangjang.domain.version.controller.IntroController; +import com.coniverse.dangjang.domain.version.service.IntroService; import com.fasterxml.jackson.databind.ObjectMapper; /** From 57bbebe2093ce58817b6d62d046a7a3b0129d52a Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 15:39:02 +0900 Subject: [PATCH 02/35] =?UTF-8?q?refactor:=20intro=20interface,=20test?= =?UTF-8?q?=EC=9A=A9=20controller=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../version/controller/IntroController.java | 16 -------- .../controller/ProdIntroController.java | 4 +- .../controller/TestIntroController.java | 29 -------------- .../controller/IntroControllerTest.java | 38 ------------------- .../dangjang/support/ControllerTest.java | 2 - 5 files changed, 1 insertion(+), 88 deletions(-) delete mode 100644 src/main/java/com/coniverse/dangjang/domain/version/controller/IntroController.java delete mode 100644 src/main/java/com/coniverse/dangjang/domain/version/controller/TestIntroController.java diff --git a/src/main/java/com/coniverse/dangjang/domain/version/controller/IntroController.java b/src/main/java/com/coniverse/dangjang/domain/version/controller/IntroController.java deleted file mode 100644 index 619c0837..00000000 --- a/src/main/java/com/coniverse/dangjang/domain/version/controller/IntroController.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.coniverse.dangjang.domain.version.controller; - -import org.springframework.http.ResponseEntity; - -import com.coniverse.dangjang.domain.version.dto.IntroResponse; -import com.coniverse.dangjang.global.dto.SuccessSingleResponse; - -/** - * client에서 앱을 처음 실행할 때, 앱의 버전을 확인하고, 최신 버전이 아니라면 업데이트를 유도하는 역할을 한다. - * - * @author TEO - * @since 1.0.0 - */ -public interface IntroController { - ResponseEntity>> getIntro(); -} diff --git a/src/main/java/com/coniverse/dangjang/domain/version/controller/ProdIntroController.java b/src/main/java/com/coniverse/dangjang/domain/version/controller/ProdIntroController.java index 3b20e2ce..acb2938b 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/controller/ProdIntroController.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/controller/ProdIntroController.java @@ -15,11 +15,9 @@ @RestController @RequestMapping("/api/intro") @RequiredArgsConstructor -public class ProdIntroController implements IntroController { +public class ProdIntroController { private final IntroService introService; - // TODO - @Override @GetMapping("/prod") public ResponseEntity>> getIntro() { IntroResponse introResponse = introService.getProdIntroResponse(); diff --git a/src/main/java/com/coniverse/dangjang/domain/version/controller/TestIntroController.java b/src/main/java/com/coniverse/dangjang/domain/version/controller/TestIntroController.java deleted file mode 100644 index 248a54f7..00000000 --- a/src/main/java/com/coniverse/dangjang/domain/version/controller/TestIntroController.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.coniverse.dangjang.domain.version.controller; - -import org.springframework.context.annotation.Profile; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import com.coniverse.dangjang.domain.version.dto.IntroResponse; -import com.coniverse.dangjang.domain.version.service.IntroService; -import com.coniverse.dangjang.global.dto.SuccessSingleResponse; - -import lombok.RequiredArgsConstructor; - -@RestController -@RequestMapping("/api/intro") -@RequiredArgsConstructor -@Profile({"dev", "local", "test"}) -public class TestIntroController implements IntroController { - private final IntroService introService; - - @Override - @GetMapping("/test") - public ResponseEntity>> getIntro() { - IntroResponse introResponse = introService.getTestIntroResponse(); - return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), introResponse)); - } -} diff --git a/src/test/java/com/coniverse/dangjang/domain/version/controller/IntroControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/version/controller/IntroControllerTest.java index c103290d..5821dbaf 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/controller/IntroControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/controller/IntroControllerTest.java @@ -13,7 +13,6 @@ import com.coniverse.dangjang.domain.version.dto.IntroResponse; import com.coniverse.dangjang.domain.version.dto.Version; import com.coniverse.dangjang.domain.version.service.IntroService; -import com.coniverse.dangjang.global.exception.BadRequestException; import com.coniverse.dangjang.support.ControllerTest; /** @@ -27,43 +26,6 @@ class IntroControllerTest extends ControllerTest { @Autowired private IntroService introService; - @Nested - class Test_Intro_URL에_접근시 { - @Test - void 성공한_응답을_반환한다() throws Exception { - // given - IntroResponse introResponse = new IntroResponse<>(MIN_VERSION, LATEST_VERSION, null); - given(introService.getTestIntroResponse()).willReturn(introResponse); - - // when - ResultActions resultActions = get(mockMvc, URI + "/test"); - - // then - resultActions.andExpectAll( - status().isOk(), - jsonPath("$.message").value(HttpStatus.OK.getReasonPhrase()), - jsonPath("$.data.minVersion").value(introResponse.minVersion()), - jsonPath("$.data.latestVersion").value(introResponse.latestVersion()) - ); - } - - @Test - void 실패한_응답을_반환한다() throws Exception { - // given - given(introService.getTestIntroResponse()).willThrow(new BadRequestException()); - - // when - ResultActions resultActions = get(mockMvc, URI + "/test"); - - // then - resultActions.andExpectAll( - status().isBadRequest(), - jsonPath("$.errorCode").value(400), - jsonPath("$.message").value("잘못된 요청입니다.") - ); - } - } - @Nested class Prod_Intro_URL에_접근시 { @Test diff --git a/src/test/java/com/coniverse/dangjang/support/ControllerTest.java b/src/test/java/com/coniverse/dangjang/support/ControllerTest.java index 87f5a57c..a848f659 100644 --- a/src/test/java/com/coniverse/dangjang/support/ControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/support/ControllerTest.java @@ -37,7 +37,6 @@ import com.coniverse.dangjang.domain.user.service.MypageService; import com.coniverse.dangjang.domain.user.service.UserSignupService; import com.coniverse.dangjang.domain.user.service.UserWithdrawalService; -import com.coniverse.dangjang.domain.version.controller.IntroController; import com.coniverse.dangjang.domain.version.service.IntroService; import com.fasterxml.jackson.databind.ObjectMapper; @@ -51,7 +50,6 @@ */ @WebMvcTest( controllers = { - IntroController.class, HealthMetricController.class, LoginController.class, SignupController.class, From 6ff0c40b400b286517f699f338049d17f50dca63 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 15:41:03 +0900 Subject: [PATCH 03/35] =?UTF-8?q?refactor:=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...odIntroController.java => VersionController.java} | 8 ++++---- .../{IntroService.java => VersionService.java} | 2 +- ...ontrollerTest.java => VersionControllerTest.java} | 8 ++++---- ...IntroServiceTest.java => VersionServiceTest.java} | 12 ++++++------ .../coniverse/dangjang/support/ControllerTest.java | 7 ++++--- 5 files changed, 19 insertions(+), 18 deletions(-) rename src/main/java/com/coniverse/dangjang/domain/version/controller/{ProdIntroController.java => VersionController.java} (78%) rename src/main/java/com/coniverse/dangjang/domain/version/service/{IntroService.java => VersionService.java} (97%) rename src/test/java/com/coniverse/dangjang/domain/version/controller/{IntroControllerTest.java => VersionControllerTest.java} (86%) rename src/test/java/com/coniverse/dangjang/domain/version/service/{IntroServiceTest.java => VersionServiceTest.java} (72%) diff --git a/src/main/java/com/coniverse/dangjang/domain/version/controller/ProdIntroController.java b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java similarity index 78% rename from src/main/java/com/coniverse/dangjang/domain/version/controller/ProdIntroController.java rename to src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java index acb2938b..d8e00b64 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/controller/ProdIntroController.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java @@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.RestController; import com.coniverse.dangjang.domain.version.dto.IntroResponse; -import com.coniverse.dangjang.domain.version.service.IntroService; +import com.coniverse.dangjang.domain.version.service.VersionService; import com.coniverse.dangjang.global.dto.SuccessSingleResponse; import lombok.RequiredArgsConstructor; @@ -15,12 +15,12 @@ @RestController @RequestMapping("/api/intro") @RequiredArgsConstructor -public class ProdIntroController { - private final IntroService introService; +public class VersionController { + private final VersionService versionService; @GetMapping("/prod") public ResponseEntity>> getIntro() { - IntroResponse introResponse = introService.getProdIntroResponse(); + IntroResponse introResponse = versionService.getProdIntroResponse(); return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), introResponse)); } } diff --git a/src/main/java/com/coniverse/dangjang/domain/version/service/IntroService.java b/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java similarity index 97% rename from src/main/java/com/coniverse/dangjang/domain/version/service/IntroService.java rename to src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java index bb59f39f..99e33c30 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/service/IntroService.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java @@ -14,7 +14,7 @@ */ @Service @RequiredArgsConstructor -public class IntroService { +public class VersionService { private static final String MIN_VERSION = Version.MINIMUM.getVersion(); private static final String LATEST_VERSION = Version.LATEST.getVersion(); private int error = -1; diff --git a/src/test/java/com/coniverse/dangjang/domain/version/controller/IntroControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java similarity index 86% rename from src/test/java/com/coniverse/dangjang/domain/version/controller/IntroControllerTest.java rename to src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java index 5821dbaf..5c5fd8e7 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/controller/IntroControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java @@ -12,19 +12,19 @@ import com.coniverse.dangjang.domain.version.dto.IntroResponse; import com.coniverse.dangjang.domain.version.dto.Version; -import com.coniverse.dangjang.domain.version.service.IntroService; +import com.coniverse.dangjang.domain.version.service.VersionService; import com.coniverse.dangjang.support.ControllerTest; /** * @author TEO * @since 1.0.0 */ -class IntroControllerTest extends ControllerTest { +class VersionControllerTest extends ControllerTest { private static final String URI = "/api/intro"; private static final String MIN_VERSION = Version.MINIMUM.getVersion(); private static final String LATEST_VERSION = Version.LATEST.getVersion(); @Autowired - private IntroService introService; + private VersionService versionService; @Nested class Prod_Intro_URL에_접근시 { @@ -32,7 +32,7 @@ class Prod_Intro_URL에_접근시 { void 성공한_응답을_반환한다() throws Exception { // given IntroResponse introResponse = new IntroResponse<>(MIN_VERSION, LATEST_VERSION, null); - given(introService.getProdIntroResponse()).willReturn(introResponse); + given(versionService.getProdIntroResponse()).willReturn(introResponse); // when ResultActions resultActions = get(mockMvc, URI + "/prod"); diff --git a/src/test/java/com/coniverse/dangjang/domain/version/service/IntroServiceTest.java b/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java similarity index 72% rename from src/test/java/com/coniverse/dangjang/domain/version/service/IntroServiceTest.java rename to src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java index 94d5c26e..8656d3a4 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/service/IntroServiceTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java @@ -15,16 +15,16 @@ * @since 1.0.0 */ @SpringBootTest -class IntroServiceTest { +class VersionServiceTest { @Autowired - private IntroService introService; + private VersionService versionService; @Nested class TestIntroResponse를 { @Test void 한_번_호출하면_IntroResponse가_반환된다() { // when - IntroResponse introResponse = introService.getTestIntroResponse(); + IntroResponse introResponse = versionService.getTestIntroResponse(); // then assertThat(introResponse).isNotNull(); @@ -33,10 +33,10 @@ class TestIntroResponse를 { @Test void 두_번_연속_호출하면_BadRequestException이_발생한다() { // given - introService.getTestIntroResponse(); + versionService.getTestIntroResponse(); // when & then - assertThatThrownBy(() -> introService.getTestIntroResponse()).isInstanceOf(BadRequestException.class); + assertThatThrownBy(() -> versionService.getTestIntroResponse()).isInstanceOf(BadRequestException.class); } } @@ -45,7 +45,7 @@ class ProdIntroResponse를 { @Test void 호출하면_IntroResponse가_반환된다() { // when - IntroResponse introResponse = introService.getProdIntroResponse(); + IntroResponse introResponse = versionService.getProdIntroResponse(); // then assertThat(introResponse).isNotNull(); diff --git a/src/test/java/com/coniverse/dangjang/support/ControllerTest.java b/src/test/java/com/coniverse/dangjang/support/ControllerTest.java index a848f659..1b762aa6 100644 --- a/src/test/java/com/coniverse/dangjang/support/ControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/support/ControllerTest.java @@ -37,7 +37,8 @@ import com.coniverse.dangjang.domain.user.service.MypageService; import com.coniverse.dangjang.domain.user.service.UserSignupService; import com.coniverse.dangjang.domain.user.service.UserWithdrawalService; -import com.coniverse.dangjang.domain.version.service.IntroService; +import com.coniverse.dangjang.domain.version.controller.VersionController; +import com.coniverse.dangjang.domain.version.service.VersionService; import com.fasterxml.jackson.databind.ObjectMapper; /** @@ -50,6 +51,7 @@ */ @WebMvcTest( controllers = { + VersionController.class, HealthMetricController.class, LoginController.class, SignupController.class, @@ -73,7 +75,7 @@ public class ControllerTest { @Autowired protected ObjectMapper objectMapper; @MockBean - private IntroService introService; + private VersionService versionService; @MockBean private OauthLoginService oAuthLoginService; @MockBean @@ -108,5 +110,4 @@ public class ControllerTest { private NotificationService notificationService; @MockBean private HealthMetricSearchService healthMetricSearchService; - } From fc8100435f520281486dfe2f1ec1d32be6ce8849 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 15:47:37 +0900 Subject: [PATCH 04/35] =?UTF-8?q?refactor:=20endpoint=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dangjang/domain/version/controller/VersionController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java index d8e00b64..7ecaabc0 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java @@ -13,12 +13,12 @@ import lombok.RequiredArgsConstructor; @RestController -@RequestMapping("/api/intro") +@RequestMapping("/api/version") @RequiredArgsConstructor public class VersionController { private final VersionService versionService; - @GetMapping("/prod") + @GetMapping("/intro") public ResponseEntity>> getIntro() { IntroResponse introResponse = versionService.getProdIntroResponse(); return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), introResponse)); From 27fda69260a0d352f659bd043a5dca59193eef0b Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 15:50:46 +0900 Subject: [PATCH 05/35] =?UTF-8?q?refactor:=20dto=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../version/controller/VersionController.java | 8 ++++---- .../dangjang/domain/version/dto/IntroResponse.java | 14 -------------- .../version/dto/response/VersionResponse.java | 14 ++++++++++++++ .../domain/version/service/VersionService.java | 14 +++++++------- .../version/controller/VersionControllerTest.java | 10 +++++----- .../domain/version/service/VersionServiceTest.java | 10 +++++----- 6 files changed, 35 insertions(+), 35 deletions(-) delete mode 100644 src/main/java/com/coniverse/dangjang/domain/version/dto/IntroResponse.java create mode 100644 src/main/java/com/coniverse/dangjang/domain/version/dto/response/VersionResponse.java diff --git a/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java index 7ecaabc0..867d632d 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java @@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.coniverse.dangjang.domain.version.dto.IntroResponse; +import com.coniverse.dangjang.domain.version.dto.response.VersionResponse; import com.coniverse.dangjang.domain.version.service.VersionService; import com.coniverse.dangjang.global.dto.SuccessSingleResponse; @@ -19,8 +19,8 @@ public class VersionController { private final VersionService versionService; @GetMapping("/intro") - public ResponseEntity>> getIntro() { - IntroResponse introResponse = versionService.getProdIntroResponse(); - return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), introResponse)); + public ResponseEntity>> getIntro() { + VersionResponse versionResponse = versionService.getProdIntroResponse(); + return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), versionResponse)); } } diff --git a/src/main/java/com/coniverse/dangjang/domain/version/dto/IntroResponse.java b/src/main/java/com/coniverse/dangjang/domain/version/dto/IntroResponse.java deleted file mode 100644 index 480f351b..00000000 --- a/src/main/java/com/coniverse/dangjang/domain/version/dto/IntroResponse.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.coniverse.dangjang.domain.version.dto; - -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonInclude; - -/** - * splash screen time때 load할 버전 정보와 데이터를 담는 dto이다. - * - * @author TEO - * @since 1.0.0 - */ -public record IntroResponse(String minVersion, String latestVersion, @JsonInclude(JsonInclude.Include.NON_NULL) List loadData) { -} diff --git a/src/main/java/com/coniverse/dangjang/domain/version/dto/response/VersionResponse.java b/src/main/java/com/coniverse/dangjang/domain/version/dto/response/VersionResponse.java new file mode 100644 index 00000000..c30777e4 --- /dev/null +++ b/src/main/java/com/coniverse/dangjang/domain/version/dto/response/VersionResponse.java @@ -0,0 +1,14 @@ +package com.coniverse.dangjang.domain.version.dto.response; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonInclude; + +/** + * 버전 정보를 반환하는 dto이다. + * + * @author TEO + * @since 1.0.0 + */ +public record VersionResponse(String minVersion, String latestVersion, @JsonInclude(JsonInclude.Include.NON_NULL) List loadData) { +} diff --git a/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java b/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java index 99e33c30..c4ccab1a 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java @@ -2,8 +2,8 @@ import org.springframework.stereotype.Service; -import com.coniverse.dangjang.domain.version.dto.IntroResponse; import com.coniverse.dangjang.domain.version.dto.Version; +import com.coniverse.dangjang.domain.version.dto.response.VersionResponse; import com.coniverse.dangjang.global.exception.BadRequestException; import lombok.RequiredArgsConstructor; @@ -25,11 +25,11 @@ public class VersionService { * @return IntroResponse * @since 1.0.0 */ - public IntroResponse getTestIntroResponse() { - IntroResponse introResponse = new IntroResponse<>(MIN_VERSION, LATEST_VERSION, null); + public VersionResponse getTestIntroResponse() { + VersionResponse versionResponse = new VersionResponse<>(MIN_VERSION, LATEST_VERSION, null); error += 1; if (error % 2 == 0) { - return introResponse; + return versionResponse; } throw new BadRequestException(); } @@ -40,9 +40,9 @@ public IntroResponse getTestIntroResponse() { * @return IntroResponse * @since 1.0.0 */ - public IntroResponse getProdIntroResponse() { - IntroResponse introResponse = new IntroResponse<>(MIN_VERSION, LATEST_VERSION, null); + public VersionResponse getProdIntroResponse() { + VersionResponse versionResponse = new VersionResponse<>(MIN_VERSION, LATEST_VERSION, null); - return introResponse; + return versionResponse; } } diff --git a/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java index 5c5fd8e7..23d0f389 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java @@ -10,8 +10,8 @@ import org.springframework.http.HttpStatus; import org.springframework.test.web.servlet.ResultActions; -import com.coniverse.dangjang.domain.version.dto.IntroResponse; import com.coniverse.dangjang.domain.version.dto.Version; +import com.coniverse.dangjang.domain.version.dto.response.VersionResponse; import com.coniverse.dangjang.domain.version.service.VersionService; import com.coniverse.dangjang.support.ControllerTest; @@ -31,8 +31,8 @@ class Prod_Intro_URL에_접근시 { @Test void 성공한_응답을_반환한다() throws Exception { // given - IntroResponse introResponse = new IntroResponse<>(MIN_VERSION, LATEST_VERSION, null); - given(versionService.getProdIntroResponse()).willReturn(introResponse); + VersionResponse versionResponse = new VersionResponse<>(MIN_VERSION, LATEST_VERSION, null); + given(versionService.getProdIntroResponse()).willReturn(versionResponse); // when ResultActions resultActions = get(mockMvc, URI + "/prod"); @@ -41,8 +41,8 @@ class Prod_Intro_URL에_접근시 { resultActions.andExpectAll( status().isOk(), jsonPath("$.message").value(HttpStatus.OK.getReasonPhrase()), - jsonPath("$.data.minVersion").value(introResponse.minVersion()), - jsonPath("$.data.latestVersion").value(introResponse.latestVersion()) + jsonPath("$.data.minVersion").value(versionResponse.minVersion()), + jsonPath("$.data.latestVersion").value(versionResponse.latestVersion()) ); } } diff --git a/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java b/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java index 8656d3a4..1db430fc 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java @@ -7,7 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import com.coniverse.dangjang.domain.version.dto.IntroResponse; +import com.coniverse.dangjang.domain.version.dto.response.VersionResponse; import com.coniverse.dangjang.global.exception.BadRequestException; /** @@ -24,10 +24,10 @@ class TestIntroResponse를 { @Test void 한_번_호출하면_IntroResponse가_반환된다() { // when - IntroResponse introResponse = versionService.getTestIntroResponse(); + VersionResponse versionResponse = versionService.getTestIntroResponse(); // then - assertThat(introResponse).isNotNull(); + assertThat(versionResponse).isNotNull(); } @Test @@ -45,10 +45,10 @@ class ProdIntroResponse를 { @Test void 호출하면_IntroResponse가_반환된다() { // when - IntroResponse introResponse = versionService.getProdIntroResponse(); + VersionResponse versionResponse = versionService.getProdIntroResponse(); // then - assertThat(introResponse).isNotNull(); + assertThat(versionResponse).isNotNull(); } } } From c8b05880afe6450a29941cb2878fca92b5ac4aa7 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 15:58:37 +0900 Subject: [PATCH 06/35] =?UTF-8?q?feat:=20version=20domain=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/version/entity/Version.java | 26 +++++++++++++++++++ .../version/repository/VersionRepository.java | 8 ++++++ 2 files changed, 34 insertions(+) create mode 100644 src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java create mode 100644 src/main/java/com/coniverse/dangjang/domain/version/repository/VersionRepository.java diff --git a/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java b/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java new file mode 100644 index 00000000..9cb167a5 --- /dev/null +++ b/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java @@ -0,0 +1,26 @@ +package com.coniverse.dangjang.domain.version.entity; + +import com.coniverse.dangjang.global.support.BaseEntity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Version extends BaseEntity { + @Id + private Long id; + private String minVersion; + private String latestVersion; + + @Builder + private Version(String minVersion, String latestVersion) { + this.minVersion = minVersion; + this.latestVersion = latestVersion; + } +} diff --git a/src/main/java/com/coniverse/dangjang/domain/version/repository/VersionRepository.java b/src/main/java/com/coniverse/dangjang/domain/version/repository/VersionRepository.java new file mode 100644 index 00000000..2069654e --- /dev/null +++ b/src/main/java/com/coniverse/dangjang/domain/version/repository/VersionRepository.java @@ -0,0 +1,8 @@ +package com.coniverse.dangjang.domain.version.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.coniverse.dangjang.domain.version.entity.Version; + +public interface VersionRepository extends JpaRepository { +} From f4400265db1dda9fa447e16ec5dc76804bba2f1f Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 16:01:53 +0900 Subject: [PATCH 07/35] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../version/controller/VersionController.java | 2 +- .../version/service/VersionService.java | 21 +--------------- .../controller/VersionControllerTest.java | 2 +- .../version/service/VersionServiceTest.java | 24 +------------------ 4 files changed, 4 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java index 867d632d..8328e411 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java @@ -20,7 +20,7 @@ public class VersionController { @GetMapping("/intro") public ResponseEntity>> getIntro() { - VersionResponse versionResponse = versionService.getProdIntroResponse(); + VersionResponse versionResponse = versionService.getIntroResponse(); return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), versionResponse)); } } diff --git a/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java b/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java index c4ccab1a..994dc2fb 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java @@ -4,7 +4,6 @@ import com.coniverse.dangjang.domain.version.dto.Version; import com.coniverse.dangjang.domain.version.dto.response.VersionResponse; -import com.coniverse.dangjang.global.exception.BadRequestException; import lombok.RequiredArgsConstructor; @@ -17,30 +16,12 @@ public class VersionService { private static final String MIN_VERSION = Version.MINIMUM.getVersion(); private static final String LATEST_VERSION = Version.LATEST.getVersion(); - private int error = -1; /** - * response를 성공적으로 반환 또는 예외 발생을 번갈아가며 실행한다. - * * @return IntroResponse * @since 1.0.0 */ - public VersionResponse getTestIntroResponse() { - VersionResponse versionResponse = new VersionResponse<>(MIN_VERSION, LATEST_VERSION, null); - error += 1; - if (error % 2 == 0) { - return versionResponse; - } - throw new BadRequestException(); - } - - /** - * TODO load data - * - * @return IntroResponse - * @since 1.0.0 - */ - public VersionResponse getProdIntroResponse() { + public VersionResponse getIntroResponse() { VersionResponse versionResponse = new VersionResponse<>(MIN_VERSION, LATEST_VERSION, null); return versionResponse; diff --git a/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java index 23d0f389..02c0fb7a 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java @@ -32,7 +32,7 @@ class Prod_Intro_URL에_접근시 { void 성공한_응답을_반환한다() throws Exception { // given VersionResponse versionResponse = new VersionResponse<>(MIN_VERSION, LATEST_VERSION, null); - given(versionService.getProdIntroResponse()).willReturn(versionResponse); + given(versionService.getIntroResponse()).willReturn(versionResponse); // when ResultActions resultActions = get(mockMvc, URI + "/prod"); diff --git a/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java b/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java index 1db430fc..7e396619 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java @@ -8,7 +8,6 @@ import org.springframework.boot.test.context.SpringBootTest; import com.coniverse.dangjang.domain.version.dto.response.VersionResponse; -import com.coniverse.dangjang.global.exception.BadRequestException; /** * @author TEO @@ -19,33 +18,12 @@ class VersionServiceTest { @Autowired private VersionService versionService; - @Nested - class TestIntroResponse를 { - @Test - void 한_번_호출하면_IntroResponse가_반환된다() { - // when - VersionResponse versionResponse = versionService.getTestIntroResponse(); - - // then - assertThat(versionResponse).isNotNull(); - } - - @Test - void 두_번_연속_호출하면_BadRequestException이_발생한다() { - // given - versionService.getTestIntroResponse(); - - // when & then - assertThatThrownBy(() -> versionService.getTestIntroResponse()).isInstanceOf(BadRequestException.class); - } - } - @Nested class ProdIntroResponse를 { @Test void 호출하면_IntroResponse가_반환된다() { // when - VersionResponse versionResponse = versionService.getProdIntroResponse(); + VersionResponse versionResponse = versionService.getIntroResponse(); // then assertThat(versionResponse).isNotNull(); From db1c7ead10c79f859ed54afa718217eb8bc4d853 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 16:50:23 +0900 Subject: [PATCH 08/35] =?UTF-8?q?feat:=20=EC=83=9D=EC=84=B1=EC=9E=90=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/version/dto/response/VersionResponse.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/coniverse/dangjang/domain/version/dto/response/VersionResponse.java b/src/main/java/com/coniverse/dangjang/domain/version/dto/response/VersionResponse.java index c30777e4..e2a60ce0 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/dto/response/VersionResponse.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/dto/response/VersionResponse.java @@ -2,13 +2,17 @@ import java.util.List; +import com.coniverse.dangjang.domain.version.entity.Version; import com.fasterxml.jackson.annotation.JsonInclude; /** * 버전 정보를 반환하는 dto이다. * * @author TEO - * @since 1.0.0 + * @since 1.3.0 */ public record VersionResponse(String minVersion, String latestVersion, @JsonInclude(JsonInclude.Include.NON_NULL) List loadData) { + public VersionResponse(Version version, List loadData) { + this(version.getMinVersion(), version.getLatestVersion(), loadData); + } } From a383311404f023b2a0ac89a2f79fad3bead17646 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 16:50:59 +0900 Subject: [PATCH 09/35] =?UTF-8?q?feat:=20=EB=B2=84=EC=A0=84=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=A5=BC=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=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 --- .../version/controller/VersionController.java | 2 +- .../version/repository/VersionRepository.java | 14 ++++++++++++++ .../version/service/VersionService.java | 19 ++++++++++--------- .../controller/VersionControllerTest.java | 2 +- .../version/service/VersionServiceTest.java | 2 +- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java index 8328e411..56bb12eb 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java @@ -20,7 +20,7 @@ public class VersionController { @GetMapping("/intro") public ResponseEntity>> getIntro() { - VersionResponse versionResponse = versionService.getIntroResponse(); + VersionResponse versionResponse = versionService.getVersionResponse(); return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), versionResponse)); } } diff --git a/src/main/java/com/coniverse/dangjang/domain/version/repository/VersionRepository.java b/src/main/java/com/coniverse/dangjang/domain/version/repository/VersionRepository.java index 2069654e..7b101533 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/repository/VersionRepository.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/repository/VersionRepository.java @@ -4,5 +4,19 @@ import com.coniverse.dangjang.domain.version.entity.Version; +/** + * version repository + * + * @author TEO + * @since 1.3.0 + */ public interface VersionRepository extends JpaRepository { + + /** + * 가장 최근의 버전 정보를 반환한다. + * + * @return Version + * @since 1.3.0 + */ + Version findFirstByOrderByCreatedAtDesc(); } diff --git a/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java b/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java index 994dc2fb..d2f88b7a 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java @@ -2,28 +2,29 @@ import org.springframework.stereotype.Service; -import com.coniverse.dangjang.domain.version.dto.Version; import com.coniverse.dangjang.domain.version.dto.response.VersionResponse; +import com.coniverse.dangjang.domain.version.entity.Version; +import com.coniverse.dangjang.domain.version.repository.VersionRepository; import lombok.RequiredArgsConstructor; /** * @author TEO - * @since 1.0.0 + * @since 1.3.0 */ @Service @RequiredArgsConstructor public class VersionService { - private static final String MIN_VERSION = Version.MINIMUM.getVersion(); - private static final String LATEST_VERSION = Version.LATEST.getVersion(); + private final VersionRepository versionRepository; /** - * @return IntroResponse + * 가장 최근의 버전 정보를 반환한다. + * + * @return VersionResponse * @since 1.0.0 */ - public VersionResponse getIntroResponse() { - VersionResponse versionResponse = new VersionResponse<>(MIN_VERSION, LATEST_VERSION, null); - - return versionResponse; + public VersionResponse getVersionResponse() { + Version version = versionRepository.findFirstByOrderByCreatedAtDesc(); + return new VersionResponse<>(version, null); } } diff --git a/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java index 02c0fb7a..66fd699a 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java @@ -32,7 +32,7 @@ class Prod_Intro_URL에_접근시 { void 성공한_응답을_반환한다() throws Exception { // given VersionResponse versionResponse = new VersionResponse<>(MIN_VERSION, LATEST_VERSION, null); - given(versionService.getIntroResponse()).willReturn(versionResponse); + given(versionService.getVersionResponse()).willReturn(versionResponse); // when ResultActions resultActions = get(mockMvc, URI + "/prod"); diff --git a/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java b/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java index 7e396619..9e2fdefe 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java @@ -23,7 +23,7 @@ class ProdIntroResponse를 { @Test void 호출하면_IntroResponse가_반환된다() { // when - VersionResponse versionResponse = versionService.getIntroResponse(); + VersionResponse versionResponse = versionService.getVersionResponse(); // then assertThat(versionResponse).isNotNull(); From 25b708dd95516cd8ccc89f0bc22d56d499315c5e Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 16:51:16 +0900 Subject: [PATCH 10/35] =?UTF-8?q?docs:=20JavaDoc=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coniverse/dangjang/domain/version/entity/Version.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java b/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java index 9cb167a5..67acabc1 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java @@ -9,6 +9,12 @@ import lombok.Getter; import lombok.NoArgsConstructor; +/** + * version entity + * + * @author TEO + * @since 1.3.0 + */ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) From e912ae7a0acbeea5e1aea17033d00af9b75ea409 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 16:53:21 +0900 Subject: [PATCH 11/35] =?UTF-8?q?refactor:=20=EB=B2=84=EC=A0=84=20enum=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dangjang/domain/version/dto/Version.java | 13 ------------- .../version/controller/VersionControllerTest.java | 4 +--- 2 files changed, 1 insertion(+), 16 deletions(-) delete mode 100644 src/main/java/com/coniverse/dangjang/domain/version/dto/Version.java diff --git a/src/main/java/com/coniverse/dangjang/domain/version/dto/Version.java b/src/main/java/com/coniverse/dangjang/domain/version/dto/Version.java deleted file mode 100644 index 2d4ed86f..00000000 --- a/src/main/java/com/coniverse/dangjang/domain/version/dto/Version.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.coniverse.dangjang.domain.version.dto; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@AllArgsConstructor -public enum Version { - MINIMUM("1.0.7"), - LATEST("1.0.7"); - - @Getter - private final String version; -} diff --git a/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java index 66fd699a..8e8970a3 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java @@ -10,7 +10,6 @@ import org.springframework.http.HttpStatus; import org.springframework.test.web.servlet.ResultActions; -import com.coniverse.dangjang.domain.version.dto.Version; import com.coniverse.dangjang.domain.version.dto.response.VersionResponse; import com.coniverse.dangjang.domain.version.service.VersionService; import com.coniverse.dangjang.support.ControllerTest; @@ -21,8 +20,7 @@ */ class VersionControllerTest extends ControllerTest { private static final String URI = "/api/intro"; - private static final String MIN_VERSION = Version.MINIMUM.getVersion(); - private static final String LATEST_VERSION = Version.LATEST.getVersion(); + @Autowired private VersionService versionService; From a53915a56e6811a8ae04c52a07af1fea623a079c Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 16:55:20 +0900 Subject: [PATCH 12/35] =?UTF-8?q?docs:=20JavaDoc=20=EC=B6=94=EA=B0=80,=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/version/controller/VersionController.java | 11 +++++++++++ .../dangjang/domain/version/entity/Version.java | 2 +- .../domain/version/repository/VersionRepository.java | 2 +- .../domain/version/service/VersionService.java | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java index 56bb12eb..7ebe4309 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java @@ -12,12 +12,23 @@ import lombok.RequiredArgsConstructor; +/** + * 앱 버전 관련 controller + * + * @author TEO + * @since 1.3.0 + */ @RestController @RequestMapping("/api/version") @RequiredArgsConstructor public class VersionController { private final VersionService versionService; + /** + * 버전 정보를 GET 요청한다. + * + * @since 1.3.0 + */ @GetMapping("/intro") public ResponseEntity>> getIntro() { VersionResponse versionResponse = versionService.getVersionResponse(); diff --git a/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java b/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java index 67acabc1..3c6f1870 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java @@ -10,7 +10,7 @@ import lombok.NoArgsConstructor; /** - * version entity + * app version entity * * @author TEO * @since 1.3.0 diff --git a/src/main/java/com/coniverse/dangjang/domain/version/repository/VersionRepository.java b/src/main/java/com/coniverse/dangjang/domain/version/repository/VersionRepository.java index 7b101533..577e97c8 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/repository/VersionRepository.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/repository/VersionRepository.java @@ -5,7 +5,7 @@ import com.coniverse.dangjang.domain.version.entity.Version; /** - * version repository + * app version repository * * @author TEO * @since 1.3.0 diff --git a/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java b/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java index d2f88b7a..f158220d 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java @@ -9,6 +9,8 @@ import lombok.RequiredArgsConstructor; /** + * 앱 버전 관련 service + * * @author TEO * @since 1.3.0 */ From 1f3cd1c0f94d2c6bc459e1e7f932aa643ac013b2 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 17:11:58 +0900 Subject: [PATCH 13/35] =?UTF-8?q?feat:=20=EC=95=B1=20=EB=B2=84=EC=A0=84=20?= =?UTF-8?q?post=20=EC=9A=94=EC=B2=AD=EC=8B=9C=20body=EC=97=90=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=A0=20dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/version/dto/request/VersionRequest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/com/coniverse/dangjang/domain/version/dto/request/VersionRequest.java diff --git a/src/main/java/com/coniverse/dangjang/domain/version/dto/request/VersionRequest.java b/src/main/java/com/coniverse/dangjang/domain/version/dto/request/VersionRequest.java new file mode 100644 index 00000000..d5eed2d0 --- /dev/null +++ b/src/main/java/com/coniverse/dangjang/domain/version/dto/request/VersionRequest.java @@ -0,0 +1,12 @@ +package com.coniverse.dangjang.domain.version.dto.request; + +import jakarta.validation.constraints.NotBlank; + +/** + * 앱 버전 post dto + * + * @author TEO + * @since 1.3.0 + */ +public record VersionRequest(@NotBlank String minVersion, @NotBlank String latestVersion, @NotBlank String key) { +} From cad1dc955d42a0f736ec12ffe95e3dfd4d343e22 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 17:12:42 +0900 Subject: [PATCH 14/35] chore: update submodule --- src/main/resources/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/config b/src/main/resources/config index 64b96d83..f027d62e 160000 --- a/src/main/resources/config +++ b/src/main/resources/config @@ -1 +1 @@ -Subproject commit 64b96d83da52275f908d1f7599812ca34dd16787 +Subproject commit f027d62e9388d1c8a0bb681a61c3ba1d0b76e2ae From 1a9e10d9542f0777e09a58832aecd65e0543ad9d Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 17:15:13 +0900 Subject: [PATCH 15/35] =?UTF-8?q?feat:=20=EC=95=B1=20=EB=B2=84=EC=A0=84?= =?UTF-8?q?=EC=9D=84=20=EC=A0=80=EC=9E=A5=ED=95=98=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../version/controller/VersionController.java | 15 ++++++++ .../version/service/VersionService.java | 37 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java index 7ebe4309..fb54a77f 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/controller/VersionController.java @@ -3,13 +3,17 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +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; +import com.coniverse.dangjang.domain.version.dto.request.VersionRequest; import com.coniverse.dangjang.domain.version.dto.response.VersionResponse; import com.coniverse.dangjang.domain.version.service.VersionService; import com.coniverse.dangjang.global.dto.SuccessSingleResponse; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; /** @@ -34,4 +38,15 @@ public ResponseEntity>> getIntro() { VersionResponse versionResponse = versionService.getVersionResponse(); return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), versionResponse)); } + + /** + * 버전 정보를 POST 요청한다. + * + * @since 1.3.0 + */ + @PostMapping + public ResponseEntity>> postVersion(@Valid @RequestBody VersionRequest request) { + VersionResponse versionResponse = versionService.saveVersion(request); + return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), versionResponse)); + } } diff --git a/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java b/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java index f158220d..0a034df7 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java @@ -1,7 +1,10 @@ package com.coniverse.dangjang.domain.version.service; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.coniverse.dangjang.domain.version.dto.request.VersionRequest; import com.coniverse.dangjang.domain.version.dto.response.VersionResponse; import com.coniverse.dangjang.domain.version.entity.Version; import com.coniverse.dangjang.domain.version.repository.VersionRepository; @@ -16,8 +19,11 @@ */ @Service @RequiredArgsConstructor +@Transactional public class VersionService { private final VersionRepository versionRepository; + @Value("${version.key}") + private String serverKey; /** * 가장 최근의 버전 정보를 반환한다. @@ -25,8 +31,39 @@ public class VersionService { * @return VersionResponse * @since 1.0.0 */ + @Transactional(readOnly = true) public VersionResponse getVersionResponse() { Version version = versionRepository.findFirstByOrderByCreatedAtDesc(); return new VersionResponse<>(version, null); } + + /** + * 버전 정보를 저장한다. + * + * @param request 버전 정보 + * @return VersionResponse + * @since 1.3.0 + */ + public VersionResponse saveVersion(VersionRequest request) { + validateKey(request.key()); + Version version = Version.builder() + .minVersion(request.minVersion()) + .latestVersion(request.latestVersion()) + .build(); + versionRepository.save(version); + return new VersionResponse<>(version, null); + } + + /** + * 버전 정보의 키 값을 확인한다. + * + * @param key 버전 키 + * @throws IllegalArgumentException 서버 키가 아닐 경우 + * @since 1.3.0 + */ + private void validateKey(String key) { + if (!key.equals(serverKey)) { + throw new IllegalArgumentException("올바르지 않은 키 값입니다."); + } + } } From 5641cb849ca6e6f18cba118ed3ba88806fc07208 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 17:17:59 +0900 Subject: [PATCH 16/35] feat: id auto increment --- .../coniverse/dangjang/domain/version/entity/Version.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java b/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java index 3c6f1870..34bed09e 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java @@ -3,6 +3,8 @@ import com.coniverse.dangjang.global.support.BaseEntity; import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import lombok.AccessLevel; import lombok.Builder; @@ -20,7 +22,8 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Version extends BaseEntity { @Id - private Long id; + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long versionId; private String minVersion; private String latestVersion; From f149c2067f39c7fb6e01a4cdc0e835febd7d5fa0 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 17:21:17 +0900 Subject: [PATCH 17/35] =?UTF-8?q?chore:=20version=20schema=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 --- src/main/resources/schema-dev.sql | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/resources/schema-dev.sql b/src/main/resources/schema-dev.sql index 50f2d073..4ff3636d 100644 --- a/src/main/resources/schema-dev.sql +++ b/src/main/resources/schema-dev.sql @@ -12,6 +12,7 @@ DROP TABLE IF EXISTS POINT_PRODUCT; DROP TABLE IF EXISTS USER_POINT; DROP TABLE IF EXISTS USERS; DROP TABLE IF EXISTS SHEDLOCK; +DROP TABLE IF EXISTS VERSION; CREATE TABLE `USERS` ( @@ -119,7 +120,7 @@ CREATE TABLE `PURCHASE_HISTORY` `CREATED_AT` dateTime NOT NULL, `PHONE` varchar(15) NOT NULL, `NAME` varchar(20) NOT NULL, - `COMMENT` varchar(255), + `COMMENT` varchar(255), `COMPLETED` boolean, PRIMARY KEY (`OAUTH_ID`, `PRODUCT_NAME`, `CREATED_AT`), FOREIGN KEY (`OAUTH_ID`) REFERENCES USERS (`OAUTH_ID`) ON DELETE CASCADE, @@ -144,7 +145,7 @@ CREATE TABLE `NOTIFICATION_TYPE` CREATE TABLE `NOTIFICATION` ( - `NOTIFICATION_ID` INT NOT NULL AUTO_INCREMENT, + `NOTIFICATION_ID` bigint NOT NULL AUTO_INCREMENT, `TITLE` varchar(255) NOT NULL, `CONTENT` varchar(255) NOT NULL, `OAUTH_ID` varchar(50) NOT NULL, @@ -156,10 +157,21 @@ CREATE TABLE `NOTIFICATION` FOREIGN KEY (`TYPE`) REFERENCES NOTIFICATION_TYPE (`TYPE`) ); -CREATE TABLE `SHEDLOCK` ( - `NAME` VARCHAR(64), - `LOCK_UNTIL` TIMESTAMP(3) NULL, - `LOCKED_AT` TIMESTAMP(3) NULL, - `LOCKED_BY` VARCHAR(255), - PRIMARY KEY (NAME) -) +CREATE TABLE `SHEDLOCK` +( + `NAME` VARCHAR(64), + `LOCK_UNTIL` TIMESTAMP(3) NULL, + `LOCKED_AT` TIMESTAMP(3) NULL, + `LOCKED_BY` VARCHAR(255), + PRIMARY KEY (NAME) +); + +CREATE TABLE `VERSION` +( + `VERSION_ID` bigint NOT NULL AUTO_INCREMENT, + `MIN_VERSION` varchar(10) NOT NULL, + `LATEST_VERSION` varchar(10) NOT NULL, + `CREATED_AT` datetime NOT NULL, + `UPDATED_AT` datetime NOT NULL, + PRIMARY KEY (`VERSION_ID`) +) \ No newline at end of file From 0331aa8452511f4943b7277c201a142643f9c08e Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 18:46:41 +0900 Subject: [PATCH 18/35] =?UTF-8?q?feat:=20created=5Fat=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=EB=A7=8C=20=EC=A1=B4=EC=9E=AC=ED=95=98=EB=8A=94=20base=20entit?= =?UTF-8?q?y=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/version/entity/Version.java | 4 +-- .../global/support/CreatedAtOnlyEntity.java | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/coniverse/dangjang/global/support/CreatedAtOnlyEntity.java diff --git a/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java b/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java index 34bed09e..e7a3113c 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java @@ -1,6 +1,6 @@ package com.coniverse.dangjang.domain.version.entity; -import com.coniverse.dangjang.global.support.BaseEntity; +import com.coniverse.dangjang.global.support.CreatedAtOnlyEntity; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -20,7 +20,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Version extends BaseEntity { +public class Version extends CreatedAtOnlyEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long versionId; diff --git a/src/main/java/com/coniverse/dangjang/global/support/CreatedAtOnlyEntity.java b/src/main/java/com/coniverse/dangjang/global/support/CreatedAtOnlyEntity.java new file mode 100644 index 00000000..1f38fac4 --- /dev/null +++ b/src/main/java/com/coniverse/dangjang/global/support/CreatedAtOnlyEntity.java @@ -0,0 +1,26 @@ +package com.coniverse.dangjang.global.support; + +import java.time.LocalDateTime; + +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import jakarta.persistence.Column; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import lombok.Getter; + +/** + * Entity 공통 매핑 정보 (CREATED_AT만 존재) + * + * @author TEO + * @since 1.3.0 + */ +@Getter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public class CreatedAtOnlyEntity { + @CreatedDate + @Column(name = "CREATED_AT", updatable = false, nullable = false) + private LocalDateTime createdAt; +} From 9ca2dd0f0d4bdcd9b63d1dc93c23ed749ecde191 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Thu, 26 Oct 2023 18:47:39 +0900 Subject: [PATCH 19/35] =?UTF-8?q?chore:=20schema=20=ED=8F=AC=EB=A7=B7=20?= =?UTF-8?q?=EC=88=98=EC=A0=95,=20not=20null=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/schema-dev.sql | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/resources/schema-dev.sql b/src/main/resources/schema-dev.sql index 4ff3636d..1fac6ad8 100644 --- a/src/main/resources/schema-dev.sql +++ b/src/main/resources/schema-dev.sql @@ -132,7 +132,7 @@ CREATE TABLE `USER_FCM_TOKEN` ( `OAUTH_ID` varchar(50) NOT NULL, `FCM_TOKEN` varchar(255) NOT NULL, - `CREATED_AT` dateTime NOT NULL, + `CREATED_AT` date NOT NULL, PRIMARY KEY (`FCM_TOKEN`), FOREIGN KEY (`OAUTH_ID`) REFERENCES USERS (`OAUTH_ID`) ON DELETE CASCADE ); @@ -159,10 +159,10 @@ CREATE TABLE `NOTIFICATION` CREATE TABLE `SHEDLOCK` ( - `NAME` VARCHAR(64), - `LOCK_UNTIL` TIMESTAMP(3) NULL, - `LOCKED_AT` TIMESTAMP(3) NULL, - `LOCKED_BY` VARCHAR(255), + `NAME` varchar(64) NOT NULL, + `LOCK_UNTIL` timestamp(3) NOT NULL, + `LOCKED_AT` timestamp(3) NOT NULL, + `LOCKED_BY` varchar(255) NOT NULL, PRIMARY KEY (NAME) ); @@ -172,6 +172,5 @@ CREATE TABLE `VERSION` `MIN_VERSION` varchar(10) NOT NULL, `LATEST_VERSION` varchar(10) NOT NULL, `CREATED_AT` datetime NOT NULL, - `UPDATED_AT` datetime NOT NULL, PRIMARY KEY (`VERSION_ID`) ) \ No newline at end of file From bd1d8f61af25c4fdd8cb8232d1d22f08827a4510 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 15:34:07 +0900 Subject: [PATCH 20/35] =?UTF-8?q?chore:=20test=EC=9A=A9=20schema=20symlink?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/schema.sql | 167 +--------------------------------- 1 file changed, 1 insertion(+), 166 deletions(-) mode change 100644 => 120000 src/test/resources/schema.sql diff --git a/src/test/resources/schema.sql b/src/test/resources/schema.sql deleted file mode 100644 index 31ad0ca8..00000000 --- a/src/test/resources/schema.sql +++ /dev/null @@ -1,166 +0,0 @@ -DROP TABLE IF EXISTS DISEASE; -DROP TABLE IF EXISTS NOTIFICATION_SETTING; -DROP TABLE IF EXISTS NOTIFICATION; -DROP TABLE IF EXISTS USER_FCM_TOKEN; -DROP TABLE IF EXISTS NOTIFICATION_TYPE; -DROP TABLE IF EXISTS DEVICE; -DROP TABLE IF EXISTS HEALTH_METRIC; --- DROP TABLE IF EXISTS CODE; -DROP TABLE IF EXISTS DANGJANG_CLUB; -DROP TABLE IF EXISTS POINT_HISTORY; -DROP TABLE IF EXISTS PURCHASE_HISTORY; -DROP TABLE IF EXISTS POINT_PRODUCT; -DROP TABLE IF EXISTS USER_POINT; -DROP TABLE IF EXISTS USERS; -DROP TABLE IF EXISTS SHEDLOCK; - -CREATE TABLE `USERS` -( - `OAUTH_ID` varchar(50) NOT NULL, - `NICKNAME` varchar(8) NOT NULL, - `OAUTH_PROVIDER` varchar(10) NOT NULL, - `GENDER` varchar(1) NOT NULL, - `BIRTHDAY` date NOT NULL, - `ACTIVITY_AMOUNT` varchar(10) NOT NULL, - `HEIGHT` int NOT NULL, - `ROLE` varchar(10) NOT NULL, - `RECOMMENDED_CALORIE` int NOT NULL, - `STATUS` varchar(10) NOT NULL, - `CREATED_AT` datetime NOT NULL, - `UPDATED_AT` datetime NOT NULL, - `PROFILE_IMAGE_PATH` varchar(255), - `DIABETIC` boolean NOT NULL, - `DIABETES_YEAR` int, - `MEDICINE` boolean, - `INJECTION` boolean, - `ACCESSED_AT` date NOT NULL, - `HEALTH_CONNECT` varchar(50) NOT NULL, - `INACTIVATED_AT` date, - PRIMARY KEY (`OAUTH_ID`), - UNIQUE (`NICKNAME`) -); - -CREATE TABLE `DANGJANG_CLUB` -( - `OAUTH_ID` varchar(50) NOT NULL, - `START_DATE` date NOT NULL, - PRIMARY KEY (`OAUTH_ID`), - FOREIGN KEY (`OAUTH_ID`) REFERENCES USERS (`OAUTH_ID`) -); - -CREATE TABLE `HEALTH_METRIC` -( - `OAUTH_ID` varchar(50) NOT NULL, - `CREATED_AT` date NOT NULL, - `TYPE` varchar(20) NOT NULL, - `GROUP_CODE` varchar(20) NOT NULL, - `UNIT` varchar(20) NOT NULL, - PRIMARY KEY (`OAUTH_ID`, `CREATED_AT`, `TYPE`), - FOREIGN KEY (`OAUTH_ID`) REFERENCES USERS (`OAUTH_ID`) -); - -CREATE TABLE `DEVICE` -( - `OAUTH_ID` varchar(50) NOT NULL, - `CODE` varchar(20) NOT NULL, - PRIMARY KEY (`OAUTH_ID`, `CODE`), - FOREIGN KEY (`OAUTH_ID`) REFERENCES USERS (`OAUTH_ID`) -); - -CREATE TABLE `NOTIFICATION_SETTING` -( - `OAUTH_ID` varchar(50) NOT NULL, - `CODE` varchar(20) NOT NULL, - PRIMARY KEY (`OAUTH_ID`, `CODE`), - FOREIGN KEY (`OAUTH_ID`) REFERENCES USERS (`OAUTH_ID`) -); - -CREATE TABLE `DISEASE` -( - `OAUTH_ID` varchar(50) NOT NULL, - `CODE` varchar(20) NOT NULL, - PRIMARY KEY (`OAUTH_ID`, `CODE`), - FOREIGN KEY (`OAUTH_ID`) REFERENCES USERS (`OAUTH_ID`) -); - -CREATE TABLE `POINT_PRODUCT` -( - `PRODUCT_NAME` varchar(255) NOT NULL, - `POINT` int, - `TYPE` varchar(20) NOT NULL, - `DESCRIPTION` varchar(255), - PRIMARY KEY (`PRODUCT_NAME`) -); - -CREATE TABLE `POINT_HISTORY` -( - `OAUTH_ID` varchar(50) NOT NULL, - `CREATED_AT` dateTime NOT NULL, - `PRODUCT_NAME` varchar(255) NOT NULL, - `CHANGE_POINT` int, - `BALANCE_POINT` int, - PRIMARY KEY (`OAUTH_ID`, `CREATED_AT`, `PRODUCT_NAME`), - FOREIGN KEY (`OAUTH_ID`) REFERENCES USERS (`OAUTH_ID`), - FOREIGN KEY (`PRODUCT_NAME`) REFERENCES POINT_PRODUCT (`PRODUCT_NAME`) -); - -CREATE TABLE `USER_POINT` -( - `OAUTH_ID` varchar(50) NOT NULL, - `POINT` int, - `VERSION` bigint, - PRIMARY KEY (`OAUTH_ID`), - FOREIGN KEY (`OAUTH_ID`) REFERENCES USERS (`OAUTH_ID`) -); - -CREATE TABLE `PURCHASE_HISTORY` -( - `OAUTH_ID` varchar(50) NOT NULL, - `PRODUCT_NAME` varchar(255) NOT NULL, - `CREATED_AT` dateTime NOT NULL, - `PHONE` varchar(20) NOT NULL, - `NAME` varchar(20) NOT NULL, - `COMMENT` varchar(255), - `COMPLETED` boolean, - PRIMARY KEY (`OAUTH_ID`, `PRODUCT_NAME`, `CREATED_AT`), - FOREIGN KEY (`OAUTH_ID`) REFERENCES USERS (`OAUTH_ID`), - FOREIGN KEY (`PRODUCT_NAME`) REFERENCES POINT_PRODUCT (`PRODUCT_NAME`) -); - - - -CREATE TABLE `USER_FCM_TOKEN` -( - `OAUTH_ID` varchar(50) NOT NULL, - `FCM_TOKEN` varchar(255) NOT NULL, - `CREATED_AT` dateTime NOT NULL, - PRIMARY KEY (`FCM_TOKEN`), - FOREIGN KEY (`OAUTH_ID`) REFERENCES USERS (`OAUTH_ID`) -); - -CREATE TABLE `NOTIFICATION_TYPE` -( - `TYPE` varchar(20) NOT NULL, - PRIMARY KEY (`TYPE`) -); - -CREATE TABLE `NOTIFICATION` -( - `NOTIFICATION_ID` INT NOT NULL AUTO_INCREMENT, - `TITLE` varchar(255) NOT NULL, - `CONTENT` varchar(255) NOT NULL, - `OAUTH_ID` varchar(50) NOT NULL, - `TYPE` varchar(20) NOT NULL, - `CREATED_AT` dateTime NOT NULL, - `IS_READ` boolean NOT NULL, - PRIMARY KEY (`NOTIFICATION_ID`), - FOREIGN KEY (`OAUTH_ID`) REFERENCES USERS (`OAUTH_ID`), - FOREIGN KEY (`TYPE`) REFERENCES NOTIFICATION_TYPE (`TYPE`) -); -CREATE TABLE `SHEDLOCK` ( - `NAME` VARCHAR(64), - `LOCK_UNTIL` TIMESTAMP(3) NULL, - `LOCKED_AT` TIMESTAMP(3) NULL, - `LOCKED_BY` VARCHAR(255), - PRIMARY KEY (NAME) -) \ No newline at end of file diff --git a/src/test/resources/schema.sql b/src/test/resources/schema.sql new file mode 120000 index 00000000..7e7f2325 --- /dev/null +++ b/src/test/resources/schema.sql @@ -0,0 +1 @@ +../../main/resources/schema-dev.sql \ No newline at end of file From 72879c26d37af346fafe9d5bd4f0d08954709921 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 17:01:27 +0900 Subject: [PATCH 21/35] =?UTF-8?q?fix:=20Version=20PK=20createdAt=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dangjang/domain/version/entity/Version.java | 15 +++++++++------ src/main/resources/schema-dev.sql | 7 +++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java b/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java index e7a3113c..0adae6a0 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/entity/Version.java @@ -1,10 +1,12 @@ package com.coniverse.dangjang.domain.version.entity; -import com.coniverse.dangjang.global.support.CreatedAtOnlyEntity; +import java.time.LocalDateTime; + +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; +import jakarta.persistence.EntityListeners; import jakarta.persistence.Id; import lombok.AccessLevel; import lombok.Builder; @@ -20,10 +22,11 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Version extends CreatedAtOnlyEntity { +@EntityListeners(AuditingEntityListener.class) +public class Version { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long versionId; + @CreatedDate + private LocalDateTime createdAt; private String minVersion; private String latestVersion; diff --git a/src/main/resources/schema-dev.sql b/src/main/resources/schema-dev.sql index 1fac6ad8..6d5e2fd6 100644 --- a/src/main/resources/schema-dev.sql +++ b/src/main/resources/schema-dev.sql @@ -168,9 +168,8 @@ CREATE TABLE `SHEDLOCK` CREATE TABLE `VERSION` ( - `VERSION_ID` bigint NOT NULL AUTO_INCREMENT, + `CREATED_AT` datetime NOT NULL, `MIN_VERSION` varchar(10) NOT NULL, `LATEST_VERSION` varchar(10) NOT NULL, - `CREATED_AT` datetime NOT NULL, - PRIMARY KEY (`VERSION_ID`) -) \ No newline at end of file + PRIMARY KEY (`CREATED_AT`) +); From c6d9affd15381380387543f4ccbd84f1f6e64b08 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 17:01:45 +0900 Subject: [PATCH 22/35] =?UTF-8?q?chore:=20data.sql=20version=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 --- src/main/resources/data-dev.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/resources/data-dev.sql b/src/main/resources/data-dev.sql index 2ac9cccc..8fc7fe73 100644 --- a/src/main/resources/data-dev.sql +++ b/src/main/resources/data-dev.sql @@ -44,3 +44,6 @@ VALUES ("11111111", "fcmToken1", '2023-10-08'), -- ("체중 기록!", "오늘 체중을 기록해보세요 ~ ", '2023-10-08', "기록", "22222222", true), -- ("접속해주세요!", "오늘은 접속 안하셨네요 ~ 접속해서 포인트 받아가세요", '2023-10-09', "접속", "22222222", false), -- ("운동 기록 !", "오늘 운동을 기록해보세요 ~ ", '2023-10-10', "기록", "11111111", false); + +INSERT INTO version(created_at, min_version, latest_version) +VALUES (now(), "1.0.0", "1.0.0"); \ No newline at end of file From 5c3407a90a04546b8b9c1a21f9dcc0cc00dfc503 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 17:02:33 +0900 Subject: [PATCH 23/35] =?UTF-8?q?refactor:=20@Value=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=20=EC=A3=BC=EC=9E=85=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lombok.config | 1 + .../dangjang/domain/version/service/VersionService.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 src/lombok.config diff --git a/src/lombok.config b/src/lombok.config new file mode 100644 index 00000000..2c6905d7 --- /dev/null +++ b/src/lombok.config @@ -0,0 +1 @@ +lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Value diff --git a/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java b/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java index 0a034df7..73ffdad8 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/service/VersionService.java @@ -23,7 +23,7 @@ public class VersionService { private final VersionRepository versionRepository; @Value("${version.key}") - private String serverKey; + private final String serverKey; /** * 가장 최근의 버전 정보를 반환한다. From 13550f91f7e6833cb69481751a152da8b1cbb2b5 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 17:02:58 +0900 Subject: [PATCH 24/35] =?UTF-8?q?chore:=20test=20yml=EC=97=90=20key=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/config/application.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/resources/config/application.yml b/src/test/resources/config/application.yml index d9714a2b..43d09e5a 100644 --- a/src/test/resources/config/application.yml +++ b/src/test/resources/config/application.yml @@ -47,9 +47,9 @@ jwt: exp: 3600000 fluentbit: - app-log-url: http://localhost:8888/app.log - server-log-url: http://localhost:8888/server.log - notification-url: http://localhost:8888/notification + app-log-url: http://localhost:1234/app.log + server-log-url: http://localhost:1234/server.log + notification-url: http://localhost:1234/notification cors: allowed-origins: "*" @@ -62,6 +62,9 @@ oauth: url: api: https://openapi.naver.com +version: + key: "1234" + logging: level: org: From 127432af9296b90e5c94dfaee69932d82a40ee27 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 17:03:31 +0900 Subject: [PATCH 25/35] =?UTF-8?q?feat:=20version=20fixture=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 --- .../dangjang/fixture/VersionFixture.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/test/java/com/coniverse/dangjang/fixture/VersionFixture.java diff --git a/src/test/java/com/coniverse/dangjang/fixture/VersionFixture.java b/src/test/java/com/coniverse/dangjang/fixture/VersionFixture.java new file mode 100644 index 00000000..f7b54072 --- /dev/null +++ b/src/test/java/com/coniverse/dangjang/fixture/VersionFixture.java @@ -0,0 +1,42 @@ +package com.coniverse.dangjang.fixture; + +import com.coniverse.dangjang.domain.version.dto.request.VersionRequest; +import com.coniverse.dangjang.domain.version.dto.response.VersionResponse; +import com.coniverse.dangjang.domain.version.entity.Version; + +/** + * @author TEO + * @since 1.3.0 + */ +public class VersionFixture { + public static Version 버전_엔티티() { + return getVersion("1.0.0", "1.0.0"); + } + + public static Version 버전_엔티티(String minVersion, String latestVersion) { + return getVersion(minVersion, latestVersion); + } + + private static Version getVersion(String minVersion, String latestVersion) { + return Version.builder() + .minVersion(minVersion) + .latestVersion(latestVersion) + .build(); + } + + public static VersionRequest 버전_요청() { + return getVersionRequest("1.0.0", "1.0.0", "1234"); + } + + public static VersionRequest 버전_요청(String minVersion, String latestVersion, String key) { + return getVersionRequest(minVersion, latestVersion, key); + } + + private static VersionRequest getVersionRequest(String minVersion, String latestVersion, String key) { + return new VersionRequest(minVersion, latestVersion, key); + } + + public static VersionResponse 버전_응답() { + return new VersionResponse<>("1.0.0", "1.0.0", null); + } +} From bad1ac0aee6fee168aa2692b358c9f245052fec1 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 17:03:49 +0900 Subject: [PATCH 26/35] test: version repository unit test --- .../repository/VersionRepositoryTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/test/java/com/coniverse/dangjang/domain/version/repository/VersionRepositoryTest.java diff --git a/src/test/java/com/coniverse/dangjang/domain/version/repository/VersionRepositoryTest.java b/src/test/java/com/coniverse/dangjang/domain/version/repository/VersionRepositoryTest.java new file mode 100644 index 00000000..73be2734 --- /dev/null +++ b/src/test/java/com/coniverse/dangjang/domain/version/repository/VersionRepositoryTest.java @@ -0,0 +1,46 @@ +package com.coniverse.dangjang.domain.version.repository; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.List; +import java.util.stream.IntStream; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import com.coniverse.dangjang.domain.version.entity.Version; +import com.coniverse.dangjang.support.annotation.JpaRepositoryTest; + +/** + * @author TEO + * @since 1.3.0 + */ +@JpaRepositoryTest +public class VersionRepositoryTest { + @Autowired + private VersionRepository versionRepository; + + @Test + void 가장_최근의_버전_정보를_반환한다() { + // given + int count = 30; + List versions = IntStream.rangeClosed(1, count) + .mapToObj(i -> Version.builder() + .minVersion("1.0." + i) + .latestVersion("1.0." + i) + .build() + ) + .toList(); + versionRepository.saveAll(versions); + + // when + Version version = versionRepository.findFirstByOrderByCreatedAtDesc(); + + // then + assertAll( + () -> assertThat(version.getMinVersion()).isEqualTo("1.0." + count), + () -> assertThat(version.getLatestVersion()).isEqualTo("1.0." + count) + ); + } +} From 54b7a60a3955aa55b9bfeea073e8cdc6847ac08f Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 17:04:06 +0900 Subject: [PATCH 27/35] test: version service unit test --- .../version/service/VersionServiceTest.java | 74 +++++++++++++++---- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java b/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java index 9e2fdefe..7ded9d28 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java @@ -1,32 +1,76 @@ package com.coniverse.dangjang.domain.version.service; +import static com.coniverse.dangjang.fixture.VersionFixture.*; import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; -import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; +import org.mockito.Mockito; +import com.coniverse.dangjang.domain.version.dto.request.VersionRequest; import com.coniverse.dangjang.domain.version.dto.response.VersionResponse; +import com.coniverse.dangjang.domain.version.entity.Version; +import com.coniverse.dangjang.domain.version.repository.VersionRepository; /** * @author TEO - * @since 1.0.0 + * @since 1.3.0 */ -@SpringBootTest class VersionServiceTest { - @Autowired private VersionService versionService; + private VersionRepository versionRepository; + private static final String KEY = "1234"; - @Nested - class ProdIntroResponse를 { - @Test - void 호출하면_IntroResponse가_반환된다() { - // when - VersionResponse versionResponse = versionService.getVersionResponse(); + @BeforeEach + void setUp() { + versionRepository = Mockito.mock(VersionRepository.class); + versionService = new VersionService(versionRepository, KEY); + } + + @Test + void 버전_응답을_반환한다() { + // given + String minVersion = "1.0.1"; + String latestVersion = "1.0.1"; + Version version = 버전_엔티티(minVersion, latestVersion); + doReturn(version).when(versionRepository).findFirstByOrderByCreatedAtDesc(); + + // when + VersionResponse versionResponse = versionService.getVersionResponse(); + + // then + assertThat(versionResponse.minVersion()).isEqualTo(minVersion); + assertThat(versionResponse.latestVersion()).isEqualTo(latestVersion); + } + + @Test + void 키가_같으면_버전을_성공적으로_저장한다() { + // given + String minVersion = "1.0.1"; + String latestVersion = "1.0.1"; + doReturn(null) + .when(versionRepository) + .save(any()); + VersionRequest versionRequest = 버전_요청(minVersion, latestVersion, KEY); + + // when + VersionResponse versionResponse = versionService.saveVersion(versionRequest); + + // then + assertThat(versionResponse.minVersion()).isEqualTo(minVersion); + assertThat(versionResponse.latestVersion()).isEqualTo(latestVersion); + } + + @Test + void 키가_다르면_예외가_발생한다() { + // given + String minVersion = "1.0.1"; + String latestVersion = "1.0.1"; + VersionRequest versionRequest = 버전_요청(minVersion, latestVersion, "wrong key"); - // then - assertThat(versionResponse).isNotNull(); - } + // when + assertThatThrownBy(() -> versionService.saveVersion(versionRequest)) + .isInstanceOf(IllegalArgumentException.class); } } From 1b32321bceea60b3d26db7f528546c792affcb37 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 17:04:17 +0900 Subject: [PATCH 28/35] test: version controller unit test --- .../controller/VersionControllerTest.java | 62 ++++++++++++------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java index 8e8970a3..0e7223bd 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java @@ -1,47 +1,65 @@ package com.coniverse.dangjang.domain.version.controller; +import static com.coniverse.dangjang.fixture.VersionFixture.*; import static com.coniverse.dangjang.support.SimpleMockMvc.*; import static org.mockito.BDDMockito.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.test.web.servlet.ResultActions; +import com.coniverse.dangjang.domain.version.dto.request.VersionRequest; import com.coniverse.dangjang.domain.version.dto.response.VersionResponse; import com.coniverse.dangjang.domain.version.service.VersionService; import com.coniverse.dangjang.support.ControllerTest; /** * @author TEO - * @since 1.0.0 + * @since 1.3.0 */ class VersionControllerTest extends ControllerTest { - private static final String URI = "/api/intro"; + private static final String URI = "/api/version"; @Autowired private VersionService versionService; - @Nested - class Prod_Intro_URL에_접근시 { - @Test - void 성공한_응답을_반환한다() throws Exception { - // given - VersionResponse versionResponse = new VersionResponse<>(MIN_VERSION, LATEST_VERSION, null); - given(versionService.getVersionResponse()).willReturn(versionResponse); - - // when - ResultActions resultActions = get(mockMvc, URI + "/prod"); - - // then - resultActions.andExpectAll( - status().isOk(), - jsonPath("$.message").value(HttpStatus.OK.getReasonPhrase()), - jsonPath("$.data.minVersion").value(versionResponse.minVersion()), - jsonPath("$.data.latestVersion").value(versionResponse.latestVersion()) - ); - } + @Test + void 앱_버전을_GET_요청하면_성공한_응답을_반환한다() throws Exception { + // given + VersionResponse versionResponse = 버전_응답(); + doReturn(versionResponse).when(versionService).getVersionResponse(); + + // when + ResultActions resultActions = get(mockMvc, URI + "/intro"); + + // then + resultActions.andExpectAll( + status().isOk(), + jsonPath("$.message").value(HttpStatus.OK.getReasonPhrase()), + jsonPath("$.data.minVersion").value(versionResponse.minVersion()), + jsonPath("$.data.latestVersion").value(versionResponse.latestVersion()) + ); + } + + @Test + void 앱_버전을_POST_요청하면_성공한_응답을_반환한다() throws Exception { + // given + VersionRequest versionRequest = 버전_요청(); + String content = objectMapper.writeValueAsString(versionRequest); + VersionResponse versionResponse = 버전_응답(); + doReturn(versionResponse).when(versionService).saveVersion(any()); + + // when + ResultActions resultActions = post(mockMvc, URI, content); + + // then + resultActions.andExpectAll( + status().isOk(), + jsonPath("$.message").value(HttpStatus.OK.getReasonPhrase()), + jsonPath("$.data.minVersion").value(versionResponse.minVersion()), + jsonPath("$.data.latestVersion").value(versionResponse.latestVersion()) + ); } } From ee8fccff2fee279e66f9c9841eefcf3d2fc3c0f8 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 17:13:02 +0900 Subject: [PATCH 29/35] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/support/CreatedAtOnlyEntity.java | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 src/main/java/com/coniverse/dangjang/global/support/CreatedAtOnlyEntity.java diff --git a/src/main/java/com/coniverse/dangjang/global/support/CreatedAtOnlyEntity.java b/src/main/java/com/coniverse/dangjang/global/support/CreatedAtOnlyEntity.java deleted file mode 100644 index 1f38fac4..00000000 --- a/src/main/java/com/coniverse/dangjang/global/support/CreatedAtOnlyEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.coniverse.dangjang.global.support; - -import java.time.LocalDateTime; - -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import jakarta.persistence.Column; -import jakarta.persistence.EntityListeners; -import jakarta.persistence.MappedSuperclass; -import lombok.Getter; - -/** - * Entity 공통 매핑 정보 (CREATED_AT만 존재) - * - * @author TEO - * @since 1.3.0 - */ -@Getter -@MappedSuperclass -@EntityListeners(AuditingEntityListener.class) -public class CreatedAtOnlyEntity { - @CreatedDate - @Column(name = "CREATED_AT", updatable = false, nullable = false) - private LocalDateTime createdAt; -} From 8d7264498789243d92bcae1c5ce8e87baacdc2b0 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 17:32:25 +0900 Subject: [PATCH 30/35] =?UTF-8?q?refactor:=20fixture=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/version/repository/VersionRepositoryTest.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/coniverse/dangjang/domain/version/repository/VersionRepositoryTest.java b/src/test/java/com/coniverse/dangjang/domain/version/repository/VersionRepositoryTest.java index 73be2734..4224ee04 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/repository/VersionRepositoryTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/repository/VersionRepositoryTest.java @@ -1,5 +1,6 @@ package com.coniverse.dangjang.domain.version.repository; +import static com.coniverse.dangjang.fixture.VersionFixture.*; import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*; @@ -26,11 +27,7 @@ public class VersionRepositoryTest { // given int count = 30; List versions = IntStream.rangeClosed(1, count) - .mapToObj(i -> Version.builder() - .minVersion("1.0." + i) - .latestVersion("1.0." + i) - .build() - ) + .mapToObj(i -> 버전_엔티티("1.0." + i, "1.0." + i)) .toList(); versionRepository.saveAll(versions); From ed96a1f348ea1f05bbbd43e865b22a6cf70ce4da Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 17:56:55 +0900 Subject: [PATCH 31/35] =?UTF-8?q?feat:=20=EC=A0=95=EA=B7=9C=EC=8B=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dangjang/domain/version/dto/request/VersionRequest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/coniverse/dangjang/domain/version/dto/request/VersionRequest.java b/src/main/java/com/coniverse/dangjang/domain/version/dto/request/VersionRequest.java index d5eed2d0..9b711bb5 100644 --- a/src/main/java/com/coniverse/dangjang/domain/version/dto/request/VersionRequest.java +++ b/src/main/java/com/coniverse/dangjang/domain/version/dto/request/VersionRequest.java @@ -1,6 +1,7 @@ package com.coniverse.dangjang.domain.version.dto.request; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; /** * 앱 버전 post dto @@ -8,5 +9,6 @@ * @author TEO * @since 1.3.0 */ -public record VersionRequest(@NotBlank String minVersion, @NotBlank String latestVersion, @NotBlank String key) { +public record VersionRequest(@NotBlank @Pattern(regexp = "^\\d\\.\\d\\.\\d$") String minVersion, + @NotBlank @Pattern(regexp = "^\\d\\.\\d\\.\\d$") String latestVersion, @NotBlank String key) { } From 7c3f69494dca7d558c9953031df057b1d7412c4b Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 17:59:43 +0900 Subject: [PATCH 32/35] test: request body validation test --- .../controller/VersionControllerTest.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java index 0e7223bd..3aee4994 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/controller/VersionControllerTest.java @@ -6,6 +6,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.test.web.servlet.ResultActions; @@ -62,4 +64,61 @@ class VersionControllerTest extends ControllerTest { jsonPath("$.data.latestVersion").value(versionResponse.latestVersion()) ); } + + @ParameterizedTest + @ValueSource(strings = {"", " ", "1/1/1", "1.1.0 ", " 1.0.1"}) + void RequestBody의_minVersion이_잘못됐을_경우_실패한_응답을_반환한다(String minVersion) throws Exception { + // given + VersionRequest versionRequest = 버전_요청(minVersion, "1.0.1", "1234"); + String content = objectMapper.writeValueAsString(versionRequest); + + // when + ResultActions resultActions = post(mockMvc, URI, content); + + // then + resultActions.andExpectAll( + status().isBadRequest(), + jsonPath("$.errorCode").value(400), + jsonPath("$.fieldErrors[0].field").value("minVersion"), + jsonPath("$.fieldErrors[0].rejectedValue").value(minVersion) + ); + } + + @ParameterizedTest + @ValueSource(strings = {"", " ", "1/1/1", "1.1.0 ", " 1.0.1"}) + void RequestBody의_latestVersion이_잘못됐을_경우_실패한_응답을_반환한다(String latestVersion) throws Exception { + // given + VersionRequest versionRequest = 버전_요청("1.0.1", latestVersion, "1234"); + String content = objectMapper.writeValueAsString(versionRequest); + + // when + ResultActions resultActions = post(mockMvc, URI, content); + + // then + resultActions.andExpectAll( + status().isBadRequest(), + jsonPath("$.errorCode").value(400), + jsonPath("$.fieldErrors[0].field").value("latestVersion"), + jsonPath("$.fieldErrors[0].rejectedValue").value(latestVersion) + ); + } + + @ParameterizedTest + @ValueSource(strings = {"", " ", "\n"}) + void RequestBody의_key가_잘못됐을_경우_실패한_응답을_반환한다(String key) throws Exception { + // given + VersionRequest versionRequest = 버전_요청("1.0.1", "1.0.1", key); + String content = objectMapper.writeValueAsString(versionRequest); + + // when + ResultActions resultActions = post(mockMvc, URI, content); + + // then + resultActions.andExpectAll( + status().isBadRequest(), + jsonPath("$.errorCode").value(400), + jsonPath("$.fieldErrors[0].field").value("key"), + jsonPath("$.fieldErrors[0].rejectedValue").value(key) + ); + } } From a240e712f6f6747143bc73891941bde5e64e6214 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 18:06:57 +0900 Subject: [PATCH 33/35] =?UTF-8?q?refactor:=20public=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/version/repository/VersionRepositoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/coniverse/dangjang/domain/version/repository/VersionRepositoryTest.java b/src/test/java/com/coniverse/dangjang/domain/version/repository/VersionRepositoryTest.java index 4224ee04..4b3cf24c 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/repository/VersionRepositoryTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/repository/VersionRepositoryTest.java @@ -18,7 +18,7 @@ * @since 1.3.0 */ @JpaRepositoryTest -public class VersionRepositoryTest { +class VersionRepositoryTest { @Autowired private VersionRepository versionRepository; From b935ecef703d1c28ed46ba059eb7cde8cf6e1da5 Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 18:08:44 +0900 Subject: [PATCH 34/35] =?UTF-8?q?refactor:=20=EC=83=81=EC=88=98=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../version/service/VersionServiceTest.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java b/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java index 7ded9d28..7b625cd3 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java @@ -21,6 +21,8 @@ class VersionServiceTest { private VersionService versionService; private VersionRepository versionRepository; private static final String KEY = "1234"; + private static final String MIN_VERSION = "1.3.1"; + private static final String LATEST_VERSION = "1.3.1"; @BeforeEach void setUp() { @@ -31,43 +33,37 @@ void setUp() { @Test void 버전_응답을_반환한다() { // given - String minVersion = "1.0.1"; - String latestVersion = "1.0.1"; - Version version = 버전_엔티티(minVersion, latestVersion); + Version version = 버전_엔티티(MIN_VERSION, LATEST_VERSION); doReturn(version).when(versionRepository).findFirstByOrderByCreatedAtDesc(); // when VersionResponse versionResponse = versionService.getVersionResponse(); // then - assertThat(versionResponse.minVersion()).isEqualTo(minVersion); - assertThat(versionResponse.latestVersion()).isEqualTo(latestVersion); + assertThat(versionResponse.minVersion()).isEqualTo(MIN_VERSION); + assertThat(versionResponse.latestVersion()).isEqualTo(LATEST_VERSION); } @Test void 키가_같으면_버전을_성공적으로_저장한다() { // given - String minVersion = "1.0.1"; - String latestVersion = "1.0.1"; doReturn(null) .when(versionRepository) .save(any()); - VersionRequest versionRequest = 버전_요청(minVersion, latestVersion, KEY); + VersionRequest versionRequest = 버전_요청(MIN_VERSION, LATEST_VERSION, KEY); // when VersionResponse versionResponse = versionService.saveVersion(versionRequest); // then - assertThat(versionResponse.minVersion()).isEqualTo(minVersion); - assertThat(versionResponse.latestVersion()).isEqualTo(latestVersion); + assertThat(versionResponse.minVersion()).isEqualTo(MIN_VERSION); + assertThat(versionResponse.latestVersion()).isEqualTo(LATEST_VERSION); } @Test void 키가_다르면_예외가_발생한다() { // given - String minVersion = "1.0.1"; - String latestVersion = "1.0.1"; - VersionRequest versionRequest = 버전_요청(minVersion, latestVersion, "wrong key"); + VersionRequest versionRequest = 버전_요청(MIN_VERSION, LATEST_VERSION, "wrong key"); // when assertThatThrownBy(() -> versionService.saveVersion(versionRequest)) From 82837771d7caa6e6dd7345f992b79a2eb6abefdb Mon Sep 17 00:00:00 2001 From: NAM GIBEOM Date: Fri, 27 Oct 2023 18:09:17 +0900 Subject: [PATCH 35/35] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC=EC=B2=B4=EC=A0=81?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dangjang/domain/version/service/VersionServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java b/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java index 7b625cd3..940fb3f3 100644 --- a/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java +++ b/src/test/java/com/coniverse/dangjang/domain/version/service/VersionServiceTest.java @@ -61,7 +61,7 @@ void setUp() { } @Test - void 키가_다르면_예외가_발생한다() { + void 키가_다르면_버전을_저장할_때_예외가_발생한다() { // given VersionRequest versionRequest = 버전_요청(MIN_VERSION, LATEST_VERSION, "wrong key");