Soft-disable room types instead of delete
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s

This commit is contained in:
androidlover5842
2026-01-27 17:24:42 +05:30
parent 4c21830eb0
commit bcfe9fbf2a
3 changed files with 10 additions and 5 deletions

View File

@@ -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()
)

View File

@@ -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>
)