diff --git a/src/main/kotlin/fr/ziedelth/controllers/AnimeController.kt b/src/main/kotlin/fr/ziedelth/controllers/AnimeController.kt index be253ae..f4b6b58 100644 --- a/src/main/kotlin/fr/ziedelth/controllers/AnimeController.kt +++ b/src/main/kotlin/fr/ziedelth/controllers/AnimeController.kt @@ -144,6 +144,34 @@ class AnimeController : AttachmentController("/animes") { } } + @APIRoute + private fun Route.update() { + put { + println("PUT $prefix") + if (isUnauthorized()) return@put + + try { + val anime = call.receive() + var savedAnime = animeRepository.find(anime.uuid) + + if (savedAnime == null) { + call.respond(HttpStatusCode.NotFound, "Anime not found") + return@put + } + + if (!anime.description.isNullOrBlank()) { + savedAnime.description = anime.description + } + + savedAnime = animeRepository.save(savedAnime) + animeService.invalidateAll() + call.respond(HttpStatusCode.OK, savedAnime) + } catch (e: Exception) { + printError(call, e) + } + } + } + @APIRoute private fun Route.merge() { put("/merge") { diff --git a/src/main/kotlin/fr/ziedelth/controllers/EpisodeController.kt b/src/main/kotlin/fr/ziedelth/controllers/EpisodeController.kt index 2aa932a..17e21ae 100644 --- a/src/main/kotlin/fr/ziedelth/controllers/EpisodeController.kt +++ b/src/main/kotlin/fr/ziedelth/controllers/EpisodeController.kt @@ -131,13 +131,15 @@ class EpisodeController : AttachmentController("/episodes") { val tmpNextSimulcast = Simulcast.getSimulcastFrom(releaseDatePlus10Days.toISO8601()) if (episode.number == 1 && tmpSimulcast != tmpNextSimulcast) { - val simulcast = simulcastRepository.findBySeasonAndYear(tmpNextSimulcast.season!!, tmpNextSimulcast.year!!) ?: tmpNextSimulcast + val simulcast = simulcastRepository.findBySeasonAndYear(tmpNextSimulcast.season!!, tmpNextSimulcast.year!!) + ?: tmpNextSimulcast if (episode.anime!!.simulcasts.isEmpty() || episode.anime!!.simulcasts.none { it.uuid == simulcast.uuid }) { episode.anime!!.simulcasts.add(simulcast) } } else { - val simulcast = simulcastRepository.findBySeasonAndYear(tmpSimulcast.season!!, tmpSimulcast.year!!) ?: tmpSimulcast + val simulcast = + simulcastRepository.findBySeasonAndYear(tmpSimulcast.season!!, tmpSimulcast.year!!) ?: tmpSimulcast if (episode.anime!!.simulcasts.isEmpty() || episode.anime!!.simulcasts.none { it.uuid == simulcast.uuid }) { episode.anime!!.simulcasts.add(simulcast) diff --git a/src/main/kotlin/fr/ziedelth/entities/Anime.kt b/src/main/kotlin/fr/ziedelth/entities/Anime.kt index 6b54918..dfa6fcd 100644 --- a/src/main/kotlin/fr/ziedelth/entities/Anime.kt +++ b/src/main/kotlin/fr/ziedelth/entities/Anime.kt @@ -40,7 +40,7 @@ class Anime( @Column(nullable = false, columnDefinition = "TEXT") val image: String? = null, @Column(nullable = true, columnDefinition = "TEXT") - val description: String? = null, + var description: String? = null, @ElementCollection(fetch = FetchType.LAZY) @CollectionTable( name = "anime_hash", diff --git a/src/test/kotlin/fr/ziedelth/controllers/EpisodeControllerTest.kt b/src/test/kotlin/fr/ziedelth/controllers/EpisodeControllerTest.kt index 4790fd2..e5c923f 100644 --- a/src/test/kotlin/fr/ziedelth/controllers/EpisodeControllerTest.kt +++ b/src/test/kotlin/fr/ziedelth/controllers/EpisodeControllerTest.kt @@ -241,13 +241,15 @@ internal class EpisodeControllerTest : AbstractAPITest() { val json = Constant.gson.fromJson(response.bodyAsText(), Array::class.java) expect(2) { json.size } - val simulcasts = json[0].anime?.simulcasts?.toMutableList()?.sortedWith(compareBy({ it.year }, { Constant.seasons.indexOf(it.season) })) + val simulcasts = json[0].anime?.simulcasts?.toMutableList() + ?.sortedWith(compareBy({ it.year }, { Constant.seasons.indexOf(it.season) })) println(simulcasts) expect(tmpNextSimulcast.season) { simulcasts?.last()?.season } expect(tmpNextSimulcast.year) { simulcasts?.last()?.year } - val simulcasts2 = json[1].anime?.simulcasts?.toMutableList()?.sortedWith(compareBy({ it.year }, { Constant.seasons.indexOf(it.season) })) + val simulcasts2 = json[1].anime?.simulcasts?.toMutableList() + ?.sortedWith(compareBy({ it.year }, { Constant.seasons.indexOf(it.season) })) println(simulcasts2) expect(tmpSimulcast.season) { simulcasts2?.last()?.season } expect(tmpSimulcast.year) { simulcasts2?.last()?.year }