Add guest update endpoint
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s

This commit is contained in:
androidlover5842
2026-01-29 08:28:41 +05:30
parent e61393fc41
commit 708ab95a31
2 changed files with 38 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import com.android.trisolarisserver.component.PropertyAccess
import com.android.trisolarisserver.component.GuestSignatureStorage
import com.android.trisolarisserver.controller.dto.GuestCreateRequest
import com.android.trisolarisserver.controller.dto.GuestResponse
import com.android.trisolarisserver.controller.dto.GuestUpdateRequest
import com.android.trisolarisserver.controller.dto.GuestVehicleRequest
import com.android.trisolarisserver.models.booking.Guest
import com.android.trisolarisserver.models.booking.GuestVehicle
@@ -101,6 +102,36 @@ class Guests(
return setOf(saved).toResponse(propertyId, guestVehicleRepo, guestRatingRepo).first()
}
@PutMapping("/{guestId}")
fun updateGuest(
@PathVariable propertyId: UUID,
@PathVariable guestId: UUID,
@AuthenticationPrincipal principal: MyPrincipal?,
@RequestBody request: GuestUpdateRequest
): GuestResponse {
requireMember(propertyAccess, propertyId, principal)
val (_, guest) = requirePropertyGuest(propertyRepo, guestRepo, propertyId, guestId)
val phone = request.phoneE164?.trim()?.takeIf { it.isNotBlank() }
if (phone != null) {
val existing = guestRepo.findByPropertyIdAndPhoneE164(propertyId, phone)
if (existing != null && existing.id != guest.id) {
throw ResponseStatusException(HttpStatus.CONFLICT, "Phone number already exists")
}
guest.phoneE164 = phone
}
val name = request.name?.trim()?.ifBlank { null }
val nationality = request.nationality?.trim()?.ifBlank { null }
val address = request.addressText?.trim()?.ifBlank { null }
if (name != null) guest.name = name
if (nationality != null) guest.nationality = nationality
if (address != null) guest.addressText = address
guest.updatedAt = OffsetDateTime.now()
val saved = guestRepo.save(guest)
return setOf(saved).toResponse(propertyId, guestVehicleRepo, guestRatingRepo).first()
}
@GetMapping("/search")
fun search(
@PathVariable propertyId: UUID,

View File

@@ -58,6 +58,13 @@ data class GuestCreateRequest(
val addressText: String? = null
)
data class GuestUpdateRequest(
val phoneE164: String? = null,
val name: String? = null,
val nationality: String? = null,
val addressText: String? = null
)
data class GuestVehicleRequest(
val vehicleNumber: String,
val bookingId: UUID