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
Expand Up @@ -3,6 +3,7 @@
import com.Timo.Timo.domain.timer.entity.TimerRecord;
import com.Timo.Timo.domain.timer.enums.TimerStatus;
import jakarta.persistence.LockModeType;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
Expand All @@ -18,6 +19,9 @@ public interface TimerRecordRepository extends JpaRepository<TimerRecord, Long>

boolean existsByTodo_IdAndStatusIn(Long todoId, List<TimerStatus> statuses);

boolean existsByTodo_IdAndTargetDateAndStatusIn(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저 ".. Todo_Id .."에서 _가 뭘 의미하는 거였죠,, 합숙하면서 들었었는데 까먹었습니다..😥

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 todo의 id를 말합니다. 보통 sql문으로 쓸때는 todo.id로 불러올텐데 메서드명으로 쓸 때는 저렇게 Todo_Id로 표기하는 것으로 알고 있습니다

Long todoId, LocalDate targetDate, List<TimerStatus> statuses);

@Modifying(clearAutomatically = true)
@Query("delete from TimerRecord r where r.todo.id = :todoId")
void deleteByTodoId(@Param("todoId") Long todoId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ public boolean hasActiveTimer(Long todoId) {
return timerRecordRepository.existsByTodo_IdAndStatusIn(todoId, ACTIVE_STATUS);
}

public boolean hasActiveTimerOn(Long todoId, LocalDate date) {
return timerRecordRepository.existsByTodo_IdAndTargetDateAndStatusIn(todoId, date, ACTIVE_STATUS);
}

@Transactional
public void deleteTimersByTodo(Long todoId) {
timerSessionRepository.deleteByTodoId(todoId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public TodoStatusChangeResponse changeCompletion(Long userId, Long todoId, TodoS
throw new CustomException(TodoErrorCode.TODO_NOT_FOUND);
}

if (timerService.hasActiveTimer(todoId)) {
if (timerService.hasActiveTimerOn(todoId, date)) {
throw new CustomException(TodoErrorCode.TIMER_RUNNING);
}

Expand Down