-
Notifications
You must be signed in to change notification settings - Fork 4
CLAP-58 작업 수정 #69
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
Merged
Merged
CLAP-58 작업 수정 #69
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
7 changes: 7 additions & 0 deletions
7
src/main/java/clap/server/adapter/inbound/web/dto/task/AttachmentRequest.java
This file contains hidden or 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,7 @@ | ||
| package clap.server.adapter.inbound.web.dto.task; | ||
|
|
||
|
|
||
| public record AttachmentRequest( | ||
| Long fileId, | ||
| String fileUrl) { | ||
| } |
This file contains hidden or 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
4 changes: 3 additions & 1 deletion
4
...ound/web/dto/task/CreateTaskResponse.java → ...dto/task/CreateAndUpdateTaskResponse.java
This file contains hidden or 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
20 changes: 20 additions & 0 deletions
20
src/main/java/clap/server/adapter/inbound/web/dto/task/UpdateTaskRequest.java
This file contains hidden or 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,20 @@ | ||
| package clap.server.adapter.inbound.web.dto.task; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record UpdateTaskRequest( | ||
| @NotNull | ||
| Long taskId, | ||
| @NotNull | ||
| Long categoryId, | ||
| @NotNull | ||
| Long mainCategoryId, | ||
| @NotBlank | ||
| String title, | ||
| String description, | ||
| List<AttachmentRequest> attachmentRequests | ||
| ) { | ||
| } |
27 changes: 0 additions & 27 deletions
27
src/main/java/clap/server/adapter/inbound/web/task/CreateTaskController.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
26 changes: 0 additions & 26 deletions
26
src/main/java/clap/server/adapter/inbound/web/task/FindTaskDetailsController.java
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
src/main/java/clap/server/adapter/inbound/web/task/ManagementTaskController.java
This file contains hidden or 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,36 @@ | ||
| package clap.server.adapter.inbound.web.task; | ||
|
|
||
| import clap.server.adapter.inbound.web.dto.task.CreateTaskRequest; | ||
| import clap.server.adapter.inbound.web.dto.task.CreateAndUpdateTaskResponse; | ||
| import clap.server.adapter.inbound.web.dto.task.UpdateTaskRequest; | ||
| import clap.server.application.port.inbound.task.CreateTaskUsecase; | ||
| import clap.server.application.port.inbound.task.UpdateTaskUsecase; | ||
| import clap.server.common.annotation.architecture.WebAdapter; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
|
|
||
| @WebAdapter | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/tasks") | ||
| public class ManagementTaskController { | ||
|
|
||
| private final CreateTaskUsecase createTaskUsecase; | ||
| private final UpdateTaskUsecase updateTaskUsecase; | ||
| private static final Long memberId = 4L; | ||
|
|
||
| @PostMapping | ||
| public ResponseEntity<CreateAndUpdateTaskResponse> createTask( | ||
| @RequestBody @Valid CreateTaskRequest createTaskRequest){ | ||
| return ResponseEntity.ok(createTaskUsecase.createTask(memberId, createTaskRequest)); | ||
| } | ||
|
|
||
| @PatchMapping | ||
| public ResponseEntity<CreateAndUpdateTaskResponse> updateTask( | ||
| @RequestBody @Valid UpdateTaskRequest updateTaskRequest){ | ||
| return ResponseEntity.ok(updateTaskUsecase.updateTask(memberId, updateTaskRequest)); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
57 changes: 57 additions & 0 deletions
57
src/main/java/clap/server/application/Task/UpdateTaskService.java
This file contains hidden or 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,57 @@ | ||
| package clap.server.application.Task; | ||
|
|
||
| import clap.server.adapter.inbound.web.dto.task.CreateAndUpdateTaskResponse; | ||
| import clap.server.adapter.inbound.web.dto.task.UpdateTaskRequest; | ||
| import clap.server.application.mapper.AttachmentMapper; | ||
| import clap.server.application.mapper.TaskMapper; | ||
| import clap.server.application.port.inbound.domain.CategoryService; | ||
| import clap.server.application.port.inbound.domain.MemberService; | ||
| import clap.server.application.port.inbound.domain.TaskService; | ||
| import clap.server.application.port.inbound.task.UpdateTaskUsecase; | ||
| import clap.server.application.port.outbound.task.CommandAttachmentPort; | ||
| import clap.server.application.port.outbound.task.CommandTaskPort; | ||
|
|
||
| import clap.server.common.annotation.architecture.ApplicationService; | ||
| import clap.server.domain.model.member.Member; | ||
| import clap.server.domain.model.task.Attachment; | ||
| import clap.server.domain.model.task.Category; | ||
| import clap.server.domain.model.task.Task; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
|
|
||
|
|
||
|
|
||
| @ApplicationService | ||
| @RequiredArgsConstructor | ||
| @Slf4j | ||
| public class UpdateTaskService implements UpdateTaskUsecase { | ||
|
|
||
| private final MemberService memberService; | ||
| private final CategoryService categoryService; | ||
| private final TaskService taskService; | ||
| private final CommandTaskPort commandTaskPort; | ||
| private final CommandAttachmentPort commandAttachmentPort; | ||
|
|
||
|
|
||
| @Override | ||
| @Transactional | ||
| public CreateAndUpdateTaskResponse updateTask(Long requesterId, UpdateTaskRequest updateTaskRequest) { | ||
| Member member = memberService.findActiveMember(requesterId); | ||
| Category category = categoryService.findById(updateTaskRequest.categoryId()); | ||
| Task task = taskService.findById(updateTaskRequest.taskId()); | ||
|
|
||
| Task updatedTask = Task.updateTask(task, member, category, updateTaskRequest.title(), updateTaskRequest.description()); | ||
| Task savedTask = commandTaskPort.save(updatedTask); | ||
|
|
||
| List<Long> attachmentIds = AttachmentMapper.toAttachmentIds(updateTaskRequest.attachmentRequests()); | ||
| commandAttachmentPort.deleteByIds(attachmentIds); | ||
|
|
||
| List<Attachment> attachments = Attachment.updateAttachments(savedTask, updateTaskRequest.attachmentRequests()); | ||
| commandAttachmentPort.saveAll(attachments); | ||
| return TaskMapper.toCreateAndUpdateTaskResponse(savedTask); | ||
| } | ||
| } |
19 changes: 10 additions & 9 deletions
19
src/main/java/clap/server/application/mapper/AttachmentMapper.java
This file contains hidden or 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,27 +1,28 @@ | ||
| package clap.server.application.mapper; | ||
|
|
||
| import clap.server.adapter.inbound.web.dto.task.AttachmentRequest; | ||
| import clap.server.adapter.inbound.web.dto.task.AttachmentResponse; | ||
| import clap.server.adapter.inbound.web.dto.task.FindTaskDetailsResponse; | ||
| import clap.server.domain.model.task.Attachment; | ||
| import clap.server.domain.model.task.Task; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class AttachmentMapper { | ||
| private AttachmentMapper() { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
|
|
||
| public static List<Attachment> toAttachments(Task task, List<String> fileUrls) { | ||
| return fileUrls.stream() | ||
| .map(fileUrl -> Attachment.builder() | ||
| .task(task) | ||
| .fileUrl(fileUrl) | ||
| .originalName("파일 예시 이름") | ||
| .fileSize("16MB") //TODO: 하드코딩 제거 | ||
| .build()) | ||
| .collect(Collectors.toList()); | ||
|
|
||
|
|
||
| public static List<Long> toAttachmentIds(List<AttachmentRequest> attachmentRequests) { | ||
| return attachmentRequests.stream() | ||
| .map(AttachmentRequest::fileId) | ||
| .filter(Objects::nonNull) | ||
| .toList(); | ||
| } | ||
|
|
||
| } | ||
|
|
Oops, something went wrong.
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.
같은 dto 형식이라도 dto는 API마다 분리해주시면 좋을것 같습니다!