Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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,7 +1,6 @@
package com.indayvidual.server.domain.todo.dto.request;

import jakarta.validation.constraints.NotBlank;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ public interface TaskRepository extends JpaRepository<Task, Long> {
List<Task> findByUserIdAndCategoryIdAndDueDate(Long userId, Long categoryId, LocalDate date);

/**
* 특정 날짜와 카테고리 내에서 현재 등록된 Task의 최대 position을 조회합니다.
* 특정 날짜와 카테고리 내에서 현재 등록된 Task 중 최대 position인 Task을 조회합니다.
* <p>
* - 새로운 Task 생성 시 position 지정에 사용됩니다.
* - 값이 없으면 null을 반환합니다.
*
* @param categoryId
* @param date
* @return max position 값 (null 가능)
* @param dueDate
* @return max position 값의 task
*/
Integer findTopByCategoryIdAndDueDateOrderByPositionDesc(Long categoryId, LocalDate date);
Optional<Task> findTopByCategoryIdAndDueDateOrderByPositionDesc(Long categoryId, LocalDate dueDate);

List<Task> findAllByUserIdAndCategoryId(Long userId, Long categoryId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ public TaskResponseDTO createTask(Long userId, Long categoryId, TaskCreateReques
* @return 새로운 할 일의 position
*/
private Integer generateNextPosition(Long categoryId, LocalDate date) {
Integer max = taskRepository.findTopByCategoryIdAndDueDateOrderByPositionDesc(categoryId, date);
Integer max = taskRepository
.findTopByCategoryIdAndDueDateOrderByPositionDesc(categoryId, date)
.map(Task::getPosition)
.orElse(null); // empty -> null

if (max == null) {
log.debug("[TASK][generateNextPosition] max가 null이므로 기본값 0으로 시작합니다.");
return 0;
Expand Down