Allow rate plan code per room type
All checks were successful
build-and-deploy / build-deploy (push) Successful in 35s

This commit is contained in:
androidlover5842
2026-01-29 05:35:19 +05:30
parent ac9df5f4bd
commit 3546b2de62
4 changed files with 47 additions and 4 deletions

View File

@@ -50,14 +50,14 @@ class RatePlans(
@RequestBody request: RatePlanCreateRequest
): RatePlanResponse {
requireRole(propertyAccess, propertyId, principal, Role.ADMIN, Role.MANAGER)
if (ratePlanRepo.existsByPropertyIdAndCode(propertyId, request.code.trim())) {
throw ResponseStatusException(HttpStatus.CONFLICT, "Rate plan code already exists")
}
val property = propertyRepo.findById(propertyId).orElseThrow {
ResponseStatusException(HttpStatus.NOT_FOUND, "Property not found")
}
val roomType = roomTypeRepo.findByPropertyIdAndCodeIgnoreCase(propertyId, request.roomTypeCode)
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Room type not found")
if (ratePlanRepo.existsByPropertyIdAndRoomTypeIdAndCode(propertyId, roomType.id!!, request.code.trim())) {
throw ResponseStatusException(HttpStatus.CONFLICT, "Rate plan code already exists for room type")
}
val plan = RatePlan(
property = property,