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/domain/action/BillAction.java b/server/src/main/java/server/haengdong/domain/action/BillAction.java index f0e82c409..1027206f5 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,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 IllegalArgumentException("앞뒤 공백을 제거한 지출 내역 제목은 2 ~ 30자여야 합니다."); + 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 IllegalArgumentException("지출 금액은 10,000,000 이하의 자연수여야 합니다."); + throw new HaengdongException(HaengdongErrorCode.BAD_REQUEST, + String.format("지출 금액은 %,d 이하의 자연수여야 합니다.", MAX_PRICE)); } } 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..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,18 +1,15 @@ package server.haengdong.presentation.request; +import jakarta.validation.constraints.NotBlank; 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) + @NotBlank String title, @NotNull - @Positive Long price ) { 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); } } 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 이하의 자연수여야 합니다."); }