Add detailed room create debug steps and exception header
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s
This commit is contained in:
@@ -189,32 +189,52 @@ class Rooms(
|
|||||||
response.setHeader("X-Room-Create-Step", "member_ok")
|
response.setHeader("X-Room-Create-Step", "member_ok")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (roomRepo.existsByPropertyIdAndRoomNumber(propertyId, request.roomNumber)) {
|
try {
|
||||||
throw ResponseStatusException(HttpStatus.CONFLICT, "Room number already exists for property")
|
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 {
|
if (debugAuth == "1") {
|
||||||
ResponseStatusException(HttpStatus.NOT_FOUND, "Property not found")
|
response.setHeader("X-Room-Create-Step", "load_property")
|
||||||
}
|
}
|
||||||
val roomType = resolveRoomType(propertyId, request)
|
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(
|
val room = Room(
|
||||||
property = property,
|
property = property,
|
||||||
roomType = roomType,
|
roomType = roomType,
|
||||||
roomNumber = request.roomNumber,
|
roomNumber = request.roomNumber,
|
||||||
floor = request.floor,
|
floor = request.floor,
|
||||||
hasNfc = request.hasNfc,
|
hasNfc = request.hasNfc,
|
||||||
active = request.active,
|
active = request.active,
|
||||||
maintenance = request.maintenance,
|
maintenance = request.maintenance,
|
||||||
notes = request.notes
|
notes = request.notes
|
||||||
)
|
)
|
||||||
|
|
||||||
val saved = roomRepo.save(room).toRoomResponse()
|
if (debugAuth == "1") {
|
||||||
if (debugAuth == "1") {
|
response.setHeader("X-Room-Create-Step", "save_room")
|
||||||
response.setHeader("X-Room-Create-Step", "saved")
|
}
|
||||||
|
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}")
|
@PutMapping("/{roomId}")
|
||||||
|
|||||||
Reference in New Issue
Block a user