Skip to content

Commit

Permalink
Fix calendar anime seasons
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Aug 14, 2024
1 parent 382f349 commit 6a169bc
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 123 deletions.
10 changes: 5 additions & 5 deletions src/main/kotlin/fr/shikkanime/controllers/api/AnimeController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fr.shikkanime.controllers.api
import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.*
import fr.shikkanime.dtos.animes.DetailedAnimeDto
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.entities.enums.CountryCode
import fr.shikkanime.services.AnimeService
Expand Down Expand Up @@ -117,16 +117,16 @@ class AnimeController : HasPageableRoute() {
private fun animeDetails(
@PathParam("uuid") uuid: UUID,
): Response {
return Response.ok(AbstractConverter.convert(animeService.findLoaded(uuid), DetailedAnimeDto::class.java))
return Response.ok(AbstractConverter.convert(animeService.findLoaded(uuid), AnimeDto::class.java))
}

@Path("/{uuid}")
@Put
@AdminSessionAuthenticated
@OpenAPI(hidden = true)
private fun updateAnime(@PathParam("uuid") uuid: UUID, @BodyParam detailedAnimeDto: DetailedAnimeDto): Response {
val updated = animeService.update(uuid, detailedAnimeDto)
return Response.ok(AbstractConverter.convert(updated, DetailedAnimeDto::class.java))
private fun updateAnime(@PathParam("uuid") uuid: UUID, @BodyParam animeDto: AnimeDto): Response {
val updated = animeService.update(uuid, animeDto)
return Response.ok(AbstractConverter.convert(updated, AnimeDto::class.java))
}

@Path("/{uuid}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.shikkanime.controllers.site

import com.google.inject.Inject
import fr.shikkanime.dtos.animes.DetailedAnimeDto
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.entities.SortParameter
import fr.shikkanime.entities.enums.ConfigPropertyKey
import fr.shikkanime.entities.enums.CountryCode
Expand Down Expand Up @@ -48,7 +48,7 @@ class SiteController {
)
}

private fun getFullAnimesSimulcast(): MutableList<DetailedAnimeDto> {
private fun getFullAnimesSimulcast(): MutableList<AnimeDto> {
val animeSimulcastLimit = 6

val animes = animeCacheService.findAllBy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package fr.shikkanime.converters.anime

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.animes.DetailedAnimeDto
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.entities.Anime
import fr.shikkanime.entities.Simulcast
import fr.shikkanime.services.AnimeService
import java.time.ZonedDateTime

class AnimeDtoToAnimeConverter : AbstractConverter<DetailedAnimeDto, Anime>() {
class AnimeDtoToAnimeConverter : AbstractConverter<AnimeDto, Anime>() {
@Inject
private lateinit var animeService: AnimeService

override fun convert(from: DetailedAnimeDto): Anime {
override fun convert(from: AnimeDto): Anime {
val findByUuid = animeService.find(from.uuid)

if (findByUuid != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package fr.shikkanime.converters.anime

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.SeasonDto
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.SimulcastDto
import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.entities.Anime
import fr.shikkanime.entities.enums.LangType
import fr.shikkanime.services.SimulcastService.Companion.sortBySeasonAndYear
import fr.shikkanime.services.caches.EpisodeVariantCacheService
import fr.shikkanime.utils.StringUtils
import fr.shikkanime.utils.withUTCString
import org.hibernate.Hibernate

class AnimeToAnimeDtoConverter : AbstractConverter<Anime, AnimeDto>() {
@Inject
private lateinit var episodeVariantCacheService: EpisodeVariantCacheService

override fun convert(from: Anime): AnimeDto {
val (audioLocales, seasons) = episodeVariantCacheService.findAudioLocalesAndSeasonsByAnimeCache(from)!!

return AnimeDto(
uuid = from.uuid,
countryCode = from.countryCode!!,
Expand All @@ -29,6 +38,10 @@ class AnimeToAnimeDtoConverter : AbstractConverter<Anime, AnimeDto>() {
)?.toList()
else
null,
audioLocales = audioLocales,
langTypes = audioLocales.map { LangType.fromAudioLocale(from.countryCode, it) }.distinct().sorted(),
seasons = seasons.map { (season, lastReleaseDateTime) -> SeasonDto(season, lastReleaseDateTime.withUTCString()) },
status = from.status
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fr.shikkanime.converters.episode_mapping
import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.PlatformDto
import fr.shikkanime.dtos.animes.DetailedAnimeDto
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.mappings.EpisodeMappingDto
import fr.shikkanime.dtos.variants.EpisodeVariantWithoutMappingDto
import fr.shikkanime.entities.EpisodeMapping
Expand All @@ -20,7 +20,7 @@ class EpisodeMappingToEpisodeMappingDtoConverter : AbstractConverter<EpisodeMapp

return EpisodeMappingDto(
uuid = from.uuid!!,
anime = convert(from.anime, DetailedAnimeDto::class.java),
anime = convert(from.anime, AnimeDto::class.java),
releaseDateTime = from.releaseDateTime.withUTCString(),
lastReleaseDateTime = from.lastReleaseDateTime.withUTCString(),
lastUpdateDateTime = from.lastUpdateDateTime.withUTCString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package fr.shikkanime.dtos.animes
package fr.shikkanime.dtos

import fr.shikkanime.dtos.SeasonDto
import fr.shikkanime.dtos.SimulcastDto
import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.dtos.mappings.EpisodeMappingWithoutAnimeDto
import fr.shikkanime.entities.enums.CountryCode
import fr.shikkanime.entities.enums.LangType
import java.util.*

data class DetailedAnimeDto(
data class AnimeDto(
val uuid: UUID?,
val countryCode: CountryCode,
var name: String,
Expand All @@ -25,18 +23,4 @@ data class DetailedAnimeDto(
var seasons: List<SeasonDto> = emptyList(),
var episodes: List<EpisodeMappingWithoutAnimeDto>? = null,
var status: Status? = null,
) {
constructor(animeDto: AnimeDto) : this(
animeDto.uuid,
animeDto.countryCode,
animeDto.name,
animeDto.shortName,
animeDto.slug,
animeDto.releaseDateTime,
animeDto.lastReleaseDateTime,
animeDto.image,
animeDto.banner,
animeDto.description,
animeDto.simulcasts,
)
}
)
4 changes: 1 addition & 3 deletions src/main/kotlin/fr/shikkanime/dtos/MissedAnimeDto.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package fr.shikkanime.dtos

import fr.shikkanime.dtos.animes.DetailedAnimeDto

data class MissedAnimeDto(
val anime: DetailedAnimeDto,
val anime: AnimeDto,
val episodeMissed: Long,
)
1 change: 0 additions & 1 deletion src/main/kotlin/fr/shikkanime/dtos/WeeklyAnimeDto.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fr.shikkanime.dtos

import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.entities.enums.EpisodeType
import fr.shikkanime.entities.enums.LangType
import java.util.*
Expand Down
19 changes: 0 additions & 19 deletions src/main/kotlin/fr/shikkanime/dtos/animes/AnimeDto.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.shikkanime.dtos.mappings

import fr.shikkanime.dtos.PlatformDto
import fr.shikkanime.dtos.animes.DetailedAnimeDto
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.dtos.variants.EpisodeVariantWithoutMappingDto
import fr.shikkanime.entities.enums.EpisodeType
Expand All @@ -10,7 +10,7 @@ import java.util.*

data class EpisodeMappingDto(
val uuid: UUID,
val anime: DetailedAnimeDto,
val anime: AnimeDto,
val releaseDateTime: String,
val lastReleaseDateTime: String,
val lastUpdateDateTime: String,
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/fr/shikkanime/modules/Routing.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.shikkanime.modules

import fr.shikkanime.dtos.*
import fr.shikkanime.dtos.animes.DetailedAnimeDto
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.dtos.mappings.EpisodeMappingDto
import fr.shikkanime.entities.enums.ConfigPropertyKey
Expand Down Expand Up @@ -252,7 +252,7 @@ private suspend fun handleBodyParam(kParameter: KParameter, call: ApplicationCal
Array<UUID>::class.java -> call.receive<Array<UUID>>()
Parameters::class.java -> call.receiveParameters()
ConfigDto::class.java -> call.receive<ConfigDto>()
DetailedAnimeDto::class.java -> call.receive<DetailedAnimeDto>()
AnimeDto::class.java -> call.receive<AnimeDto>()
EpisodeMappingDto::class.java -> call.receive<EpisodeMappingDto>()
GenericDto::class.java -> call.receive<GenericDto>()
MultiPartData::class.java -> call.receiveMultipart()
Expand Down
39 changes: 19 additions & 20 deletions src/main/kotlin/fr/shikkanime/services/AnimeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.PlatformDto
import fr.shikkanime.dtos.WeeklyAnimeDto
import fr.shikkanime.dtos.WeeklyAnimesDto
import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.dtos.animes.DetailedAnimeDto
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.entities.*
import fr.shikkanime.entities.enums.CountryCode
Expand Down Expand Up @@ -176,56 +175,56 @@ class AnimeService : AbstractService<Anime, AnimeRepository>() {
return savedEntity
}

fun update(uuid: UUID, detailedAnimeDto: DetailedAnimeDto): Anime? {
fun update(uuid: UUID, animeDto: AnimeDto): Anime? {
val anime = findLoaded(uuid) ?: return null

if (detailedAnimeDto.name.isNotBlank() && detailedAnimeDto.name != anime.name) {
anime.name = detailedAnimeDto.name
if (animeDto.name.isNotBlank() && animeDto.name != anime.name) {
anime.name = animeDto.name
}

if (!detailedAnimeDto.slug.isNullOrBlank() && detailedAnimeDto.slug != anime.slug) {
val findBySlug = findBySlug(anime.countryCode!!, detailedAnimeDto.slug!!)
if (!animeDto.slug.isNullOrBlank() && animeDto.slug != anime.slug) {
val findBySlug = findBySlug(anime.countryCode!!, animeDto.slug!!)

if (findBySlug != null && findBySlug.uuid != anime.uuid) {
merge(anime, findBySlug)
}

anime.slug = detailedAnimeDto.slug
anime.slug = animeDto.slug
}

if (detailedAnimeDto.releaseDateTime.isNotBlank() && detailedAnimeDto.releaseDateTime != anime.releaseDateTime.toString()) {
anime.releaseDateTime = ZonedDateTime.parse(detailedAnimeDto.releaseDateTime)
if (animeDto.releaseDateTime.isNotBlank() && animeDto.releaseDateTime != anime.releaseDateTime.toString()) {
anime.releaseDateTime = ZonedDateTime.parse(animeDto.releaseDateTime)
}

if (!detailedAnimeDto.image.isNullOrBlank() && detailedAnimeDto.image != anime.image) {
anime.image = detailedAnimeDto.image
if (!animeDto.image.isNullOrBlank() && animeDto.image != anime.image) {
anime.image = animeDto.image
ImageService.remove(anime.uuid!!, ImageService.Type.IMAGE)
addImage(anime.uuid, anime.image!!)
}

if (!detailedAnimeDto.banner.isNullOrBlank() && detailedAnimeDto.banner != anime.banner) {
anime.banner = detailedAnimeDto.banner
if (!animeDto.banner.isNullOrBlank() && animeDto.banner != anime.banner) {
anime.banner = animeDto.banner
ImageService.remove(anime.uuid!!, ImageService.Type.BANNER)
addBanner(anime.uuid, anime.banner)
}

if (!detailedAnimeDto.description.isNullOrBlank() && detailedAnimeDto.description != anime.description) {
anime.description = detailedAnimeDto.description
if (!animeDto.description.isNullOrBlank() && animeDto.description != anime.description) {
anime.description = animeDto.description
}

updateAnimeSimulcast(detailedAnimeDto, anime)
updateAnimeSimulcast(animeDto, anime)

anime.status = StringUtils.getStatus(anime)
val update = super.update(anime)
MapCache.invalidate(Anime::class.java)
return update
}

private fun updateAnimeSimulcast(detailedAnimeDto: DetailedAnimeDto, anime: Anime) {
if (detailedAnimeDto.simulcasts != null) {
private fun updateAnimeSimulcast(animeDto: AnimeDto, anime: Anime) {
if (animeDto.simulcasts != null) {
anime.simulcasts.clear()

detailedAnimeDto.simulcasts.forEach { simulcastDto ->
animeDto.simulcasts.forEach { simulcastDto ->
val simulcast = simulcastService.find(simulcastDto.uuid!!) ?: return@forEach

if (anime.simulcasts.none { it.uuid == simulcast.uuid }) {
Expand Down
Loading

0 comments on commit 6a169bc

Please sign in to comment.