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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user