Add bookings list endpoint with status filter
Some checks failed
build-and-deploy / build-deploy (push) Failing after 29s
Some checks failed
build-and-deploy / build-deploy (push) Failing after 29s
This commit is contained in:
@@ -9,6 +9,7 @@ import com.android.trisolarisserver.controller.dto.BookingCreateRequest
|
||||
import com.android.trisolarisserver.controller.dto.BookingCreateResponse
|
||||
import com.android.trisolarisserver.controller.dto.BookingLinkGuestRequest
|
||||
import com.android.trisolarisserver.controller.dto.BookingNoShowRequest
|
||||
import com.android.trisolarisserver.controller.dto.BookingListItem
|
||||
import com.android.trisolarisserver.controller.dto.RoomStayPreAssignRequest
|
||||
import com.android.trisolarisserver.db.repo.BookingRepo
|
||||
import com.android.trisolarisserver.db.repo.GuestDocumentRepo
|
||||
@@ -30,8 +31,10 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RequestParam
|
||||
import org.springframework.web.bind.annotation.ResponseStatus
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
@@ -127,6 +130,40 @@ class BookingFlow(
|
||||
)
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
fun listBookings(
|
||||
@PathVariable propertyId: UUID,
|
||||
@AuthenticationPrincipal principal: MyPrincipal?,
|
||||
@RequestParam(required = false) status: String?
|
||||
): List<BookingListItem> {
|
||||
requireMember(propertyAccess, propertyId, principal)
|
||||
val statuses = parseStatuses(status)
|
||||
val bookings = if (statuses.isEmpty()) {
|
||||
bookingRepo.findByPropertyIdOrderByCreatedAtDesc(propertyId)
|
||||
} else {
|
||||
bookingRepo.findByPropertyIdAndStatusInOrderByCreatedAtDesc(propertyId, statuses)
|
||||
}
|
||||
return bookings.map { booking ->
|
||||
BookingListItem(
|
||||
id = booking.id!!,
|
||||
status = booking.status.name,
|
||||
guestId = booking.primaryGuest?.id,
|
||||
source = booking.source,
|
||||
expectedCheckInAt = booking.expectedCheckinAt?.toString(),
|
||||
expectedCheckOutAt = booking.expectedCheckoutAt?.toString(),
|
||||
checkInAt = booking.checkinAt?.toString(),
|
||||
checkOutAt = booking.checkoutAt?.toString(),
|
||||
adultCount = booking.adultCount,
|
||||
childCount = booking.childCount,
|
||||
maleCount = booking.maleCount,
|
||||
femaleCount = booking.femaleCount,
|
||||
totalGuestCount = booking.totalGuestCount,
|
||||
expectedGuestCount = booking.expectedGuestCount,
|
||||
notes = booking.notes
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/{bookingId}/link-guest")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
@Transactional
|
||||
@@ -272,6 +309,21 @@ class BookingFlow(
|
||||
return guestRepo.save(guest)
|
||||
}
|
||||
|
||||
private fun parseStatuses(raw: String?): Set<BookingStatus> {
|
||||
if (raw.isNullOrBlank()) return emptySet()
|
||||
return raw.split(",")
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotEmpty() }
|
||||
.map { value ->
|
||||
try {
|
||||
BookingStatus.valueOf(value.uppercase())
|
||||
} catch (_: IllegalArgumentException) {
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid status: $value")
|
||||
}
|
||||
}
|
||||
.toSet()
|
||||
}
|
||||
|
||||
@PostMapping("/{bookingId}/cancel")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
@Transactional
|
||||
|
||||
@@ -35,6 +35,24 @@ data class BookingCreateResponse(
|
||||
val expectedCheckOutAt: String?
|
||||
)
|
||||
|
||||
data class BookingListItem(
|
||||
val id: UUID,
|
||||
val status: String,
|
||||
val guestId: UUID?,
|
||||
val source: String?,
|
||||
val expectedCheckInAt: String?,
|
||||
val expectedCheckOutAt: String?,
|
||||
val checkInAt: String?,
|
||||
val checkOutAt: String?,
|
||||
val adultCount: Int?,
|
||||
val childCount: Int?,
|
||||
val maleCount: Int?,
|
||||
val femaleCount: Int?,
|
||||
val totalGuestCount: Int?,
|
||||
val expectedGuestCount: Int?,
|
||||
val notes: String?
|
||||
)
|
||||
|
||||
data class BookingLinkGuestRequest(
|
||||
val guestId: UUID
|
||||
)
|
||||
|
||||
@@ -8,4 +8,6 @@ interface BookingRepo : JpaRepository<Booking, UUID> {
|
||||
fun findByPropertyIdAndSourceBookingId(propertyId: UUID, sourceBookingId: String): Booking?
|
||||
fun existsByPropertyIdAndSourceBookingId(propertyId: UUID, sourceBookingId: String): Boolean
|
||||
fun countByPrimaryGuestId(guestId: UUID): Long
|
||||
fun findByPropertyIdAndStatusInOrderByCreatedAtDesc(propertyId: UUID, status: Collection<com.android.trisolarisserver.models.booking.BookingStatus>): List<Booking>
|
||||
fun findByPropertyIdOrderByCreatedAtDesc(propertyId: UUID): List<Booking>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user