Soft-disable room types instead of delete
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:
@@ -72,6 +72,7 @@ class RoomTypes(
|
||||
maxOccupancy = request.maxOccupancy ?: 3,
|
||||
sqFeet = request.sqFeet,
|
||||
bathroomSqFeet = request.bathroomSqFeet,
|
||||
active = request.active ?: true,
|
||||
otaAliases = request.otaAliases?.toMutableSet() ?: mutableSetOf()
|
||||
)
|
||||
if (request.amenityIds != null) {
|
||||
@@ -115,6 +116,7 @@ class RoomTypes(
|
||||
roomType.maxOccupancy = request.maxOccupancy ?: roomType.maxOccupancy
|
||||
roomType.sqFeet = request.sqFeet ?: roomType.sqFeet
|
||||
roomType.bathroomSqFeet = request.bathroomSqFeet ?: roomType.bathroomSqFeet
|
||||
roomType.active = request.active ?: roomType.active
|
||||
if (request.otaAliases != null) {
|
||||
roomType.otaAliases = request.otaAliases.toMutableSet()
|
||||
}
|
||||
@@ -137,11 +139,8 @@ class RoomTypes(
|
||||
|
||||
val roomType = roomTypeRepo.findByIdAndPropertyId(roomTypeId, propertyId)
|
||||
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Room type not found")
|
||||
|
||||
if (roomRepo.existsByPropertyIdAndRoomTypeId(propertyId, roomTypeId)) {
|
||||
throw ResponseStatusException(HttpStatus.CONFLICT, "Cannot delete room type with rooms")
|
||||
}
|
||||
roomTypeRepo.delete(roomType)
|
||||
roomType.active = false
|
||||
roomTypeRepo.save(roomType)
|
||||
}
|
||||
|
||||
private fun requirePrincipal(principal: MyPrincipal?) {
|
||||
@@ -163,6 +162,7 @@ private fun RoomType.toResponse(): RoomTypeResponse {
|
||||
maxOccupancy = maxOccupancy,
|
||||
sqFeet = sqFeet,
|
||||
bathroomSqFeet = bathroomSqFeet,
|
||||
active = active,
|
||||
otaAliases = otaAliases.toSet(),
|
||||
amenities = amenities.map { it.toResponse() }.toSet()
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ data class RoomTypeUpsertRequest(
|
||||
val maxOccupancy: Int? = null,
|
||||
val sqFeet: Int? = null,
|
||||
val bathroomSqFeet: Int? = null,
|
||||
val active: Boolean? = null,
|
||||
val otaAliases: Set<String>? = null,
|
||||
val amenityIds: Set<UUID>? = null
|
||||
)
|
||||
@@ -22,6 +23,7 @@ data class RoomTypeResponse(
|
||||
val maxOccupancy: Int,
|
||||
val sqFeet: Int?,
|
||||
val bathroomSqFeet: Int?,
|
||||
val active: Boolean,
|
||||
val otaAliases: Set<String>,
|
||||
val amenities: Set<AmenityResponse>
|
||||
)
|
||||
|
||||
@@ -38,6 +38,9 @@ class RoomType(
|
||||
@Column(name = "bathroom_sq_feet")
|
||||
var bathroomSqFeet: Int? = null,
|
||||
|
||||
@Column(name = "is_active", nullable = false)
|
||||
var active: Boolean = true,
|
||||
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@CollectionTable(
|
||||
name = "room_type_alias",
|
||||
|
||||
Reference in New Issue
Block a user