From 1c7edb5eb1953e759350d41cc6a2be5db949708c Mon Sep 17 00:00:00 2001 From: Seokyeong Date: Wed, 23 Aug 2023 20:05:50 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20category,=20task,=20subTask=20id=20head?= =?UTF-8?q?er=EB=A1=9C=20=EC=9D=91=EB=8B=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/category/controller/CategoryController.java | 6 ++++-- .../api/category/service/CategoryService.java | 2 +- .../api/category/service/Impl/CategoryServiceImpl.java | 6 ++++-- .../api/subTask/controller/SubTaskController.java | 6 ++++-- .../api/subTask/service/Impl/SubTaskServiceImpl.java | 4 +++- .../katchupserver/api/subTask/service/SubTaskService.java | 2 +- .../katchupserver/api/task/controller/TaskController.java | 8 ++++---- .../api/task/service/Impl/TaskServiceImpl.java | 6 ++++-- .../katchupserver/api/task/service/TaskService.java | 2 +- 9 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/java/site/katchup/katchupserver/api/category/controller/CategoryController.java b/src/main/java/site/katchup/katchupserver/api/category/controller/CategoryController.java index fc2c226..7f1a23e 100644 --- a/src/main/java/site/katchup/katchupserver/api/category/controller/CategoryController.java +++ b/src/main/java/site/katchup/katchupserver/api/category/controller/CategoryController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -37,9 +38,10 @@ public class CategoryController { @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) }) public ApiResponseDto createCategoryName(Principal principal, - @RequestBody @Valid final CategoryCreateRequestDto requestDto) { + @RequestBody @Valid final CategoryCreateRequestDto requestDto, HttpServletResponse response) { Long memberId = MemberUtil.getMemberId(principal); - categoryService.createCategoryName(memberId, requestDto); + Long categoryId = categoryService.createCategoryName(memberId, requestDto); + response.addHeader("Location", String.valueOf(categoryId)); return ApiResponseDto.success(); } diff --git a/src/main/java/site/katchup/katchupserver/api/category/service/CategoryService.java b/src/main/java/site/katchup/katchupserver/api/category/service/CategoryService.java index f455451..1387a05 100644 --- a/src/main/java/site/katchup/katchupserver/api/category/service/CategoryService.java +++ b/src/main/java/site/katchup/katchupserver/api/category/service/CategoryService.java @@ -8,7 +8,7 @@ public interface CategoryService { - void createCategoryName(Long memberId, CategoryCreateRequestDto categoryCreateRequestDto); + Long createCategoryName(Long memberId, CategoryCreateRequestDto categoryCreateRequestDto); List getAllCategory(Long memberId); void updateCategoryName(Long memberId, Long categoryId, CategoryUpdateRequestDto categoryUpdateRequestDto); void deleteCategory(Long categoryId); diff --git a/src/main/java/site/katchup/katchupserver/api/category/service/Impl/CategoryServiceImpl.java b/src/main/java/site/katchup/katchupserver/api/category/service/Impl/CategoryServiceImpl.java index e998efb..d85e6f9 100644 --- a/src/main/java/site/katchup/katchupserver/api/category/service/Impl/CategoryServiceImpl.java +++ b/src/main/java/site/katchup/katchupserver/api/category/service/Impl/CategoryServiceImpl.java @@ -31,14 +31,16 @@ public class CategoryServiceImpl implements CategoryService { @Override @Transactional - public void createCategoryName(Long memberId, CategoryCreateRequestDto requestDto) { + public Long createCategoryName(Long memberId, CategoryCreateRequestDto requestDto) { checkDuplicateCategoryName(memberId, requestDto.getName()); - categoryRepository.save(Category.builder() + Category category = categoryRepository.save(Category.builder() .name(requestDto.getName()) .member(memberRepository.findByIdOrThrow(memberId)) .isShared(false) .build()); + + return category.getId(); } @Override diff --git a/src/main/java/site/katchup/katchupserver/api/subTask/controller/SubTaskController.java b/src/main/java/site/katchup/katchupserver/api/subTask/controller/SubTaskController.java index 1364706..1a9456a 100644 --- a/src/main/java/site/katchup/katchupserver/api/subTask/controller/SubTaskController.java +++ b/src/main/java/site/katchup/katchupserver/api/subTask/controller/SubTaskController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -46,8 +47,9 @@ public ApiResponseDto> getAllSubTask(Principal princ @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) } ) - public ApiResponseDto createSubTask(@Valid @RequestBody SubTaskCreateRequestDto requestDto) { - subTaskService.createSubTask(requestDto); + public ApiResponseDto createSubTask(@Valid @RequestBody SubTaskCreateRequestDto requestDto, HttpServletResponse response) { + Long subTaskId = subTaskService.createSubTask(requestDto); + response.addHeader("Location", String.valueOf(subTaskId)); return ApiResponseDto.success(); } } \ No newline at end of file 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 f5da24f..b1908c7 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 @@ -32,11 +32,13 @@ public List getAllSubTask(Long taskId) { @Override @Transactional - public void createSubTask(SubTaskCreateRequestDto requestDto) { + public Long createSubTask(SubTaskCreateRequestDto requestDto) { Task task = taskRepository.findByIdOrThrow(requestDto.getTaskId()); SubTask subTask = new SubTask(requestDto.getName(), task); subTaskRepository.save(subTask); + + return subTask.getId(); } } diff --git a/src/main/java/site/katchup/katchupserver/api/subTask/service/SubTaskService.java b/src/main/java/site/katchup/katchupserver/api/subTask/service/SubTaskService.java index fa45700..29f00f5 100644 --- a/src/main/java/site/katchup/katchupserver/api/subTask/service/SubTaskService.java +++ b/src/main/java/site/katchup/katchupserver/api/subTask/service/SubTaskService.java @@ -8,6 +8,6 @@ public interface SubTaskService { List getAllSubTask(Long taskId); - void createSubTask(SubTaskCreateRequestDto requestDto); + Long createSubTask(SubTaskCreateRequestDto requestDto); } 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 f9cc2bc..990da96 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 @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -15,7 +16,6 @@ import site.katchup.katchupserver.api.task.dto.request.TaskCreateRequestDto; import site.katchup.katchupserver.api.task.dto.request.TaskUpdateRequestDto; import site.katchup.katchupserver.api.task.dto.response.TaskGetResponseDto; -import site.katchup.katchupserver.api.task.repository.TaskRepository; import site.katchup.katchupserver.api.task.service.TaskService; import site.katchup.katchupserver.common.dto.ApiResponseDto; import site.katchup.katchupserver.common.util.MemberUtil; @@ -31,7 +31,6 @@ @Tag(name = "[Task] 업무 관련 API (V1)") public class TaskController { - private final TaskRepository taskRepository; private final CardService cardService; private final TaskService taskService; @@ -82,8 +81,9 @@ public ApiResponseDto updateTaskName(@PathVariable final Long taskId, }) @PostMapping() @ResponseStatus(HttpStatus.CREATED) - public ApiResponseDto createTaskName(@RequestBody @Valid final TaskCreateRequestDto requestDto) { - taskService.createTaskName(requestDto); + public ApiResponseDto createTaskName(@RequestBody @Valid final TaskCreateRequestDto requestDto, HttpServletResponse response) { + Long taskId = taskService.createTaskName(requestDto); + response.addHeader("Location", String.valueOf(taskId)); return ApiResponseDto.success(); } 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 243aa89..f4f0871 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 @@ -55,15 +55,17 @@ public void updateTaskName(Long taskId, TaskUpdateRequestDto requestDto) { @Override @Transactional - public void createTaskName(TaskCreateRequestDto requestDto) { + public Long createTaskName(TaskCreateRequestDto requestDto) { Category findCategory = categoryRepository.findByIdOrThrow(requestDto.getCategoryId()); checkDuplicateTaskName(findCategory.getId(), requestDto.getName()); - taskRepository.save(Task.builder() + Task task = taskRepository.save(Task.builder() .name(requestDto.getName()) .category(findCategory) .build()); + + return task.getId(); } @Override 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 56bab94..4b76e26 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 @@ -12,7 +12,7 @@ public interface TaskService { List getAllTask(Long memberId); List getByCategoryId(Long categoryId); void updateTaskName(Long taskId, TaskUpdateRequestDto taskUpdateRequestDto); - void createTaskName(TaskCreateRequestDto taskCreateRequestDto); + Long createTaskName(TaskCreateRequestDto taskCreateRequestDto); void deleteTask(Long taskId); }