Files
TrisolarisServer/src/main/kotlin/com/android/trisolarisserver/repo/IssuedCardRepo.kt
androidlover5842 385a66d5c5
All checks were successful
build-and-deploy / build-deploy (push) Successful in 1m33s
Revoke cards by cardIndex and drop cardId uniqueness
2026-01-28 18:24:40 +05:30

53 lines
2.2 KiB
Kotlin

package com.android.trisolarisserver.repo
import com.android.trisolarisserver.models.room.IssuedCard
import org.springframework.data.jpa.repository.JpaRepository
import java.util.UUID
interface IssuedCardRepo : JpaRepository<IssuedCard, UUID> {
fun findByRoomStayIdOrderByIssuedAtDesc(roomStayId: UUID): List<IssuedCard>
fun findByIdAndPropertyId(id: UUID, propertyId: UUID): IssuedCard?
fun findByCardIdIgnoreCaseAndPropertyId(cardId: String, propertyId: UUID): IssuedCard?
fun findAllByCardIdIgnoreCaseAndPropertyId(cardId: String, propertyId: UUID): List<IssuedCard>
fun findByPropertyIdAndCardIndex(propertyId: UUID, cardIndex: Int): IssuedCard?
@org.springframework.data.jpa.repository.Query("""
select case when count(c) > 0 then true else false end
from IssuedCard c
where c.property.id = :propertyId
and c.room.id = :roomId
and c.revokedAt is null
and c.expiresAt > :now
""")
fun existsActiveForRoom(
@org.springframework.data.repository.query.Param("propertyId") propertyId: UUID,
@org.springframework.data.repository.query.Param("roomId") roomId: UUID,
@org.springframework.data.repository.query.Param("now") now: java.time.OffsetDateTime
): Boolean
@org.springframework.data.jpa.repository.Query("""
select case when count(c) > 0 then true else false end
from IssuedCard c
where c.roomStay.id = :roomStayId
and c.revokedAt is null
and c.expiresAt > :now
""")
fun existsActiveForRoomStay(
@org.springframework.data.repository.query.Param("roomStayId") roomStayId: UUID,
@org.springframework.data.repository.query.Param("now") now: java.time.OffsetDateTime
): Boolean
@org.springframework.data.jpa.repository.Query("""
select c
from IssuedCard c
where c.property.id = :propertyId
and c.roomStay is null
and c.revokedAt is null
and c.expiresAt > :now
""")
fun findActiveTempCardsForProperty(
@org.springframework.data.repository.query.Param("propertyId") propertyId: UUID,
@org.springframework.data.repository.query.Param("now") now: java.time.OffsetDateTime
): List<IssuedCard>
}