-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 특정 날짜에 동일 코드가 있는지 확인하는 조건 QueryDsl로 개선
- Loading branch information
1 parent
3b2b331
commit 74da4db
Showing
5 changed files
with
45 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/org/idiot/yesslave/worktimer/repository/WorkTimerCustomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.idiot.yesslave.worktimer.repository; | ||
|
||
import org.idiot.yesslave.worktimer.domain.VerificationCode; | ||
import org.idiot.yesslave.worktimer.domain.WorkTimer; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Optional; | ||
|
||
public interface WorkTimerCustomRepository { | ||
Optional<WorkTimer> findByCheckInAndCode(LocalDate checkIn, VerificationCode code); | ||
} |
9 changes: 1 addition & 8 deletions
9
src/main/java/org/idiot/yesslave/worktimer/repository/WorkTimerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,8 @@ | ||
package org.idiot.yesslave.worktimer.repository; | ||
|
||
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.repository.query.Param; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
public interface WorkTimerRepository extends JpaRepository<WorkTimer, Long>, WorkTimerCustomRepository { | ||
|
||
public interface WorkTimerRepository extends JpaRepository<WorkTimer, Long> { | ||
|
||
Optional<WorkTimer> findByCheckInGreaterThanEqualAndCode(@Param("checkIn") LocalDateTime checkIn, @Param("code") VerificationCode code); | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/org/idiot/yesslave/worktimer/repository/WorkTimerRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.idiot.yesslave.worktimer.repository; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.idiot.yesslave.worktimer.domain.QWorkTimer; | ||
import org.idiot.yesslave.worktimer.domain.VerificationCode; | ||
import org.idiot.yesslave.worktimer.domain.WorkTimer; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Optional; | ||
|
||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class WorkTimerRepositoryImpl implements WorkTimerCustomRepository { | ||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
@Override | ||
public Optional<WorkTimer> findByCheckInAndCode(LocalDate checkIn, VerificationCode code) { | ||
QWorkTimer workTimer = QWorkTimer.workTimer; | ||
|
||
return Optional.ofNullable(jpaQueryFactory.selectFrom(workTimer) | ||
.where(workTimer.checkIn.after(checkIn.atStartOfDay()) | ||
.and(workTimer.checkIn.before(checkIn.plusDays(1).atStartOfDay())) | ||
.and(workTimer.code.eq(code))) | ||
.limit(1) | ||
.fetchOne()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters