Skip to content
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

[FIX] 업무 카드 생성 시, 세부 업무 작성 안하면 '기타' 업무로 분류 & 업무 내 키워드 목록 조회 로직 수정 #113

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<KeywordGetResponseDto>> getAllKeyword(@PathVariable Long cardId) {
return ApiResponseDto.success(keywordService.getAllKeyword(cardId));
public ApiResponseDto<List<KeywordGetResponseDto>> getAllKeyword(@PathVariable Long taskId) {
return ApiResponseDto.success(keywordService.getAllKeyword(taskId));
}

@Operation(summary = "키워드 생성 API")
Expand All @@ -44,7 +44,7 @@ public ApiResponseDto<List<KeywordGetResponseDto>> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SubTask, Long> {
List<SubTask> findAllByTaskId(Long taskId);

Optional<SubTask> 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);
});
}
}
Loading