From da1bd599cdbd495134063c4071b612293e52a80c Mon Sep 17 00:00:00 2001 From: Arachneee Date: Wed, 24 Jul 2024 20:15:31 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=EC=A7=80=EC=B6=9C=20=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20=EC=83=9D=EC=84=B1=20=EC=98=88=EC=99=B8=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/server/haengdong/domain/action/BillAction.java | 6 ++++-- .../server/haengdong/exception/HaengdongErrorCode.java | 2 ++ .../presentation/request/BillActionSaveRequest.java | 7 ++----- .../server/haengdong/domain/action/BillActionTest.java | 5 +++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/server/haengdong/domain/action/BillAction.java b/server/src/main/java/server/haengdong/domain/action/BillAction.java index f0e82c409..e74ea499d 100644 --- a/server/src/main/java/server/haengdong/domain/action/BillAction.java +++ b/server/src/main/java/server/haengdong/domain/action/BillAction.java @@ -11,6 +11,8 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import server.haengdong.exception.HaengdongErrorCode; +import server.haengdong.exception.HaengdongException; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -45,13 +47,13 @@ public BillAction(Action action, String title, Long price) { private void validateTitle(String title) { int titleLength = title.trim().length(); if (titleLength < MIN_TITLE_LENGTH || titleLength > MAX_TITLE_LENGTH) { - throw new IllegalArgumentException("앞뒤 공백을 제거한 지출 내역 제목은 2 ~ 30자여야 합니다."); + throw new HaengdongException(HaengdongErrorCode.INVALID_BILL_ACTION_SIZE); } } private void validatePrice(Long price) { if (price < MIN_PRICE || price > MAX_PRICE) { - throw new IllegalArgumentException("지출 금액은 10,000,000 이하의 자연수여야 합니다."); + throw new HaengdongException(HaengdongErrorCode.INVALID_PRICE_SIZE); } } diff --git a/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java b/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java index 792baa838..9b1d66370 100644 --- a/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java +++ b/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java @@ -8,6 +8,8 @@ public enum HaengdongErrorCode { BAD_REQUEST(HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), DUPLICATED_MEMBER_ACTION(HttpStatus.BAD_REQUEST, "올바르지 않은 인원 요청입니다."), INVALID_MEMBER_ACTION(HttpStatus.BAD_REQUEST, "잘못된 맴버 액션입니다."), + INVALID_BILL_ACTION_SIZE(HttpStatus.BAD_REQUEST, "앞뒤 공백을 제거한 지출 내역 제목은 2 ~ 30자여야 합니다."), + INVALID_PRICE_SIZE(HttpStatus.BAD_REQUEST, "지출 금액은 10,000,000 이하의 자연수여야 합니다."), NOT_FOUND_EVENT(HttpStatus.NOT_FOUND, "존재하지 않는 행사입니다."), diff --git a/server/src/main/java/server/haengdong/presentation/request/BillActionSaveRequest.java b/server/src/main/java/server/haengdong/presentation/request/BillActionSaveRequest.java index 8d662050f..cfdef0f01 100644 --- a/server/src/main/java/server/haengdong/presentation/request/BillActionSaveRequest.java +++ b/server/src/main/java/server/haengdong/presentation/request/BillActionSaveRequest.java @@ -1,18 +1,15 @@ package server.haengdong.presentation.request; +import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Positive; -import jakarta.validation.constraints.Size; import server.haengdong.application.request.BillActionAppRequest; public record BillActionSaveRequest( - @NotNull - @Size(min = 2, max = 30) + @NotEmpty String title, @NotNull - @Positive Long price ) { diff --git a/server/src/test/java/server/haengdong/domain/action/BillActionTest.java b/server/src/test/java/server/haengdong/domain/action/BillActionTest.java index d179ca6eb..601ca95d7 100644 --- a/server/src/test/java/server/haengdong/domain/action/BillActionTest.java +++ b/server/src/test/java/server/haengdong/domain/action/BillActionTest.java @@ -9,6 +9,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import server.haengdong.domain.event.Event; +import server.haengdong.exception.HaengdongException; class BillActionTest { @@ -21,7 +22,7 @@ void validateTitle(String title) { Long price = 100L; assertThatThrownBy(() -> new BillAction(action, title, price)) - .isInstanceOf(IllegalArgumentException.class) + .isInstanceOf(HaengdongException.class) .hasMessage("앞뒤 공백을 제거한 지출 내역 제목은 2 ~ 30자여야 합니다."); } @@ -34,7 +35,7 @@ void validatePrice(long price) { String title = "title"; assertThatThrownBy(() -> new BillAction(action, title, price)) - .isInstanceOf(IllegalArgumentException.class) + .isInstanceOf(HaengdongException.class) .hasMessage("지출 금액은 10,000,000 이하의 자연수여야 합니다."); } From 4d3c9e73315796d0ddf0a7361d51b66f842310ab Mon Sep 17 00:00:00 2001 From: Arachneee Date: Wed, 24 Jul 2024 21:37:58 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20=ED=98=84=EC=9E=AC=20=EC=9D=B8?= =?UTF-8?q?=EC=9B=90=20=EC=A1=B0=ED=9A=8C=20=EC=98=88=EC=99=B8=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/haengdong/application/MemberActionService.java | 4 +++- .../presentation/request/BillActionSaveRequest.java | 4 ++-- .../haengdong/application/MemberActionServiceTest.java | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/server/haengdong/application/MemberActionService.java b/server/src/main/java/server/haengdong/application/MemberActionService.java index ba17b28c4..5094bf2c0 100644 --- a/server/src/main/java/server/haengdong/application/MemberActionService.java +++ b/server/src/main/java/server/haengdong/application/MemberActionService.java @@ -13,6 +13,8 @@ import server.haengdong.domain.action.MemberActionRepository; import server.haengdong.domain.event.Event; import server.haengdong.domain.event.EventRepository; +import server.haengdong.exception.HaengdongErrorCode; +import server.haengdong.exception.HaengdongException; @RequiredArgsConstructor @Transactional(readOnly = true) @@ -53,6 +55,6 @@ public List getCurrentMembers(String token) { private Event findEvent(String token) { return eventRepository.findByToken(token) - .orElseThrow(() -> new IllegalArgumentException("event not found")); + .orElseThrow(() -> new HaengdongException(HaengdongErrorCode.NOT_FOUND_EVENT)); } } diff --git a/server/src/main/java/server/haengdong/presentation/request/BillActionSaveRequest.java b/server/src/main/java/server/haengdong/presentation/request/BillActionSaveRequest.java index cfdef0f01..a0d878f7f 100644 --- a/server/src/main/java/server/haengdong/presentation/request/BillActionSaveRequest.java +++ b/server/src/main/java/server/haengdong/presentation/request/BillActionSaveRequest.java @@ -1,12 +1,12 @@ package server.haengdong.presentation.request; -import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import server.haengdong.application.request.BillActionAppRequest; public record BillActionSaveRequest( - @NotEmpty + @NotBlank String title, @NotNull diff --git a/server/src/test/java/server/haengdong/application/MemberActionServiceTest.java b/server/src/test/java/server/haengdong/application/MemberActionServiceTest.java index 378aa6006..7212e300d 100644 --- a/server/src/test/java/server/haengdong/application/MemberActionServiceTest.java +++ b/server/src/test/java/server/haengdong/application/MemberActionServiceTest.java @@ -19,6 +19,7 @@ import server.haengdong.domain.action.MemberActionRepository; import server.haengdong.domain.event.Event; import server.haengdong.domain.event.EventRepository; +import server.haengdong.exception.HaengdongException; @SpringBootTest class MemberActionServiceTest { @@ -79,13 +80,13 @@ void saveMemberActionTest2() { List.of(new MemberActionSaveAppRequest("TOKEN", "OUT"))); assertThatCode(() -> memberActionService.saveMemberAction("TOKEN", appRequest)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(HaengdongException.class); } @DisplayName("이벤트가 없으면 현재 참여 인원을 조회할 수 없다.") @Test void getCurrentMembers() { assertThatThrownBy(() -> memberActionService.getCurrentMembers("token")) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(HaengdongException.class); } } From d334b0b9c40bf86f000603c97b564e39a0360eeb Mon Sep 17 00:00:00 2001 From: Arachneee Date: Thu, 25 Jul 2024 09:54:10 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=EC=98=88=EC=99=B8=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=A0=84=EB=8B=AC=20=EB=B0=A9=EB=B2=95=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 --- .../java/server/haengdong/domain/action/BillAction.java | 6 ++++-- .../java/server/haengdong/exception/HaengdongErrorCode.java | 2 -- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/server/haengdong/domain/action/BillAction.java b/server/src/main/java/server/haengdong/domain/action/BillAction.java index e74ea499d..1027206f5 100644 --- a/server/src/main/java/server/haengdong/domain/action/BillAction.java +++ b/server/src/main/java/server/haengdong/domain/action/BillAction.java @@ -47,13 +47,15 @@ public BillAction(Action action, String title, Long price) { private void validateTitle(String title) { int titleLength = title.trim().length(); if (titleLength < MIN_TITLE_LENGTH || titleLength > MAX_TITLE_LENGTH) { - throw new HaengdongException(HaengdongErrorCode.INVALID_BILL_ACTION_SIZE); + throw new HaengdongException(HaengdongErrorCode.BAD_REQUEST, + String.format("앞뒤 공백을 제거한 지출 내역 제목은 %d ~ %d자여야 합니다.", MIN_TITLE_LENGTH, MAX_TITLE_LENGTH)); } } private void validatePrice(Long price) { if (price < MIN_PRICE || price > MAX_PRICE) { - throw new HaengdongException(HaengdongErrorCode.INVALID_PRICE_SIZE); + throw new HaengdongException(HaengdongErrorCode.BAD_REQUEST, + String.format("지출 금액은 %,d 이하의 자연수여야 합니다.", MAX_PRICE)); } } diff --git a/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java b/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java index 9b1d66370..792baa838 100644 --- a/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java +++ b/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java @@ -8,8 +8,6 @@ public enum HaengdongErrorCode { BAD_REQUEST(HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), DUPLICATED_MEMBER_ACTION(HttpStatus.BAD_REQUEST, "올바르지 않은 인원 요청입니다."), INVALID_MEMBER_ACTION(HttpStatus.BAD_REQUEST, "잘못된 맴버 액션입니다."), - INVALID_BILL_ACTION_SIZE(HttpStatus.BAD_REQUEST, "앞뒤 공백을 제거한 지출 내역 제목은 2 ~ 30자여야 합니다."), - INVALID_PRICE_SIZE(HttpStatus.BAD_REQUEST, "지출 금액은 10,000,000 이하의 자연수여야 합니다."), NOT_FOUND_EVENT(HttpStatus.NOT_FOUND, "존재하지 않는 행사입니다."),