-
Notifications
You must be signed in to change notification settings - Fork 0
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
[#9] Task CRUD API 스펙 정의 및 생성 #10
Merged
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2365d68
refactor: HealthController 파일 이동
olivejua e4ebac4
docs: README.md git flow 내용 추가
olivejua 52e6b7a
chore: lombok 플러그인 추가
olivejua 43aaeb8
feat: ApiResponse 클래스 생성
olivejua 84843ea
refactor: ErrorDetail 클래스명 변경
olivejua d57bbc5
chore: restDocs 설정 추가
olivejua 6f626ab
feat: Task 단건조회 API 생성
olivejua 6942547
feat: Task 생성 API 생성
olivejua 55639b5
feat: Task 삭제 API 생성
olivejua 7c1a8a2
feat: ApiControllerAdvice 생성 및 실패테스트케이스 추가
olivejua 00871e2
docs: index.adoc 작성
olivejua dfe4b06
style: todo 주석 제거
olivejua 369e578
refactor: NoData 클래스 제거
olivejua e05ff3a
chore: bootJar태스크의 dependson 추가
olivejua fcaedc8
refactor: Custom Exception 제거 및 Error Code 통일
olivejua e50bd14
refactor: TaskControllerTest 클래스명 변경
olivejua 39a0a26
refactor: TAskCreateRequest 의 파라미터 유효성 검증 및 테스트 추가
olivejua c0d6ee3
refactor: TaskUpdate API 테스트 및 실패케이스 추가
olivejua ac12666
style: todo 주석 제거
olivejua d34dbc4
test: update task 실패케이스 추가
olivejua f2a372e
docs: task.adoc 생성
olivejua 90a9de0
style: TODO 코멘트 수정 및 이슈 번호 추가
olivejua 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
9 changes: 8 additions & 1 deletion
9
api/src/main/java/com/taskbuddy/api/controller/request/TaskCreateRequest.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,9 +1,16 @@ | ||
package com.taskbuddy.api.controller.request; | ||
|
||
import com.taskbuddy.api.controller.response.task.TimeFrame; | ||
import org.springframework.util.Assert; | ||
|
||
public record TaskCreateRequest( | ||
String title, | ||
String description, | ||
TimeFrame timeFrame | ||
) {} | ||
) { | ||
public TaskCreateRequest { | ||
Assert.state(title != null && !title.isBlank(), "The title of task must not be blank."); | ||
Assert.state(description == null || description.length() <= 500, "The description length must be equal or less than 500"); | ||
Assert.notNull(timeFrame, "The timeFrame must not be null."); | ||
} | ||
} |
10 changes: 9 additions & 1 deletion
10
api/src/main/java/com/taskbuddy/api/controller/response/task/TimeFrame.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,7 +1,15 @@ | ||
package com.taskbuddy.api.controller.response.task; | ||
|
||
import org.springframework.util.Assert; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record TimeFrame( | ||
LocalDateTime startDateTime, | ||
LocalDateTime endDateTime) {} | ||
LocalDateTime endDateTime) { | ||
public TimeFrame { | ||
Assert.notNull(startDateTime, "The startDateTime must not be null."); | ||
Assert.notNull(endDateTime, "The endDateTime must not be null."); | ||
Assert.isTrue(endDateTime.isAfter(startDateTime), "The endDateTime must be after than the startDateTime."); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
api/src/test/java/com/taskbuddy/api/controller/request/TaskCreateRequestTest.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,65 @@ | ||
package com.taskbuddy.api.controller.request; | ||
|
||
import com.taskbuddy.api.controller.response.task.TimeFrame; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.NullAndEmptySource; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
||
class TaskCreateRequestTest { | ||
|
||
@ParameterizedTest | ||
@NullAndEmptySource | ||
void Title이_Null이거나_비어있는_값이면_예외를_던진다(String emptyTitle) { | ||
//given | ||
TimeFrame dummyTimeFrame = new TimeFrame(LocalDateTime.now(), LocalDateTime.now().plusDays(1)); | ||
|
||
//when & then | ||
assertThatThrownBy(() -> new TaskCreateRequest(emptyTitle, null, dummyTimeFrame)) | ||
.isInstanceOf(IllegalStateException.class) | ||
.hasMessage("The title of task must not be blank."); | ||
} | ||
|
||
@Test | ||
void description길이가_500자_초과라면_예외를_던진다() { | ||
//given | ||
String longDescription = "A".repeat(501); | ||
TimeFrame dummyTimeFrame = new TimeFrame(LocalDateTime.now(), LocalDateTime.now().plusDays(1)); | ||
|
||
//when & then | ||
assertThatThrownBy(() -> new TaskCreateRequest("sample title", longDescription, dummyTimeFrame)) | ||
.isInstanceOf(IllegalStateException.class) | ||
.hasMessage("The description length must be equal or less than 500"); | ||
} | ||
|
||
@Test | ||
void description길이가_500자_이하라면_정상적으로_객체가_생성된다() { | ||
//given | ||
String longDescription = "A".repeat(500); | ||
TimeFrame dummyTimeFrame = new TimeFrame(LocalDateTime.now(), LocalDateTime.now().plusDays(1)); | ||
|
||
//when & then | ||
assertDoesNotThrow(() -> new TaskCreateRequest("sample title", longDescription, dummyTimeFrame)); | ||
} | ||
|
||
@Test | ||
void timeFrame이_null이라면_예외를_던진다() { | ||
//given & when & then | ||
assertThatThrownBy(() -> new TaskCreateRequest("sample title", null, null)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("The timeFrame must not be null."); | ||
} | ||
|
||
@Test | ||
void 정상적인_생성자_파라미터로_객체를_생성할_수_있다() { | ||
//given | ||
TimeFrame mockTimeFrame = new TimeFrame(LocalDateTime.now(), LocalDateTime.now().plusDays(1)); | ||
|
||
//when & then | ||
assertDoesNotThrow(() -> new TaskCreateRequest("sample title", null, mockTimeFrame)); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
api/src/test/java/com/taskbuddy/api/controller/response/task/TimeFrameTest.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,49 @@ | ||
package com.taskbuddy.api.controller.response.task; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
||
class TimeFrameTest { | ||
|
||
@Test | ||
void startDateTime이_null이면_예외를_던진다() { | ||
//given & when & then | ||
assertThatThrownBy(() -> new TimeFrame(null, LocalDateTime.now())) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("The startDateTime must not be null."); | ||
} | ||
|
||
@Test | ||
void endDateTime이_null이면_예외를_던진다() { | ||
//given & when & then | ||
assertThatThrownBy(() -> new TimeFrame(LocalDateTime.now(), null)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("The endDateTime must not be null."); | ||
} | ||
|
||
@Test | ||
void endDateTime이_startDateTime보다_과거일시라면_예외를_던진다() { | ||
//given | ||
LocalDateTime mockStartDateTime = LocalDateTime.now(); | ||
LocalDateTime mockEndDateTime = mockStartDateTime.minusDays(1); | ||
|
||
//when & then | ||
assertThatThrownBy(() -> new TimeFrame(mockStartDateTime, mockEndDateTime)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("The endDateTime must be after than the startDateTime."); | ||
} | ||
|
||
@Test | ||
void 정상적인_생성자_파라미터로_객체를_생성할_수_있다() { | ||
//given | ||
LocalDateTime mockStartDateTime = LocalDateTime.now(); | ||
LocalDateTime mockEndDateTime = mockStartDateTime.plusHours(1); | ||
|
||
//when & then | ||
assertDoesNotThrow(() -> new TimeFrame(mockStartDateTime, mockEndDateTime)); | ||
} | ||
} |
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.
다른 부분이랑 스타일이 다른 것 같네요?
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.
Spring Validation 의존성을 추가하기 전에 Request에 대한 Validation을 진행해야할 것 같아 Assert 를 추가한 유효성검증 로직을 추가하면서 생성자를 만들었습니다. Spring Validation Annotation을 붙이면 해당 생성자는 제거하려고 합니다!