Add detailed room create debug steps and exception header
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s

This commit is contained in:
androidlover5842
2026-01-27 02:33:09 +05:30
parent 9aa1f71c32
commit c2c54d24f5

View File

@@ -189,32 +189,52 @@ class Rooms(
response.setHeader("X-Room-Create-Step", "member_ok")
}
if (roomRepo.existsByPropertyIdAndRoomNumber(propertyId, request.roomNumber)) {
throw ResponseStatusException(HttpStatus.CONFLICT, "Room number already exists for property")
}
try {
if (debugAuth == "1") {
response.setHeader("X-Room-Create-Step", "check_duplicate")
}
if (roomRepo.existsByPropertyIdAndRoomNumber(propertyId, request.roomNumber)) {
throw ResponseStatusException(HttpStatus.CONFLICT, "Room number already exists for property")
}
val property = propertyRepo.findById(propertyId).orElseThrow {
ResponseStatusException(HttpStatus.NOT_FOUND, "Property not found")
}
val roomType = resolveRoomType(propertyId, request)
if (debugAuth == "1") {
response.setHeader("X-Room-Create-Step", "load_property")
}
val property = propertyRepo.findById(propertyId).orElseThrow {
ResponseStatusException(HttpStatus.NOT_FOUND, "Property not found")
}
if (debugAuth == "1") {
response.setHeader("X-Room-Create-Step", "resolve_room_type")
}
val roomType = resolveRoomType(propertyId, request)
val room = Room(
property = property,
roomType = roomType,
roomNumber = request.roomNumber,
floor = request.floor,
hasNfc = request.hasNfc,
active = request.active,
maintenance = request.maintenance,
notes = request.notes
)
val room = Room(
property = property,
roomType = roomType,
roomNumber = request.roomNumber,
floor = request.floor,
hasNfc = request.hasNfc,
active = request.active,
maintenance = request.maintenance,
notes = request.notes
)
val saved = roomRepo.save(room).toRoomResponse()
if (debugAuth == "1") {
response.setHeader("X-Room-Create-Step", "saved")
if (debugAuth == "1") {
response.setHeader("X-Room-Create-Step", "save_room")
}
val saved = roomRepo.save(room).toRoomResponse()
if (debugAuth == "1") {
response.setHeader("X-Room-Create-Step", "saved")
}
roomBoardEvents.emit(propertyId)
return saved
} catch (ex: Exception) {
if (debugAuth == "1") {
val msg = ex.message?.take(200) ?: ""
response.setHeader("X-Room-Create-Exception", "${ex::class.java.simpleName}:$msg")
}
throw ex
}
roomBoardEvents.emit(propertyId)
return saved
}
@PutMapping("/{roomId}")