guestDocument: add missing files
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package com.android.trisolarisserver.controller
|
||||
|
||||
import com.android.trisolarisserver.models.booking.GuestDocument
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import java.util.UUID
|
||||
|
||||
data class GuestDocumentResponse(
|
||||
val id: UUID,
|
||||
val propertyId: UUID,
|
||||
val guestId: UUID,
|
||||
val bookingId: UUID,
|
||||
val uploadedByUserId: UUID,
|
||||
val uploadedAt: String,
|
||||
val originalFilename: String,
|
||||
val contentType: String?,
|
||||
val sizeBytes: Long,
|
||||
val extractedData: Map<String, String>?,
|
||||
val extractedAt: String?
|
||||
)
|
||||
|
||||
internal fun GuestDocument.toResponse(objectMapper: ObjectMapper): GuestDocumentResponse {
|
||||
val id = id ?: throw IllegalStateException("Document id missing")
|
||||
val extracted: Map<String, String>? = extractedData?.let {
|
||||
try {
|
||||
val raw = objectMapper.readValue(it, Map::class.java)
|
||||
raw.entries.associate { entry ->
|
||||
entry.key.toString() to (entry.value?.toString() ?: "")
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
return GuestDocumentResponse(
|
||||
id = id,
|
||||
propertyId = property.id!!,
|
||||
guestId = guest.id!!,
|
||||
bookingId = booking.id!!,
|
||||
uploadedByUserId = uploadedBy.id!!,
|
||||
uploadedAt = uploadedAt.toString(),
|
||||
originalFilename = originalFilename,
|
||||
contentType = contentType,
|
||||
sizeBytes = sizeBytes,
|
||||
extractedData = extracted,
|
||||
extractedAt = extractedAt?.toString()
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user