Delete image tags and unlink from images
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
This commit is contained in:
@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.ResponseStatus
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import java.util.UUID
|
||||
|
||||
@RestController
|
||||
@@ -68,16 +69,15 @@ class RoomImageTags(
|
||||
|
||||
@DeleteMapping("/{tagId}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
@Transactional
|
||||
fun deleteTag(
|
||||
@PathVariable tagId: UUID,
|
||||
@AuthenticationPrincipal principal: MyPrincipal?
|
||||
) {
|
||||
requireSuperAdmin(principal)
|
||||
if (roomImageRepo.existsByTagsId(tagId)) {
|
||||
throw ResponseStatusException(HttpStatus.CONFLICT, "Tag is used by images")
|
||||
}
|
||||
val tag = roomImageTagRepo.findById(tagId).orElse(null)
|
||||
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Tag not found")
|
||||
roomImageRepo.deleteTagLinks(tagId)
|
||||
roomImageTagRepo.delete(tag)
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,10 @@ interface RoomImageRepo : JpaRepository<RoomImage, UUID> {
|
||||
fun existsByRoomIdAndContentHash(roomId: UUID, contentHash: String): Boolean
|
||||
fun existsByTagsId(id: UUID): Boolean
|
||||
|
||||
@org.springframework.data.jpa.repository.Modifying
|
||||
@Query(value = "delete from room_image_tag_link where tag_id = :tagId", nativeQuery = true)
|
||||
fun deleteTagLinks(@Param("tagId") tagId: UUID): Int
|
||||
|
||||
@Query("select coalesce(max(ri.roomSortOrder), 0) from RoomImage ri where ri.room.id = :roomId")
|
||||
fun findMaxRoomSortOrder(@Param("roomId") roomId: UUID): Int
|
||||
|
||||
|
||||
Reference in New Issue
Block a user