Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] 지출 내역 생성 및 현재 참여 인원 조회 예외 메시지 변경 #100

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -53,6 +55,6 @@ public List<CurrentMemberAppResponse> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Copy link
Contributor

@3Juhwan 3Juhwan Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (titleLength < MIN_TITLE_LENGTH || titleLength > MAX_TITLE_LENGTH) {
if (titleLength < MIN_TITLE_LENGTH || MAX_TITLE_LENGTH < titleLength) {

c: 제안해 봅니다

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

길이가 최소값보다 작거나 길이가 최대값보다 크거나 로 읽는 것이 자연스러워 보여 기각합니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 이 부분은 망쵸의 의견과 같네요.
감자키 < 망쵸키 && 망쵸키 < 백호키 이런 식으로 보는게 직관적이라고 생각합니다~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

감자키 < 망쵸키 && 망쵸키 < 백호키

이건 동의하는데
망쵸키 < 감자키 || 백호키 < 망쵸키 는 어색하지 않나요?

Copy link
Contributor

@kunsanglee kunsanglee Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제가 처음 들었던 예시를 뒤집어서 했군요.
A가 10 미만이거나 20 초과라면?
이라는 조건을 제가 코드로 표현한다면
A < 10 || 20 < A
라고 작성할 것 같은데요, 백호는 어떻게 생각하나요? 추가: 생각해보니 사람마다 다를 것 같긴 하네요 반영 안하셔도 상관 없을 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!(10 < A && A < 20) 은 어떤가요?

Copy link
Contributor

@3Juhwan 3Juhwan Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개인적으로 부등호 방향이 같은 게 인지하기 쉽다고 생각해요! A < 10 || 20 < A을 주장해 봅니다.
!(10 < A && A < 20)이 좀더 직관적일 수 있을 것 같긴 해요. 다만 !를 인지하는 것도 비용이 든다고 생각해요.
사람마다 다른 것 같아요. 편한대로 해주세요 :)

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));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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자여야 합니다.");
}

Expand All @@ -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 이하의 자연수여야 합니다.");
}

Expand Down
Loading