Add guest document SSE stream
All checks were successful
build-and-deploy / build-deploy (push) Successful in 31s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 31s
This commit is contained in:
@@ -3,6 +3,7 @@ package com.android.trisolarisserver.controller
|
||||
import com.android.trisolarisserver.component.DocumentStorage
|
||||
import com.android.trisolarisserver.component.DocumentTokenService
|
||||
import com.android.trisolarisserver.component.ExtractionQueue
|
||||
import com.android.trisolarisserver.component.GuestDocumentEvents
|
||||
import com.android.trisolarisserver.component.LlamaClient
|
||||
import com.android.trisolarisserver.component.PropertyAccess
|
||||
import com.android.trisolarisserver.db.repo.BookingRepo
|
||||
@@ -42,6 +43,7 @@ class GuestDocuments(
|
||||
private val storage: DocumentStorage,
|
||||
private val tokenService: DocumentTokenService,
|
||||
private val extractionQueue: ExtractionQueue,
|
||||
private val guestDocumentEvents: GuestDocumentEvents,
|
||||
private val llamaClient: LlamaClient,
|
||||
private val objectMapper: ObjectMapper,
|
||||
@org.springframework.beans.factory.annotation.Value("\${storage.documents.publicBaseUrl}")
|
||||
@@ -107,6 +109,7 @@ class GuestDocuments(
|
||||
)
|
||||
val saved = guestDocumentRepo.save(document)
|
||||
runExtraction(saved.id!!, propertyId, guestId)
|
||||
guestDocumentEvents.emit(propertyId, guestId)
|
||||
return saved.toResponse(objectMapper)
|
||||
}
|
||||
|
||||
@@ -123,6 +126,16 @@ class GuestDocuments(
|
||||
.map { it.toResponse(objectMapper) }
|
||||
}
|
||||
|
||||
@GetMapping("/stream")
|
||||
fun streamDocuments(
|
||||
@PathVariable propertyId: UUID,
|
||||
@PathVariable guestId: UUID,
|
||||
@AuthenticationPrincipal principal: MyPrincipal?
|
||||
): org.springframework.web.servlet.mvc.method.annotation.SseEmitter {
|
||||
requireRole(propertyAccess, propertyId, principal, Role.ADMIN, Role.MANAGER)
|
||||
return guestDocumentEvents.subscribe(propertyId, guestId)
|
||||
}
|
||||
|
||||
@GetMapping("/{documentId}/file")
|
||||
fun downloadDocument(
|
||||
@PathVariable propertyId: UUID,
|
||||
@@ -183,6 +196,7 @@ class GuestDocuments(
|
||||
throw ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to delete file")
|
||||
}
|
||||
guestDocumentRepo.delete(document)
|
||||
guestDocumentEvents.emit(propertyId, guestId)
|
||||
}
|
||||
|
||||
private fun runExtraction(documentId: UUID, propertyId: UUID, guestId: UUID) {
|
||||
@@ -243,6 +257,7 @@ class GuestDocuments(
|
||||
document.extractedData = objectMapper.writeValueAsString(results)
|
||||
document.extractedAt = OffsetDateTime.now()
|
||||
guestDocumentRepo.save(document)
|
||||
guestDocumentEvents.emit(propertyId, guestId)
|
||||
} catch (_: Exception) {
|
||||
// Keep upload successful even if AI extraction fails.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user