-
Notifications
You must be signed in to change notification settings - Fork 5
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] 행사 생성 API 예외 메세지 및 DTO 검증 애너테이션 추가 #103
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a90eafc
refactor: 행사 생성 API 예외 메세지 추가 및 DTO 검증 애너테이션 추가
kunsanglee 1f0bb13
refactor: 행사 생성 API EventSaveRequest name을 eventName으로 변경
kunsanglee 2d00932
refactor: 행사 생성 요청 객체 검증 애너테이션 @Size 제거
kunsanglee 093645c
refactor: 연속된 공백 검증 및 예외 메세지 상수 사용하도록 리팩터링
kunsanglee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
server/src/main/java/server/haengdong/presentation/request/EventSaveRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package server.haengdong.presentation.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import server.haengdong.application.request.EventAppRequest; | ||
|
||
public record EventSaveRequest(String name) { | ||
public record EventSaveRequest( | ||
|
||
@NotBlank | ||
String eventName | ||
) { | ||
|
||
public EventAppRequest toAppRequest() { | ||
return new EventAppRequest(name); | ||
return new EventAppRequest(eventName); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
server/src/test/java/server/haengdong/domain/event/EventTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package server.haengdong.domain.event; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import server.haengdong.exception.HaengdongException; | ||
|
||
class EventTest { | ||
|
||
@DisplayName("공백 문자가 연속되지 않고, 이름이 2자 이상 20자 이하인 행사를 생성하면 예외가 발생하지 않는다.") | ||
@ParameterizedTest | ||
@ValueSource(strings = {"12", "12345678901234567890", "공 백", " 공백", "공백 ", " 공 백 "}) | ||
void createSuccessTest(String eventName) { | ||
assertThatCode(() -> new Event(eventName, "TEST_TOKEN")) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@DisplayName("공백 문자가 연속되면 예외가 발생한다.") | ||
@ParameterizedTest | ||
@ValueSource(strings = {" 공백", "공백 ", "공백 연속", "공 백"}) | ||
void createFailTest1(String eventName) { | ||
assertThatCode(() -> new Event(eventName, "TEST_TOKEN")) | ||
.isInstanceOf(HaengdongException.class) | ||
.hasMessage(String.format("행사 이름에는 공백 문자가 연속될 수 없습니다. 입력한 이름 : %s", eventName)); | ||
} | ||
|
||
@DisplayName("이름이 2자 미만이거나 20자 초과인 경우 예외가 발생한다.") | ||
@ParameterizedTest | ||
@ValueSource(strings = {"", " ", "123456789012345678901"}) | ||
void createFilTest2(String eventName) { | ||
assertThatCode(() -> new Event(eventName, "TEST_TOKEN")) | ||
.isInstanceOf(HaengdongException.class) | ||
.hasMessage(String.format("행사 이름은 2자 이상 20자 이하만 입력 가능합니다. 입력한 이름 길이 : %d", eventName.length())); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c: BillActionController에서는
@Valid
를 뒤에 썼는데,@Valid
랑@RequestBody
순서 어떻게 할지도 정해야겠네요There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Valid @RequestBody
순서로 반영했습니다.