-
Notifications
You must be signed in to change notification settings - Fork 0
Feat[#124] 특정 태스크의 모립세트 불러오기 #125
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
base: main
Are you sure you want to change the base?
Changes from all commits
be1fc57
bfb8366
97a1bf6
179a954
c773c82
d7444a9
042c65e
760e33d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package org.sopt.jaksim.category.dto; | ||
|
|
||
| import org.sopt.jaksim.mset.domain.Mset; | ||
| import org.sopt.jaksim.mset.domain.MsetDTO; | ||
| import org.sopt.jaksim.task.domain.Task; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record TaskMsetLinkResponse( | ||
| Task task, | ||
| List<MsetDTO> msets | ||
| ) { | ||
| public static TaskMsetLinkResponse of(Task task, List<MsetDTO> msets) { | ||
| return new TaskMsetLinkResponse(task, msets); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package org.sopt.jaksim.category.facade; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.sopt.jaksim.category.domain.Category; | ||
| import org.sopt.jaksim.category.dto.CategoryMsetLinkResponse; | ||
| import org.sopt.jaksim.category.dto.TaskMsetLinkResponse; | ||
| import org.sopt.jaksim.category.service.CategoryService; | ||
| import org.sopt.jaksim.mset.domain.CategoryMset; | ||
| import org.sopt.jaksim.mset.domain.Mset; | ||
| import org.sopt.jaksim.mset.domain.MsetDTO; | ||
| import org.sopt.jaksim.mset.domain.TaskMset; | ||
| import org.sopt.jaksim.mset.service.CategoryMsetService; | ||
| import org.sopt.jaksim.mset.service.MsetService; | ||
| import org.sopt.jaksim.mset.service.TaskMsetService; | ||
| import org.sopt.jaksim.task.domain.Task; | ||
| import org.sopt.jaksim.task.service.TaskService; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class TaskMsetFacade { | ||
| private final TaskService taskService; | ||
| private final MsetService msetService; | ||
| private final TaskMsetService taskMsetService; | ||
|
|
||
| public TaskMsetLinkResponse getFromOtherTask(Long taskId) { | ||
| Task task = taskService.getTaskById(taskId); | ||
| List<TaskMset> taskMsetList = taskMsetService.getByTaskId(taskId); | ||
| List<MsetDTO> msets = taskMsetList.stream() // | ||
|
Contributor
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. map을 두번 엮어서 간결하게 코드를 표현해주신 것 아주 좋네요 :) !! |
||
| .map(taskMset -> msetService.getMsetById(taskMset.getMsetId())) | ||
| .map(mset -> new MsetDTO(mset.getId(), mset.getName(), mset.getUrl())) | ||
|
Contributor
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. 이렇게
Contributor
Author
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. 넵넵... |
||
| .collect(Collectors.toList()); | ||
| return TaskMsetLinkResponse.of(task, msets); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package org.sopt.jaksim.mset.domain; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class MsetDTO { | ||
|
Contributor
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. dto는 클라이언트와 controller 레벨에서 주고받는 객체의 형태입니다. 여기서 예를 들어,
Contributor
Author
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. 넵 의견 감사합니다
Contributor
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. record가 아닌 class를 사용한 이유가 있을까요?
Contributor
Author
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. 고치겠슴니다.... |
||
| private final Long id; | ||
| private final String name; | ||
| private final String url; | ||
|
|
||
| public MsetDTO(Long id, String name, String url) { | ||
|
Contributor
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. TaskMsetLinkResponse의 형태처럼 정적 팩토리 메소드 패턴을 이용한 것이 아닌, 매개변수가 있는 생성자를 이용한 특별한 이유가 있을까요? 또한, 매개변수를 모두 파라미터로 받는 생성자를 작성할 때는 Lombok의 @AllArgsConstructor가 있기 때문에 코드를 더 간결하게 만들 수도 있겠네요! |
||
| this.id = id; | ||
| this.name = name; | ||
| this.url = url; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package org.sopt.jaksim.mset.repository; | ||
|
|
||
| import org.sopt.jaksim.mset.domain.TaskMset; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface TaskMsetRepository extends JpaRepository<TaskMset, Long> { | ||
| List<TaskMset> findByTaskId(Long taskId); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||||||
| package org.sopt.jaksim.mset.service; | ||||||||||
|
|
||||||||||
| import lombok.RequiredArgsConstructor; | ||||||||||
| import lombok.extern.slf4j.Slf4j; | ||||||||||
| import org.sopt.jaksim.mset.domain.CategoryMset; | ||||||||||
| import org.sopt.jaksim.mset.domain.TaskMset; | ||||||||||
| import org.sopt.jaksim.mset.repository.CategoryMsetRepository; | ||||||||||
| import org.sopt.jaksim.mset.repository.TaskMsetRepository; | ||||||||||
| import org.springframework.stereotype.Service; | ||||||||||
|
|
||||||||||
| import java.util.List; | ||||||||||
|
|
||||||||||
| @Slf4j | ||||||||||
| @Service | ||||||||||
| @RequiredArgsConstructor | ||||||||||
| public class TaskMsetService { | ||||||||||
| private final TaskMsetRepository taskMsetRepository; | ||||||||||
| public List<TaskMset> getByTaskId(Long taskId) { | ||||||||||
| return taskMsetRepository.findByTaskId(taskId); | ||||||||||
|
Contributor
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. taskId가 존재하지 않는 경우를 핸들링해주는 코드가 필요할 것 같아요 !
Suggested change
Contributor
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. 추가적으로,
Contributor
Author
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. 아하 넵!
Contributor
Author
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. 말씀해주신대로 taskMsetRepository.findByTaskId(taskId).orElseThrow(
() -> new NotFoundException(ErrorMessage.NOT_FOUND)
)이렇게 바꾸고 repository는 Optional을 추가해줘야할 것 같군요! |
||||||||||
| } | ||||||||||
| } | ||||||||||
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.
근데, TaskMsetLinkResponse에는 Task는 제외해도 됩니다 :) 모립세트만 포함되면 됩니다!