diff --git a/src/main/kotlin/com/example/onui/domain/diary/repository/QDiaryRepositoryImpl.kt b/src/main/kotlin/com/example/onui/domain/diary/repository/QDiaryRepositoryImpl.kt new file mode 100644 index 0000000..248b519 --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/diary/repository/QDiaryRepositoryImpl.kt @@ -0,0 +1,29 @@ +package com.example.onui.domain.diary.repository + +import com.example.onui.domain.diary.entity.Diary +import com.example.onui.domain.diary.entity.QDiary.diary +import com.example.onui.domain.user.entity.User +import com.querydsl.jpa.impl.JPAQueryFactory +import org.springframework.stereotype.Repository +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import java.time.LocalDateTime + +@Service +@Transactional(readOnly = true) +@Repository +class QDiaryRepositoryImpl( + private val queryFactory: JPAQueryFactory +): QDiaryRepository { + + override fun find3DayAgoByUser(user: User): Diary? { + + val ago = LocalDateTime.now().minusDays(3) + + return queryFactory.selectFrom(diary) + .orderBy(diary.createdAt.desc()) + .where(diary.user.eq(user).and(diary.createdAt.after(ago))) + .limit(1) + .fetchOne() + } +} \ No newline at end of file