Skip to content

Commit

Permalink
Merge pull request #180 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Ziedelth authored Feb 13, 2024
2 parents 0ab5f38 + 945c042 commit 6395cd6
Show file tree
Hide file tree
Showing 25 changed files with 215 additions and 83 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import java.net.URI

val ktorVersion = "2.3.8"
val kotlinVersion = "1.9.22"
val hibernateSearchVersion = "7.1.0.Alpha2"
val hibernateSearchVersion = "7.1.0.CR1"
val junitVersion = "5.10.2"
val tikaVersion = "3.0.0-BETA"
val ktorSwaggerUiVersion = "2.7.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fr.shikkanime.controllers.admin

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.entities.enums.Link
import fr.shikkanime.services.AnimeService
import fr.shikkanime.utils.routes.AdminSessionAuthenticated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fr.shikkanime.controllers.api

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.SimulcastDto
import fr.shikkanime.dtos.simulcasts.SimulcastDto
import fr.shikkanime.services.SimulcastService
import fr.shikkanime.utils.routes.*
import fr.shikkanime.utils.routes.method.Get
Expand Down
17 changes: 13 additions & 4 deletions src/main/kotlin/fr/shikkanime/controllers/site/SiteController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,17 @@ class SiteController {
@Path("sitemap.xml")
@Get
private fun sitemap(): Response {
val simulcasts = simulcastCacheService.findAll()!!
val animes = animeCacheService.findAll()!!
val simulcasts = simulcastCacheService.findAllUpdated()!!

val animes = simulcasts.flatMap {
animeCacheService.findAllByUpdated(
CountryCode.FR,
it.uuid,
listOf(SortParameter("name", SortParameter.Order.ASC)),
1,
102
)!!.data
}

val episode = episodeCacheService.findAllBy(
CountryCode.FR,
Expand All @@ -87,8 +96,8 @@ class SiteController {
null,
mutableMapOf(
"episode" to episode,
"simulcasts" to simulcasts,
"animes" to animes
"simulcastsUpdated" to simulcasts,
"animesUpdated" to animes
),
contentType = ContentType.Text.Xml
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fr.shikkanime.converters.anime

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.entities.Anime
import fr.shikkanime.entities.Simulcast
import fr.shikkanime.entities.enums.CountryCode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package fr.shikkanime.converters.anime

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.SimulcastDto
import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.dtos.simulcasts.SimulcastDto
import fr.shikkanime.entities.Anime
import fr.shikkanime.entities.SortParameter
import fr.shikkanime.services.caches.EpisodeCacheService
import fr.shikkanime.utils.StringUtils
import fr.shikkanime.utils.withUTC
import org.apache.tika.language.detect.LanguageDetector
Expand All @@ -17,24 +14,13 @@ import java.time.format.DateTimeFormatter
class AnimeToAnimeDtoConverter : AbstractConverter<Anime, AnimeDto>() {
private val languageDetector: LanguageDetector = LanguageDetector.getDefaultLanguageDetector().loadModels()

@Inject
private lateinit var episodeCacheService: EpisodeCacheService

override fun convert(from: Anime): AnimeDto {
val lastReleaseDate = episodeCacheService.findAllBy(
from.countryCode!!,
from.uuid,
listOf(SortParameter("releaseDateTime", SortParameter.Order.DESC)),
1,
1
)?.data?.firstOrNull()?.releaseDateTime

val status = if (
from.image.isNullOrBlank() ||
from.banner.isNullOrBlank() ||
from.description.isNullOrBlank() ||
from.description?.startsWith("(") == true ||
languageDetector.detect(from.description).language.lowercase() != from.countryCode.name.lowercase()
languageDetector.detect(from.description).language.lowercase() != from.countryCode!!.name.lowercase()
) Status.INVALID else Status.VALID

return AnimeDto(
Expand All @@ -43,7 +29,7 @@ class AnimeToAnimeDtoConverter : AbstractConverter<Anime, AnimeDto>() {
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME),
image = from.image,
banner = from.banner,
countryCode = from.countryCode,
countryCode = from.countryCode!!,
name = from.name!!,
shortName = StringUtils.getShortName(from.name!!),
description = from.description,
Expand All @@ -53,7 +39,6 @@ class AnimeToAnimeDtoConverter : AbstractConverter<Anime, AnimeDto>() {
) else null,
status = status,
slug = from.slug,
lastReleaseDateTime = lastReleaseDate
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package fr.shikkanime.converters.anime

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.animes.UpdatedAnimeDto
import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.dtos.simulcasts.SimulcastDto
import fr.shikkanime.entities.Anime
import fr.shikkanime.entities.SortParameter
import fr.shikkanime.services.caches.EpisodeCacheService
import fr.shikkanime.utils.StringUtils
import fr.shikkanime.utils.withUTC
import org.apache.tika.language.detect.LanguageDetector
import org.hibernate.Hibernate
import java.time.format.DateTimeFormatter

class AnimeToUpdatedAnimeDtoConverter : AbstractConverter<Anime, UpdatedAnimeDto>() {
private val languageDetector: LanguageDetector = LanguageDetector.getDefaultLanguageDetector().loadModels()

@Inject
private lateinit var episodeCacheService: EpisodeCacheService

override fun convert(from: Anime): UpdatedAnimeDto {
val lastReleaseDate = episodeCacheService.findAllBy(
from.countryCode!!,
from.uuid,
listOf(SortParameter("releaseDateTime", SortParameter.Order.DESC)),
1,
1
)?.data?.firstOrNull()?.releaseDateTime

val status = if (
from.image.isNullOrBlank() ||
from.banner.isNullOrBlank() ||
from.description.isNullOrBlank() ||
from.description?.startsWith("(") == true ||
languageDetector.detect(from.description).language.lowercase() != from.countryCode.name.lowercase()
) Status.INVALID else Status.VALID

return UpdatedAnimeDto(
uuid = from.uuid,
releaseDateTime = from.releaseDateTime.withUTC()
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME),
image = from.image,
banner = from.banner,
countryCode = from.countryCode,
name = from.name!!,
shortName = StringUtils.getShortName(from.name!!),
description = from.description,
simulcasts = if (Hibernate.isInitialized(from.simulcasts)) convert(
from.simulcasts,
SimulcastDto::class.java
) else null,
status = status,
slug = from.slug,
lastReleaseDateTime = lastReleaseDate
)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package fr.shikkanime.converters.episode

import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.EpisodeDto
import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.entities.Episode
import fr.shikkanime.utils.withUTC
import java.time.format.DateTimeFormatter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fr.shikkanime.converters.simulcast

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.SimulcastDto
import fr.shikkanime.dtos.simulcasts.SimulcastDto
import fr.shikkanime.entities.Simulcast
import fr.shikkanime.services.SimulcastService

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
package fr.shikkanime.converters.simulcast

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.SimulcastDto
import fr.shikkanime.dtos.simulcasts.SimulcastDto
import fr.shikkanime.entities.Simulcast
import fr.shikkanime.entities.SortParameter
import fr.shikkanime.entities.enums.CountryCode
import fr.shikkanime.services.caches.AnimeCacheService

class SimulcastToSimulcastDtoConverter : AbstractConverter<Simulcast, SimulcastDto>() {
@Inject
private lateinit var animeCacheService: AnimeCacheService

override fun convert(from: Simulcast): SimulcastDto {
val lastReleaseDateTime = animeCacheService.findAllBy(
CountryCode.FR,
from.uuid,
listOf(SortParameter("releaseDateTime", SortParameter.Order.DESC)),
1,
1
)?.data?.firstOrNull()?.releaseDateTime

return SimulcastDto(
uuid = from.uuid,
season = from.season!!,
Expand All @@ -33,7 +18,6 @@ class SimulcastToSimulcastDtoConverter : AbstractConverter<Simulcast, SimulcastD
"AUTUMN" -> "Automne"
else -> "Inconnu"
} + " ${from.year}",
lastReleaseDateTime = lastReleaseDateTime
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package fr.shikkanime.converters.simulcast

import com.google.inject.Inject
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.simulcasts.UpdatedSimulcastDto
import fr.shikkanime.entities.Simulcast
import fr.shikkanime.entities.SortParameter
import fr.shikkanime.entities.enums.CountryCode
import fr.shikkanime.services.caches.AnimeCacheService

class SimulcastToUpdatedSimulcastDtoConverter : AbstractConverter<Simulcast, UpdatedSimulcastDto>() {
@Inject
private lateinit var animeCacheService: AnimeCacheService

override fun convert(from: Simulcast): UpdatedSimulcastDto {
val lastReleaseDateTime = animeCacheService.findAllBy(
CountryCode.FR,
from.uuid,
listOf(SortParameter("releaseDateTime", SortParameter.Order.DESC)),
1,
1
)?.data?.firstOrNull()?.releaseDateTime

return UpdatedSimulcastDto(
uuid = from.uuid,
season = from.season!!,
year = from.year!!,
slug = "${from.season.lowercase()}-${from.year}",
label = when (from.season) {
"WINTER" -> "Hiver"
"SPRING" -> "Printemps"
"SUMMER" -> "Été"
"AUTUMN" -> "Automne"
else -> "Inconnu"
} + " ${from.year}",
lastReleaseDateTime = lastReleaseDateTime
)
}
}
1 change: 1 addition & 0 deletions src/main/kotlin/fr/shikkanime/dtos/EpisodeDto.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.shikkanime.dtos

import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.entities.enums.EpisodeType
import fr.shikkanime.entities.enums.LangType
import fr.shikkanime.entities.enums.Platform
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.shikkanime.dtos
package fr.shikkanime.dtos.animes

import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.dtos.simulcasts.SimulcastDto
import fr.shikkanime.entities.enums.CountryCode
import java.io.Serializable
import java.util.*
Expand All @@ -17,5 +18,4 @@ data class AnimeDto(
val simulcasts: List<SimulcastDto>?,
val status: Status? = null,
val slug: String? = null,
val lastReleaseDateTime: String? = null
) : Serializable
22 changes: 22 additions & 0 deletions src/main/kotlin/fr/shikkanime/dtos/animes/UpdatedAnimeDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.shikkanime.dtos.animes

import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.dtos.simulcasts.SimulcastDto
import fr.shikkanime.entities.enums.CountryCode
import java.io.Serializable
import java.util.*

data class UpdatedAnimeDto(
val uuid: UUID?,
val countryCode: CountryCode,
var name: String,
var shortName: String,
var releaseDateTime: String,
val image: String? = null,
val banner: String? = null,
val description: String?,
val simulcasts: List<SimulcastDto>?,
val status: Status? = null,
val slug: String? = null,
val lastReleaseDateTime: String? = null
) : Serializable
12 changes: 12 additions & 0 deletions src/main/kotlin/fr/shikkanime/dtos/simulcasts/SimulcastDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fr.shikkanime.dtos.simulcasts

import java.io.Serializable
import java.util.*

data class SimulcastDto(
val uuid: UUID?,
val season: String,
val year: Int,
val slug: String,
val label: String,
) : Serializable
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package fr.shikkanime.dtos
package fr.shikkanime.dtos.simulcasts

import java.io.Serializable
import java.util.*

data class SimulcastDto(
data class UpdatedSimulcastDto(
val uuid: UUID?,
val season: String,
val year: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import com.google.inject.Inject
import fr.shikkanime.caches.CountryCodeNamePaginationKeyCache
import fr.shikkanime.caches.CountryCodeUUIDSortPaginationKeyCache
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.PageableDto
import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.dtos.animes.UpdatedAnimeDto
import fr.shikkanime.entities.Anime
import fr.shikkanime.entities.SortParameter
import fr.shikkanime.entities.enums.CountryCode
Expand All @@ -25,6 +26,14 @@ class AnimeCacheService : AbstractCacheService() {
)
}

private val findAllByUpdatedCache =
MapCache<CountryCodeUUIDSortPaginationKeyCache, PageableDto<UpdatedAnimeDto>>(classes = listOf(Anime::class.java)) {
PageableDto.fromPageable(
animeService.findAllBy(it.countryCode, it.uuid, it.sort, it.page, it.limit),
UpdatedAnimeDto::class.java
)
}

private val findAllByNameCache = MapCache<CountryCodeNamePaginationKeyCache, PageableDto<AnimeDto>>(classes = listOf(Anime::class.java)) {
PageableDto.fromPageable(
animeService.findAllByName(it.name, it.countryCode, it.page, it.limit),
Expand Down Expand Up @@ -52,6 +61,14 @@ class AnimeCacheService : AbstractCacheService() {
limit: Int
) = findAllByCache[CountryCodeUUIDSortPaginationKeyCache(countryCode, uuid, sort, page, limit)]

fun findAllByUpdated(
countryCode: CountryCode?,
uuid: UUID?,
sort: List<SortParameter>,
page: Int,
limit: Int
) = findAllByUpdatedCache[CountryCodeUUIDSortPaginationKeyCache(countryCode, uuid, sort, page, limit)]

fun findAllByName(name: String, countryCode: CountryCode?, page: Int, limit: Int) =
findAllByNameCache[CountryCodeNamePaginationKeyCache(countryCode, name, page, limit)]

Expand Down
Loading

0 comments on commit 6395cd6

Please sign in to comment.