From b03a957b015a666c29bc8db07aeb4660fa46017e Mon Sep 17 00:00:00 2001 From: Ziedelth Date: Wed, 4 Oct 2023 17:13:39 +0200 Subject: [PATCH] Add deleteAnime function to AnimeController --- .../ziedelth/controllers/AnimeController.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/kotlin/fr/ziedelth/controllers/AnimeController.kt b/src/main/kotlin/fr/ziedelth/controllers/AnimeController.kt index f4b6b58..61ebc5f 100644 --- a/src/main/kotlin/fr/ziedelth/controllers/AnimeController.kt +++ b/src/main/kotlin/fr/ziedelth/controllers/AnimeController.kt @@ -172,6 +172,29 @@ class AnimeController : AttachmentController("/animes") { } } + @APIRoute + private fun Route.deleteAnime() { + delete("/{uuid}") { + try { + val uuid = UUID.fromString(call.parameters["uuid"]!!) + println("DELETE $prefix/$uuid") + if (isUnauthorized()) return@delete + val savedAnime = animeRepository.find(uuid) + + if (savedAnime == null) { + call.respond(HttpStatusCode.NotFound, "Anime not found") + return@delete + } + + animeRepository.delete(savedAnime) + animeService.invalidateAll() + call.respond(HttpStatusCode.NoContent) + } catch (e: Exception) { + printError(call, e) + } + } + } + @APIRoute private fun Route.merge() { put("/merge") {