From 9262a2f7328c8fd166d7486adb4342fd48c451aa Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Fri, 25 Aug 2023 03:03:41 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20=EC=97=85=EB=AC=B4=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EC=8B=9C=20=ED=95=B4=EB=8B=B9=20=EC=97=85=EB=AC=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9D=98=20=EC=B9=B4=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=95=88=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/card/service/CardService.java | 2 +- .../card/service/Impl/CardServiceImpl.java | 2 +- .../repository/CategoryRepository.java | 7 ++++-- .../subTask/repository/SubTaskRepository.java | 6 ++++- .../service/Impl/SubTaskServiceImpl.java | 2 +- .../api/task/controller/TaskController.java | 23 ++++--------------- .../api/task/repository/TaskRepository.java | 12 ++++++++-- .../task/service/Impl/TaskServiceImpl.java | 13 ++--------- .../api/task/service/TaskService.java | 3 +-- 9 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/main/java/site/katchup/katchupserver/api/card/service/CardService.java b/src/main/java/site/katchup/katchupserver/api/card/service/CardService.java index d10a9fb..f56d9e9 100644 --- a/src/main/java/site/katchup/katchupserver/api/card/service/CardService.java +++ b/src/main/java/site/katchup/katchupserver/api/card/service/CardService.java @@ -11,7 +11,7 @@ @Transactional public interface CardService { - List getCardList(Long folderId); + List getCardList(Long taskId); CardGetResponseDto getCard(Long cardId); void deleteCardList(CardDeleteRequestDto cardDeleteRequestDto); void createCard(Long memberId, CardCreateRequestDto cardCreateRequestDto); diff --git a/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java b/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java index 0c7cce7..59a5242 100644 --- a/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java +++ b/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java @@ -63,7 +63,7 @@ public class CardServiceImpl implements CardService { @Override public List getCardList(Long taskId) { - return subTaskRepository.findAllByTaskId(taskId).stream() + return subTaskRepository.findAllByTaskIdAndNotDeleted(taskId).stream() .flatMap(subTask -> subTask.getCards().stream()) .collect(Collectors.groupingBy(Card::getSubTask)) // subTaskId 그룹화 .values().stream() diff --git a/src/main/java/site/katchup/katchupserver/api/category/repository/CategoryRepository.java b/src/main/java/site/katchup/katchupserver/api/category/repository/CategoryRepository.java index 460e4c1..80f6c1c 100644 --- a/src/main/java/site/katchup/katchupserver/api/category/repository/CategoryRepository.java +++ b/src/main/java/site/katchup/katchupserver/api/category/repository/CategoryRepository.java @@ -4,22 +4,25 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import site.katchup.katchupserver.api.category.domain.Category; +import site.katchup.katchupserver.api.task.domain.Task; import site.katchup.katchupserver.common.exception.NotFoundException; import site.katchup.katchupserver.common.response.ErrorCode; import java.util.List; +import java.util.Optional; public interface CategoryRepository extends JpaRepository { - boolean existsByMemberIdAndName(Long memberId, String name); + Optional findByIdAndIsDeletedFalse(Long id); + boolean existsByMemberIdAndName(Long memberId, String name); @Query("select c from Category c where c.member.id = :memberId and c.isDeleted = false") List findAllByMemberIdAndNotDeleted(@Param("memberId") Long memberId); default Category findByIdOrThrow(Long categoryId) { - return findById(categoryId).orElseThrow( + return findByIdAndIsDeletedFalse(categoryId).orElseThrow( () -> new NotFoundException(ErrorCode.NOT_FOUND_CATEGORY)); } } diff --git a/src/main/java/site/katchup/katchupserver/api/subTask/repository/SubTaskRepository.java b/src/main/java/site/katchup/katchupserver/api/subTask/repository/SubTaskRepository.java index 9863223..cfaade7 100644 --- a/src/main/java/site/katchup/katchupserver/api/subTask/repository/SubTaskRepository.java +++ b/src/main/java/site/katchup/katchupserver/api/subTask/repository/SubTaskRepository.java @@ -1,7 +1,10 @@ package site.katchup.katchupserver.api.subTask.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import site.katchup.katchupserver.api.category.domain.Category; import site.katchup.katchupserver.api.subTask.domain.SubTask; import site.katchup.katchupserver.api.task.domain.Task; import site.katchup.katchupserver.common.exception.NotFoundException; @@ -12,7 +15,8 @@ @Repository public interface SubTaskRepository extends JpaRepository { - List findAllByTaskId(Long taskId); + @Query("select s from SubTask s where s.task.id = :taskId and s.isDeleted = false") + List findAllByTaskIdAndNotDeleted(@Param("taskId") Long taskId); Optional findSubTaskByTaskAndName(Task task, String name); diff --git a/src/main/java/site/katchup/katchupserver/api/subTask/service/Impl/SubTaskServiceImpl.java b/src/main/java/site/katchup/katchupserver/api/subTask/service/Impl/SubTaskServiceImpl.java index b1908c7..98c99ce 100644 --- a/src/main/java/site/katchup/katchupserver/api/subTask/service/Impl/SubTaskServiceImpl.java +++ b/src/main/java/site/katchup/katchupserver/api/subTask/service/Impl/SubTaskServiceImpl.java @@ -25,7 +25,7 @@ public class SubTaskServiceImpl implements SubTaskService { @Transactional(readOnly = true) public List getAllSubTask(Long taskId) { - return subTaskRepository.findAllByTaskId(taskId).stream() + return subTaskRepository.findAllByTaskIdAndNotDeleted(taskId).stream() .map(subTask -> SubTaskGetResponseDto.of(subTask.getId(), subTask.getName())) .collect(Collectors.toList()); } diff --git a/src/main/java/site/katchup/katchupserver/api/task/controller/TaskController.java b/src/main/java/site/katchup/katchupserver/api/task/controller/TaskController.java index 990da96..0f08494 100644 --- a/src/main/java/site/katchup/katchupserver/api/task/controller/TaskController.java +++ b/src/main/java/site/katchup/katchupserver/api/task/controller/TaskController.java @@ -34,29 +34,16 @@ public class TaskController { private final CardService cardService; private final TaskService taskService; - @Operation(summary = "업무 목록 조회 API") + @Operation(summary = "카테고리 내의 업무 조회 API") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "업무 목록 조회 성공"), - @ApiResponse(responseCode = "400", description = "업무 목록 조회 성공", content = @Content), - @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) - }) - @GetMapping() - @ResponseStatus(HttpStatus.OK) - public ApiResponseDto> getAllTask(Principal principal) { - Long memberId = MemberUtil.getMemberId(principal); - return ApiResponseDto.success(taskService.getAllTask(memberId)); - } - - @Operation(summary = "업무 조회 API") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "업무 조회 성공"), - @ApiResponse(responseCode = "400", description = "업무 조회 실패", content = @Content), + @ApiResponse(responseCode = "200", description = "카테고리 내의 업무 조회 성공"), + @ApiResponse(responseCode = "400", description = "카테고리 내의 업무 조회 실패", content = @Content), @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) }) @GetMapping("/categories/{categoryId}") @ResponseStatus(HttpStatus.OK) public ApiResponseDto> getByCategoryId(@PathVariable final Long categoryId) { - return ApiResponseDto.success(taskService.getByCategoryId(categoryId)); + return ApiResponseDto.success(taskService.getAllByCategory(categoryId)); } @Operation(summary = "업무 업데이트 API") @@ -95,7 +82,7 @@ public ApiResponseDto createTaskName(@RequestBody @Valid final TaskCreateRequest }) @GetMapping("/{taskId}/cards") @ResponseStatus(HttpStatus.OK) - public ApiResponseDto> getCardList(@PathVariable final Long taskId) { + public ApiResponseDto> getCardList(@PathVariable Long taskId) { return ApiResponseDto.success(cardService.getCardList(taskId)); } diff --git a/src/main/java/site/katchup/katchupserver/api/task/repository/TaskRepository.java b/src/main/java/site/katchup/katchupserver/api/task/repository/TaskRepository.java index a952eaa..c1989af 100644 --- a/src/main/java/site/katchup/katchupserver/api/task/repository/TaskRepository.java +++ b/src/main/java/site/katchup/katchupserver/api/task/repository/TaskRepository.java @@ -1,19 +1,27 @@ package site.katchup.katchupserver.api.task.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import site.katchup.katchupserver.api.category.domain.Category; import site.katchup.katchupserver.api.task.domain.Task; import site.katchup.katchupserver.common.exception.NotFoundException; import site.katchup.katchupserver.common.response.ErrorCode; import java.util.List; +import java.util.Optional; public interface TaskRepository extends JpaRepository { - List findByCategoryId(Long categoryId); + + Optional findByIdAndIsDeletedFalse(Long id); boolean existsByCategoryIdAndName(Long categoryId, String name); + @Query("select t from Task t where t.category.id = :categoryId and t.isDeleted = false") + List findAllByCategoryIdAndNotDeleted(@Param("categoryId") Long categoryId); + default Task findByIdOrThrow(Long taskId) { - return findById(taskId).orElseThrow( + return findByIdAndIsDeletedFalse(taskId).orElseThrow( () -> new NotFoundException(ErrorCode.NOT_FOUND_TASK)); } } \ No newline at end of file diff --git a/src/main/java/site/katchup/katchupserver/api/task/service/Impl/TaskServiceImpl.java b/src/main/java/site/katchup/katchupserver/api/task/service/Impl/TaskServiceImpl.java index f4f0871..d731fd3 100644 --- a/src/main/java/site/katchup/katchupserver/api/task/service/Impl/TaskServiceImpl.java +++ b/src/main/java/site/katchup/katchupserver/api/task/service/Impl/TaskServiceImpl.java @@ -28,17 +28,8 @@ public class TaskServiceImpl implements TaskService { @Override @Transactional(readOnly = true) - public List getAllTask(Long memberId) { - return categoryRepository.findAllByMemberIdAndNotDeleted(memberId).stream() - .flatMap(category -> taskRepository.findByCategoryId(category.getId()).stream()) - .map(task -> TaskGetResponseDto.of(task.getId(), task.getName())) - .collect(Collectors.toList()); - } - - @Override - @Transactional(readOnly = true) - public List getByCategoryId(Long categoryId) { - return taskRepository.findByCategoryId(categoryId).stream() + public List getAllByCategory(Long categoryId) { + return taskRepository.findAllByCategoryIdAndNotDeleted(categoryId).stream() .map(task -> TaskGetResponseDto.of(task.getId(), task.getName())) .collect(Collectors.toList()); } diff --git a/src/main/java/site/katchup/katchupserver/api/task/service/TaskService.java b/src/main/java/site/katchup/katchupserver/api/task/service/TaskService.java index 4b76e26..b1c2a0d 100644 --- a/src/main/java/site/katchup/katchupserver/api/task/service/TaskService.java +++ b/src/main/java/site/katchup/katchupserver/api/task/service/TaskService.java @@ -9,8 +9,7 @@ public interface TaskService { - List getAllTask(Long memberId); - List getByCategoryId(Long categoryId); + List getAllByCategory(Long categoryId); void updateTaskName(Long taskId, TaskUpdateRequestDto taskUpdateRequestDto); Long createTaskName(TaskCreateRequestDto taskCreateRequestDto); void deleteTask(Long taskId);