Auto-assign room image order on upload
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s

This commit is contained in:
androidlover5842
2026-01-27 16:33:26 +05:30
parent 6b4cac0235
commit 9049face76
2 changed files with 10 additions and 4 deletions

View File

@@ -58,8 +58,6 @@ class RoomImages(
@PathVariable roomId: UUID,
@AuthenticationPrincipal principal: MyPrincipal?,
@RequestParam("file") file: MultipartFile,
@RequestParam(required = false) roomSortOrder: Int?,
@RequestParam(required = false) roomTypeSortOrder: Int?,
@RequestParam(required = false) tags: List<String>?
): RoomImageResponse {
requirePrincipal(principal)
@@ -76,6 +74,8 @@ class RoomImages(
throw ResponseStatusException(HttpStatus.BAD_REQUEST, ex.message ?: "Invalid image")
}
val nextRoomSortOrder = roomImageRepo.findMaxRoomSortOrder(roomId) + 1
val nextRoomTypeSortOrder = roomImageRepo.findMaxRoomTypeSortOrder(room.roomType.code) + 1
val image = RoomImage(
property = room.property,
room = room,
@@ -85,8 +85,8 @@ class RoomImages(
sizeBytes = stored.sizeBytes,
roomTypeCode = room.roomType.code,
tags = tags?.toMutableSet() ?: mutableSetOf(),
roomSortOrder = roomSortOrder ?: 0,
roomTypeSortOrder = roomTypeSortOrder ?: 0
roomSortOrder = nextRoomSortOrder,
roomTypeSortOrder = nextRoomTypeSortOrder
)
return roomImageRepo.save(image).toResponse(publicBaseUrl)
}