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, maxOccupancy = request.maxOccupancy ?: 3,
sqFeet = request.sqFeet, sqFeet = request.sqFeet,
bathroomSqFeet = request.bathroomSqFeet, bathroomSqFeet = request.bathroomSqFeet,
active = request.active ?: true,
otaAliases = request.otaAliases?.toMutableSet() ?: mutableSetOf() otaAliases = request.otaAliases?.toMutableSet() ?: mutableSetOf()
) )
if (request.amenityIds != null) { if (request.amenityIds != null) {
@@ -115,6 +116,7 @@ class RoomTypes(
roomType.maxOccupancy = request.maxOccupancy ?: roomType.maxOccupancy roomType.maxOccupancy = request.maxOccupancy ?: roomType.maxOccupancy
roomType.sqFeet = request.sqFeet ?: roomType.sqFeet roomType.sqFeet = request.sqFeet ?: roomType.sqFeet
roomType.bathroomSqFeet = request.bathroomSqFeet ?: roomType.bathroomSqFeet roomType.bathroomSqFeet = request.bathroomSqFeet ?: roomType.bathroomSqFeet
roomType.active = request.active ?: roomType.active
if (request.otaAliases != null) { if (request.otaAliases != null) {
roomType.otaAliases = request.otaAliases.toMutableSet() roomType.otaAliases = request.otaAliases.toMutableSet()
} }
@@ -137,11 +139,8 @@ class RoomTypes(
val roomType = roomTypeRepo.findByIdAndPropertyId(roomTypeId, propertyId) val roomType = roomTypeRepo.findByIdAndPropertyId(roomTypeId, propertyId)
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Room type not found") ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Room type not found")
roomType.active = false
if (roomRepo.existsByPropertyIdAndRoomTypeId(propertyId, roomTypeId)) { roomTypeRepo.save(roomType)
throw ResponseStatusException(HttpStatus.CONFLICT, "Cannot delete room type with rooms")
}
roomTypeRepo.delete(roomType)
} }
private fun requirePrincipal(principal: MyPrincipal?) { private fun requirePrincipal(principal: MyPrincipal?) {
@@ -163,6 +162,7 @@ private fun RoomType.toResponse(): RoomTypeResponse {
maxOccupancy = maxOccupancy, maxOccupancy = maxOccupancy,
sqFeet = sqFeet, sqFeet = sqFeet,
bathroomSqFeet = bathroomSqFeet, bathroomSqFeet = bathroomSqFeet,
active = active,
otaAliases = otaAliases.toSet(), otaAliases = otaAliases.toSet(),
amenities = amenities.map { it.toResponse() }.toSet() amenities = amenities.map { it.toResponse() }.toSet()
) )

View File

@@ -9,6 +9,7 @@ data class RoomTypeUpsertRequest(
val maxOccupancy: Int? = null, val maxOccupancy: Int? = null,
val sqFeet: Int? = null, val sqFeet: Int? = null,
val bathroomSqFeet: Int? = null, val bathroomSqFeet: Int? = null,
val active: Boolean? = null,
val otaAliases: Set<String>? = null, val otaAliases: Set<String>? = null,
val amenityIds: Set<UUID>? = null val amenityIds: Set<UUID>? = null
) )
@@ -22,6 +23,7 @@ data class RoomTypeResponse(
val maxOccupancy: Int, val maxOccupancy: Int,
val sqFeet: Int?, val sqFeet: Int?,
val bathroomSqFeet: Int?, val bathroomSqFeet: Int?,
val active: Boolean,
val otaAliases: Set<String>, val otaAliases: Set<String>,
val amenities: Set<AmenityResponse> val amenities: Set<AmenityResponse>
) )

View File

@@ -38,6 +38,9 @@ class RoomType(
@Column(name = "bathroom_sq_feet") @Column(name = "bathroom_sq_feet")
var bathroomSqFeet: Int? = null, var bathroomSqFeet: Int? = null,
@Column(name = "is_active", nullable = false)
var active: Boolean = true,
@ElementCollection(fetch = FetchType.EAGER) @ElementCollection(fetch = FetchType.EAGER)
@CollectionTable( @CollectionTable(
name = "room_type_alias", name = "room_type_alias",