From 30f38f113102d5a8a6818616ce87800531bb0170 Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Wed, 23 Aug 2023 18:40:59 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20=EC=97=85=EB=AC=B4=20=EC=B9=B4=EB=93=9C?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=20=EC=8B=9C,=20=EC=84=B8=EB=B6=80=20?= =?UTF-8?q?=EC=97=85=EB=AC=B4=20=EC=9E=91=EC=84=B1=20=EC=95=88=ED=95=98?= =?UTF-8?q?=EB=A9=B4=20'=EA=B8=B0=ED=83=80'=20=EC=97=85=EB=AC=B4=EB=A1=9C?= =?UTF-8?q?=20=EB=B6=84=EB=A5=98=20&=20=EC=97=85=EB=AC=B4=20=EB=82=B4=20?= =?UTF-8?q?=ED=82=A4=EC=9B=8C=EB=93=9C=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/CardCreateRequestDto.java | 2 ++ .../card/service/Impl/CardServiceImpl.java | 10 +++++++++- .../keyword/controller/KeywordController.java | 16 ++++++++-------- .../subTask/repository/SubTaskRepository.java | 19 +++++++++++++++++-- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/main/java/site/katchup/katchupserver/api/card/dto/request/CardCreateRequestDto.java b/src/main/java/site/katchup/katchupserver/api/card/dto/request/CardCreateRequestDto.java index 93c19da..a75dd43 100644 --- a/src/main/java/site/katchup/katchupserver/api/card/dto/request/CardCreateRequestDto.java +++ b/src/main/java/site/katchup/katchupserver/api/card/dto/request/CardCreateRequestDto.java @@ -1,5 +1,6 @@ package site.katchup.katchupserver.api.card.dto.request; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; @@ -16,6 +17,7 @@ public class CardCreateRequestDto { private Long categoryId; @NotNull(message = "CD-111") private Long taskId; + @Schema(description = "세부 업무 작성 안할 시, 해당 값 0으로") @NotNull(message = "CD-112") private Long subTaskId; @NotNull(message = "CD-113") 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 b2c9de6..89fb03f 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 @@ -39,6 +39,8 @@ @Transactional(readOnly = true) public class CardServiceImpl implements CardService { + private static final String SUB_TASK_ETC_NAME = "기타"; + private final SubTaskRepository subTaskRepository; private final CardKeywordRepository cardKeywordRepository; private final TrashRepository trashRepository; @@ -82,7 +84,13 @@ public void deleteCardList(CardDeleteRequestDto cardDeleteRequestDto) { @Transactional public void createCard(CardCreateRequestDto requestDto) { - SubTask subTask = subTaskRepository.findByIdOrThrow(requestDto.getSubTaskId()); + SubTask subTask; + if (requestDto.getSubTaskId() == 0) { + Task task = taskRepository.findByIdOrThrow(requestDto.getTaskId()); + subTask = subTaskRepository.findOrCreateEtcSubTask(task, SUB_TASK_ETC_NAME); + } else { + subTask = subTaskRepository.findByIdOrThrow(requestDto.getSubTaskId()); + } Card card = Card.builder() .content(requestDto.getContent()) diff --git a/src/main/java/site/katchup/katchupserver/api/keyword/controller/KeywordController.java b/src/main/java/site/katchup/katchupserver/api/keyword/controller/KeywordController.java index 8fecc8a..52a388f 100644 --- a/src/main/java/site/katchup/katchupserver/api/keyword/controller/KeywordController.java +++ b/src/main/java/site/katchup/katchupserver/api/keyword/controller/KeywordController.java @@ -16,24 +16,24 @@ import java.util.List; @RestController -@RequestMapping("/api/v1/cards") +@RequestMapping("/api/v1/keywords") @RequiredArgsConstructor @Tag(name = "[Keyword] 키워드 관련 API (V1)") public class KeywordController { private final KeywordService keywordService; - @Operation(summary = "업무 카드의 모든 키워드 조회 API") + @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("/{cardId}/keywords") + @GetMapping("/{taskId}") @ResponseStatus(HttpStatus.OK) - public ApiResponseDto> getAllKeyword(@PathVariable Long cardId) { - return ApiResponseDto.success(keywordService.getAllKeyword(cardId)); + public ApiResponseDto> getAllKeyword(@PathVariable Long taskId) { + return ApiResponseDto.success(keywordService.getAllKeyword(taskId)); } @Operation(summary = "키워드 생성 API") @@ -44,7 +44,7 @@ public ApiResponseDto> getAllKeyword(@PathVariable L @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) } ) - @PostMapping("/keywords") + @PostMapping() @ResponseStatus(HttpStatus.CREATED) public ApiResponseDto createKeyword(@Valid @RequestBody KeywordCreateRequestDto requestDto) { keywordService.createKeyword(requestDto); 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 e42814d..9863223 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 @@ -3,17 +3,32 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import site.katchup.katchupserver.api.subTask.domain.SubTask; +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; @Repository public interface SubTaskRepository extends JpaRepository { List findAllByTaskId(Long taskId); + Optional findSubTaskByTaskAndName(Task task, String name); + default SubTask findByIdOrThrow(Long subTaskId) { - return findById(subTaskId).orElseThrow( - () -> new NotFoundException(ErrorCode.NOT_FOUND_SUB_TASK)); + return findById(subTaskId) + .orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_SUB_TASK)); + } + + default SubTask findOrCreateEtcSubTask(Task task, String etcName) { + return findSubTaskByTaskAndName(task, etcName) + .orElseGet(() -> { + SubTask etcSubTask = SubTask.builder() + .task(task) + .name(etcName) + .build(); + return save(etcSubTask); + }); } }