Add guest create endpoint
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s
This commit is contained in:
@@ -113,6 +113,7 @@ Card issuing
|
|||||||
- POST /properties/{propertyId}/rooms/{roomId}/cards/temp
|
- POST /properties/{propertyId}/rooms/{roomId}/cards/temp
|
||||||
|
|
||||||
Guest APIs
|
Guest APIs
|
||||||
|
- POST /properties/{propertyId}/guests
|
||||||
- /properties/{propertyId}/guests/search?phone=... or ?vehicleNumber=...
|
- /properties/{propertyId}/guests/search?phone=... or ?vehicleNumber=...
|
||||||
- /properties/{propertyId}/guests/{guestId}/vehicles (add vehicle)
|
- /properties/{propertyId}/guests/{guestId}/vehicles (add vehicle)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.android.trisolarisserver.controller
|
package com.android.trisolarisserver.controller
|
||||||
|
|
||||||
import com.android.trisolarisserver.component.PropertyAccess
|
import com.android.trisolarisserver.component.PropertyAccess
|
||||||
|
import com.android.trisolarisserver.controller.dto.GuestCreateRequest
|
||||||
import com.android.trisolarisserver.controller.dto.GuestResponse
|
import com.android.trisolarisserver.controller.dto.GuestResponse
|
||||||
import com.android.trisolarisserver.controller.dto.GuestVehicleRequest
|
import com.android.trisolarisserver.controller.dto.GuestVehicleRequest
|
||||||
import com.android.trisolarisserver.models.booking.Guest
|
import com.android.trisolarisserver.models.booking.Guest
|
||||||
@@ -15,6 +16,7 @@ import org.springframework.http.HttpStatus
|
|||||||
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
import org.springframework.web.server.ResponseStatusException
|
import org.springframework.web.server.ResponseStatusException
|
||||||
|
import java.time.OffsetDateTime
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -28,6 +30,38 @@ class Guests(
|
|||||||
private val guestRatingRepo: GuestRatingRepo
|
private val guestRatingRepo: GuestRatingRepo
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
@ResponseStatus(HttpStatus.CREATED)
|
||||||
|
fun createGuest(
|
||||||
|
@PathVariable propertyId: UUID,
|
||||||
|
@AuthenticationPrincipal principal: MyPrincipal?,
|
||||||
|
@RequestBody request: GuestCreateRequest
|
||||||
|
): GuestResponse {
|
||||||
|
requireMember(propertyAccess, propertyId, principal)
|
||||||
|
val property = requireProperty(propertyRepo, propertyId)
|
||||||
|
|
||||||
|
val phone = request.phoneE164.trim()
|
||||||
|
if (phone.isBlank()) {
|
||||||
|
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "phoneE164 required")
|
||||||
|
}
|
||||||
|
val existing = guestRepo.findByPropertyIdAndPhoneE164(propertyId, phone)
|
||||||
|
if (existing != null) {
|
||||||
|
throw ResponseStatusException(HttpStatus.CONFLICT, "Guest already exists")
|
||||||
|
}
|
||||||
|
|
||||||
|
val now = OffsetDateTime.now()
|
||||||
|
val guest = Guest(
|
||||||
|
property = property,
|
||||||
|
phoneE164 = phone,
|
||||||
|
name = request.name?.trim()?.ifBlank { null },
|
||||||
|
nationality = request.nationality?.trim()?.ifBlank { null },
|
||||||
|
addressText = request.addressText?.trim()?.ifBlank { null },
|
||||||
|
updatedAt = now
|
||||||
|
)
|
||||||
|
guestRepo.save(guest)
|
||||||
|
return setOf(guest).toResponse(guestVehicleRepo, guestRatingRepo).first()
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/search")
|
@GetMapping("/search")
|
||||||
fun search(
|
fun search(
|
||||||
@PathVariable propertyId: UUID,
|
@PathVariable propertyId: UUID,
|
||||||
|
|||||||
@@ -49,6 +49,13 @@ data class GuestResponse(
|
|||||||
val averageScore: Double?
|
val averageScore: Double?
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class GuestCreateRequest(
|
||||||
|
val phoneE164: String,
|
||||||
|
val name: String? = null,
|
||||||
|
val nationality: String? = null,
|
||||||
|
val addressText: String? = null
|
||||||
|
)
|
||||||
|
|
||||||
data class GuestVehicleRequest(
|
data class GuestVehicleRequest(
|
||||||
val vehicleNumber: String,
|
val vehicleNumber: String,
|
||||||
val bookingId: UUID
|
val bookingId: UUID
|
||||||
|
|||||||
Reference in New Issue
Block a user