Add ordered categories for room images
All checks were successful
build-and-deploy / build-deploy (push) Successful in 28s

This commit is contained in:
androidlover5842
2026-01-27 16:04:01 +05:30
parent 46f9fecf4a
commit 7934b7efd5
4 changed files with 28 additions and 4 deletions

View File

@@ -47,7 +47,7 @@ class RoomImages(
requirePrincipal(principal) requirePrincipal(principal)
propertyAccess.requireMember(propertyId, principal!!.userId) propertyAccess.requireMember(propertyId, principal!!.userId)
ensureRoom(propertyId, roomId) ensureRoom(propertyId, roomId)
return roomImageRepo.findByRoomIdOrderByCreatedAtDesc(roomId) return roomImageRepo.findByRoomIdOrdered(roomId)
.map { it.toResponse(publicBaseUrl) } .map { it.toResponse(publicBaseUrl) }
} }
@@ -57,7 +57,9 @@ class RoomImages(
@PathVariable propertyId: UUID, @PathVariable propertyId: UUID,
@PathVariable roomId: UUID, @PathVariable roomId: UUID,
@AuthenticationPrincipal principal: MyPrincipal?, @AuthenticationPrincipal principal: MyPrincipal?,
@RequestParam("file") file: MultipartFile @RequestParam("file") file: MultipartFile,
@RequestParam(required = false) sortOrder: Int?,
@RequestParam(required = false) category: String?
): RoomImageResponse { ): RoomImageResponse {
requirePrincipal(principal) requirePrincipal(principal)
propertyAccess.requireMember(propertyId, principal!!.userId) propertyAccess.requireMember(propertyId, principal!!.userId)
@@ -79,7 +81,9 @@ class RoomImages(
originalPath = stored.originalPath, originalPath = stored.originalPath,
thumbnailPath = stored.thumbnailPath, thumbnailPath = stored.thumbnailPath,
contentType = stored.contentType, contentType = stored.contentType,
sizeBytes = stored.sizeBytes sizeBytes = stored.sizeBytes,
sortOrder = sortOrder,
category = category
) )
return roomImageRepo.save(image).toResponse(publicBaseUrl) return roomImageRepo.save(image).toResponse(publicBaseUrl)
} }
@@ -134,6 +138,8 @@ private fun RoomImage.toResponse(baseUrl: String): RoomImageResponse {
thumbnailUrl = "$baseUrl/properties/${property.id}/rooms/${room.id}/images/$id/file?size=thumb", thumbnailUrl = "$baseUrl/properties/${property.id}/rooms/${room.id}/images/$id/file?size=thumb",
contentType = contentType, contentType = contentType,
sizeBytes = sizeBytes, sizeBytes = sizeBytes,
sortOrder = sortOrder,
category = category,
createdAt = createdAt.toString() createdAt = createdAt.toString()
) )
} }

View File

@@ -38,6 +38,8 @@ data class RoomImageResponse(
val thumbnailUrl: String, val thumbnailUrl: String,
val contentType: String, val contentType: String,
val sizeBytes: Long, val sizeBytes: Long,
val sortOrder: Int?,
val category: String?,
val createdAt: String val createdAt: String
) )

View File

@@ -33,6 +33,12 @@ class RoomImage(
@Column(name = "size_bytes", nullable = false) @Column(name = "size_bytes", nullable = false)
var sizeBytes: Long, var sizeBytes: Long,
@Column(name = "sort_order")
var sortOrder: Int? = null,
@Column
var category: String? = null,
@Column(name = "created_at", nullable = false, columnDefinition = "timestamptz") @Column(name = "created_at", nullable = false, columnDefinition = "timestamptz")
val createdAt: OffsetDateTime = OffsetDateTime.now() val createdAt: OffsetDateTime = OffsetDateTime.now()
) )

View File

@@ -1,10 +1,20 @@
package com.android.trisolarisserver.repo package com.android.trisolarisserver.repo
import com.android.trisolarisserver.models.room.RoomImage import com.android.trisolarisserver.models.room.RoomImage
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.JpaRepository
import java.util.UUID import java.util.UUID
interface RoomImageRepo : JpaRepository<RoomImage, UUID> { interface RoomImageRepo : JpaRepository<RoomImage, UUID> {
fun findByRoomIdOrderByCreatedAtDesc(roomId: UUID): List<RoomImage> @Query(
"""
select ri
from RoomImage ri
where ri.room.id = :roomId
order by (ri.sortOrder is null), ri.sortOrder asc, ri.createdAt desc
"""
)
fun findByRoomIdOrdered(@Param("roomId") roomId: UUID): List<RoomImage>
fun findByIdAndRoomIdAndPropertyId(id: UUID, roomId: UUID, propertyId: UUID): RoomImage? fun findByIdAndRoomIdAndPropertyId(id: UUID, roomId: UUID, propertyId: UUID): RoomImage?
} }