Skip to content

Commit

Permalink
refactor: 날짜 조회하는 부분 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
zinzoddari committed Jan 7, 2024
1 parent d0da9f1 commit b61d0a1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public class WorkTimerService {
public Long registerTimer(LocalDateTime checkIn, AuthenticateCodeGenerator authenticateCodeStrategy) {

VerificationCode code = VerificationCode.create(authenticateCodeStrategy);
boolean isExistence = workTimerRepository.findByCheckInAndCode(checkIn.toLocalDate(), code).isPresent();
boolean isExistence = workTimerRepository.findByCheckInGreaterThanEqualAndCode(checkIn.toLocalDate().atStartOfDay(), code).isPresent();

while (isExistence) {
code = VerificationCode.create(authenticateCodeStrategy);
isExistence = workTimerRepository.findByCheckInAndCode(checkIn.toLocalDate(), code).isPresent();
isExistence = workTimerRepository.findByCheckInGreaterThanEqualAndCode(checkIn.toLocalDate().atStartOfDay(), code).isPresent();
}

return workTimerRepository.save(WorkTimer.registerOf(checkIn, code))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import org.idiot.yesslave.worktimer.domain.VerificationCode;
import org.idiot.yesslave.worktimer.domain.WorkTimer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Optional;

public interface WorkTimerRepository extends JpaRepository<WorkTimer, Long> {

@Query("SELECT wt FROM WorkTimer wt WHERE DATE(wt.checkIn) = :checkIn AND wt.code = :code")
Optional<WorkTimer> findByCheckInAndCode(@Param("checkIn") LocalDate checkIn, @Param("code") VerificationCode code);
Optional<WorkTimer> findByCheckInGreaterThanEqualAndCode(@Param("checkIn") LocalDateTime checkIn, @Param("code") VerificationCode code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void success() {

final WorkTimer expectedWorkTime = new WorkTimer(1L, checkIn, null, code);

given(workTimerRepository.findByCheckInAndCode(eq(checkIn.toLocalDate()), any(VerificationCode.class)))
given(workTimerRepository.findByCheckInGreaterThanEqualAndCode(eq(checkIn.toLocalDate().atStartOfDay()), any(VerificationCode.class)))
.willReturn(Optional.empty());

given(workTimerRepository.save(any(WorkTimer.class)))
Expand Down

0 comments on commit b61d0a1

Please sign in to comment.