-
Notifications
You must be signed in to change notification settings - Fork 1
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
[Feat] #30 - Task POST API 개발 #31
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2fa1ede
[Fix] #30 : TaskCreateRequestDto 위치 변경
its-sky 7e74920
[Feat] #30 : Task POST API 구현
its-sky fae76dd
[Feat] #30 : Task POST API 구현
its-sky e7fc47d
[Del] #30 : 사용하지 않는 import 문 삭제
its-sky 8e86d6c
[Fix] #30 : 컨벤션에 맞게 수정
its-sky cfe2d1c
[Fix] #30 : 충돌 해결
its-sky 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
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
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
28 changes: 28 additions & 0 deletions
28
src/main/java/org/moonshot/server/domain/task/controller/TaskController.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,28 @@ | ||
package org.moonshot.server.domain.task.controller; | ||
|
||
import static org.moonshot.server.global.common.response.SuccessType.*; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.moonshot.server.domain.task.dto.request.TaskSingleCreateRequestDto; | ||
import org.moonshot.server.domain.task.service.TaskService; | ||
import org.moonshot.server.global.common.response.ApiResponse; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/v1/task") | ||
public class TaskController { | ||
|
||
private final TaskService taskService; | ||
|
||
@PostMapping | ||
public ApiResponse<?> createTask(@RequestBody @Valid TaskSingleCreateRequestDto request) { | ||
taskService.createTask(request); | ||
return ApiResponse.success(POST_TASK_SUCCESS); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...ive/dto/request/TaskCreateRequestDto.java → ...ask/dto/request/TaskCreateRequestDto.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
16 changes: 16 additions & 0 deletions
16
src/main/java/org/moonshot/server/domain/task/dto/request/TaskSingleCreateRequestDto.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,16 @@ | ||
package org.moonshot.server.domain.task.dto.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import org.hibernate.validator.constraints.Range; | ||
|
||
public record TaskSingleCreateRequestDto( | ||
@NotNull(message = "KR이 생성될 KeyResult Id를 입력해주세요.") | ||
Long keyResultId, | ||
@Size(min = 1, max = 30, message = "Task는 30자 이하여야 합니다.") | ||
String title, | ||
@NotNull(message = "KR 순서를 입력해주세요") | ||
@Range(min = 0, max = 2, message = "KeyResult의 순서는 0부터 2까지로 설정할 수 있습니다.") | ||
Short idx | ||
) { | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/moonshot/server/domain/task/exception/TaskInvalidPositionException.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,12 @@ | ||
package org.moonshot.server.domain.task.exception; | ||
|
||
import org.moonshot.server.global.common.exception.MoonshotException; | ||
import org.moonshot.server.global.common.response.ErrorType; | ||
|
||
public class TaskInvalidPositionException extends MoonshotException { | ||
|
||
public TaskInvalidPositionException() { | ||
super(ErrorType.INVALID_TASK_ORDER); | ||
} | ||
Comment on lines
+8
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p4; |
||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/moonshot/server/domain/task/exception/TaskNumberExceededException.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,12 @@ | ||
package org.moonshot.server.domain.task.exception; | ||
|
||
import org.moonshot.server.global.common.exception.MoonshotException; | ||
import org.moonshot.server.global.common.response.ErrorType; | ||
|
||
public class TaskNumberExceededException extends MoonshotException { | ||
|
||
public TaskNumberExceededException() { | ||
super(ErrorType.ACTIVE_TASK_NUMBER_EXCEEDED); | ||
} | ||
Comment on lines
+8
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p4; |
||
|
||
} |
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
48 changes: 48 additions & 0 deletions
48
src/main/java/org/moonshot/server/domain/task/service/TaskService.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,48 @@ | ||
package org.moonshot.server.domain.task.service; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.moonshot.server.domain.keyresult.exception.KeyResultInvalidPositionException; | ||
import org.moonshot.server.domain.keyresult.model.KeyResult; | ||
import org.moonshot.server.domain.keyresult.repository.KeyResultRepository; | ||
import org.moonshot.server.domain.task.dto.request.TaskSingleCreateRequestDto; | ||
import org.moonshot.server.domain.task.exception.TaskNumberExceededException; | ||
import org.moonshot.server.domain.task.model.Task; | ||
import org.moonshot.server.domain.task.repository.TaskRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class TaskService { | ||
|
||
private static final int ACTIVE_TASK_NUMBER = 3; | ||
|
||
private final KeyResultRepository keyResultRepository; | ||
private final TaskRepository taskRepository; | ||
|
||
@Transactional | ||
public void createTask(TaskSingleCreateRequestDto request) { | ||
KeyResult keyResult = keyResultRepository.findKeyResultAndObjective(request.keyResultId()) | ||
.orElseThrow(); | ||
List<Task> taskList = taskRepository.findAllByKeyResultOrderByIdx(keyResult); | ||
|
||
if (taskList.size() >= ACTIVE_TASK_NUMBER) { | ||
throw new TaskNumberExceededException(); | ||
} | ||
if (request.idx() > taskList.size()) { | ||
throw new KeyResultInvalidPositionException(); | ||
} | ||
|
||
for (short i = request.idx(); i < taskList.size(); i++) { | ||
taskList.get(i).incrementIdx(); | ||
} | ||
taskRepository.save(Task.builder() | ||
.title(request.title()) | ||
.idx(request.idx()) | ||
.keyResult(keyResult) | ||
.build()); | ||
} | ||
|
||
} |
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
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
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.
p4;
캬캬~ 위아래 한칸이요!