Files
TrisolarisServer/src/main/kotlin/com/android/trisolarisserver/component/BookingEvents.kt
androidlover5842 69df1429fa
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s
Add booking SSE stream and emit on updates
2026-01-31 13:30:51 +05:30

36 lines
1.0 KiB
Kotlin

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
)