Skip to content

Commit

Permalink
⭐️ :: find3DayAgoByUser
Browse files Browse the repository at this point in the history
  • Loading branch information
gurdl0525 committed Nov 1, 2023
1 parent 1e38093 commit bc95b7a
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit bc95b7a

Please sign in to comment.