Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #167 from Z-Jais/master
Browse files Browse the repository at this point in the history
Add PUT update function in AnimeController
  • Loading branch information
Ziedelth authored Sep 28, 2023
2 parents 125df75 + 82c0317 commit fcd983a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
28 changes: 28 additions & 0 deletions src/main/kotlin/fr/ziedelth/controllers/AnimeController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,34 @@ class AnimeController : AttachmentController<Anime>("/animes") {
}
}

@APIRoute
private fun Route.update() {
put {
println("PUT $prefix")
if (isUnauthorized()) return@put

try {
val anime = call.receive<Anime>()
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") {
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/fr/ziedelth/controllers/EpisodeController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,15 @@ class EpisodeController : AttachmentController<Episode>("/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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/fr/ziedelth/entities/Anime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,15 @@ internal class EpisodeControllerTest : AbstractAPITest() {
val json = Constant.gson.fromJson(response.bodyAsText(), Array<Episode>::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 }
Expand Down

0 comments on commit fcd983a

Please sign in to comment.