Add booking SSE stream and emit on updates
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s

This commit is contained in:
androidlover5842
2026-01-31 13:30:51 +05:30
parent db6ea5d529
commit 69df1429fa
6 changed files with 163 additions and 55 deletions

View File

@@ -0,0 +1,35 @@
package com.android.trisolarisserver.component
import com.android.trisolarisserver.controller.BookingSnapshotBuilder
import com.android.trisolarisserver.controller.dto.BookingDetailResponse
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter
import java.util.UUID
@Component
class BookingEvents(
private val bookingSnapshotBuilder: BookingSnapshotBuilder
) {
private val hub = SseHub<BookingKey>("booking") { key ->
bookingSnapshotBuilder.build(key.propertyId, key.bookingId)
}
fun subscribe(propertyId: UUID, bookingId: UUID): SseEmitter {
return hub.subscribe(BookingKey(propertyId, bookingId))
}
fun emit(propertyId: UUID, bookingId: UUID) {
hub.emit(BookingKey(propertyId, bookingId))
}
@Scheduled(fixedDelayString = "25000")
fun heartbeat() {
hub.heartbeat()
}
}
private data class BookingKey(
val propertyId: UUID,
val bookingId: UUID
)

View File

@@ -19,7 +19,8 @@ class DocumentExtractionService(
private val propertyRepo: PropertyRepo,
private val paddleOcrClient: PaddleOcrClient,
private val bookingRepo: BookingRepo,
private val pincodeResolver: PincodeResolver
private val pincodeResolver: PincodeResolver,
private val bookingEvents: BookingEvents
) {
private val logger = LoggerFactory.getLogger(DocumentExtractionService::class.java)
@@ -476,6 +477,9 @@ class DocumentExtractionService(
if (updated) {
booking.updatedAt = OffsetDateTime.now()
bookingRepo.save(booking)
val propertyId = booking.property.id ?: return
val bookingId = booking.id ?: return
bookingEvents.emit(propertyId, bookingId)
}
}
}