From de4fc465868af5ed7e52d648371104e585f346a9 Mon Sep 17 00:00:00 2001 From: Cavin Date: Mon, 7 Sep 2026 22:52:40 +0300 Subject: [PATCH 1/2] chore(visitor): fix active visit protection and lifecycle transitions --- .../io/github/devcavin/gatelog/visitors/OverdueVisitJob.kt | 6 +++--- .../io/github/devcavin/gatelog/visitors/VisitService.kt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/io/github/devcavin/gatelog/visitors/OverdueVisitJob.kt b/src/main/kotlin/io/github/devcavin/gatelog/visitors/OverdueVisitJob.kt index bb1a917..211244d 100644 --- a/src/main/kotlin/io/github/devcavin/gatelog/visitors/OverdueVisitJob.kt +++ b/src/main/kotlin/io/github/devcavin/gatelog/visitors/OverdueVisitJob.kt @@ -32,7 +32,7 @@ class OverdueVisitJob( visitorStatusRepository.findByName("OVERDUE") ?: throw ResourceNotFoundException( "Visit Status", - "OVERDUE" + "OVERDUE".lowercase() ) val threshold = @@ -47,8 +47,8 @@ class OverdueVisitJob( val siteId = requireNotNull(site.id) val flagged = visitRepository.markOverdue( - threshold = threshold, - overdueStatus = overdueStatus + threshold, + overdueStatus ) if (flagged > 0) { diff --git a/src/main/kotlin/io/github/devcavin/gatelog/visitors/VisitService.kt b/src/main/kotlin/io/github/devcavin/gatelog/visitors/VisitService.kt index 5876994..ab4da21 100644 --- a/src/main/kotlin/io/github/devcavin/gatelog/visitors/VisitService.kt +++ b/src/main/kotlin/io/github/devcavin/gatelog/visitors/VisitService.kt @@ -143,7 +143,7 @@ class VisitService( visitId ) - if (visit.visitStatus.name != CHECKED_IN) { + if (visit.visitStatus.name != CHECKED_IN && visit.visitStatus.name != OVERDUE) { throw InvalidStateException( "Visitor is already ${ visit.visitStatus.name From a60e17628e5113d25bbe7886c0e74ee1d9a272a1 Mon Sep 17 00:00:00 2001 From: Cavin Date: Tue, 8 Sep 2026 21:04:39 +0300 Subject: [PATCH 2/2] fix(visits): enforce site scope and visit lifecycle rules --- .../gatelog/visitors/OverdueVisitJob.kt | 33 ++++--------------- .../gatelog/visitors/VisitResponseMapper.kt | 1 + 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/main/kotlin/io/github/devcavin/gatelog/visitors/OverdueVisitJob.kt b/src/main/kotlin/io/github/devcavin/gatelog/visitors/OverdueVisitJob.kt index 211244d..ad1f02f 100644 --- a/src/main/kotlin/io/github/devcavin/gatelog/visitors/OverdueVisitJob.kt +++ b/src/main/kotlin/io/github/devcavin/gatelog/visitors/OverdueVisitJob.kt @@ -2,7 +2,6 @@ package io.github.devcavin.gatelog.visitors import io.github.devcavin.gatelog.common.exception.ResourceNotFoundException import io.github.devcavin.gatelog.common.time.TimeUtil -import io.github.devcavin.gatelog.sites.SiteRepository import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Value import org.springframework.scheduling.annotation.Scheduled @@ -13,7 +12,6 @@ import org.springframework.transaction.annotation.Transactional class OverdueVisitJob( private val visitRepository: VisitRepository, private val visitorStatusRepository: VisitStatusRepository, - private val siteRepository: SiteRepository, private val timeUtil: TimeUtil, @Value($$"${gatelog.scheduler.overdue-threshold-hours:2}") @@ -38,34 +36,15 @@ class OverdueVisitJob( val threshold = timeUtil.timeNow().minusHours(overdueThresholdHours) - val sites = siteRepository.findAll() + val flagged = visitRepository.markOverdue( + threshold, + overdueStatus + ) - var totalFlagged = 0 - - sites.forEach { site -> - - val siteId = requireNotNull(site.id) - - val flagged = visitRepository.markOverdue( - threshold, - overdueStatus - ) - - if (flagged > 0) { - log.info( - "Flagged {} overdue visitor(s) at site {}", - flagged, - siteId - ) - } - - totalFlagged += flagged - } - - if (totalFlagged > 0) { + if (flagged > 0) { log.info( "Overdue job complete - {} visitor(s) flagged", - totalFlagged + flagged ) } } diff --git a/src/main/kotlin/io/github/devcavin/gatelog/visitors/VisitResponseMapper.kt b/src/main/kotlin/io/github/devcavin/gatelog/visitors/VisitResponseMapper.kt index a8d2028..217abe5 100644 --- a/src/main/kotlin/io/github/devcavin/gatelog/visitors/VisitResponseMapper.kt +++ b/src/main/kotlin/io/github/devcavin/gatelog/visitors/VisitResponseMapper.kt @@ -24,6 +24,7 @@ class VisitResponseMapper( purpose = visit.purpose, status = visit.visitStatus.name, siteId = requireNotNull(visit.site.id), + siteName = requireNotNull(visit.site.name), zoneId = visit.zone?.id, zoneName = visit.zone?.name, createdById = requireNotNull(visit.createdBy.id),