Refactor and include new elements in details of anime

v5 v5.5.0
Jéluchu 2 months ago
parent c54a28967b
commit 93cf3816d6

@ -0,0 +1,27 @@
package com.jeluchu.core.models.jikan.anime
import com.jeluchu.core.models.jikan.search.Pagination
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class Episodes(
@SerialName("mal_id")
val malId: Int? = 0,
@SerialName("title")
val title: String? = "",
@SerialName("episode")
val episode: String? = "",
@SerialName("url")
val url: String? = "",
/**
* Data list of all anime found.
*/
@SerialName("data")
val data: List<AnimeData>? = emptyList()
)

@ -39,6 +39,7 @@ object RssSources {
object Endpoints { object Endpoints {
const val POSTS = "posts" const val POSTS = "posts"
const val ANIME = "anime" const val ANIME = "anime"
const val EPISODES = "episodes"
const val SCHEDULES = "schedules" const val SCHEDULES = "schedules"
const val TOP_ANIME = "top/anime" const val TOP_ANIME = "top/anime"
const val TOP_MANGA = "top/manga" const val TOP_MANGA = "top/manga"
@ -63,6 +64,7 @@ object Routes {
const val ANITAKUME = "/anitakume" const val ANITAKUME = "/anitakume"
const val CHARACTER = "/characters" const val CHARACTER = "/characters"
const val LAST_EPISODES = "/lastEpisodes" const val LAST_EPISODES = "/lastEpisodes"
const val EPISODES = "/episodes"
const val ID = "/{id}" const val ID = "/{id}"
const val TYPE = "/{type}" const val TYPE = "/{type}"
const val SEASON = "/{year}/{season}" const val SEASON = "/{year}/{season}"
@ -76,6 +78,7 @@ object TimerKey {
const val LAST_UPDATED = "lastUpdated" const val LAST_UPDATED = "lastUpdated"
const val ANIME_TYPE = "anime_" const val ANIME_TYPE = "anime_"
const val THEMES = "themes_" const val THEMES = "themes_"
const val EPISODES = "episodes_"
const val LAST_EPISODES = "last_episodes" const val LAST_EPISODES = "last_episodes"
} }
@ -87,11 +90,11 @@ object Collections {
const val ANITAKUME = "anitakume" const val ANITAKUME = "anitakume"
const val ANIME_THEMES = "anime_themes" const val ANIME_THEMES = "anime_themes"
const val ARTISTS_INDEX = "artists_index" const val ARTISTS_INDEX = "artists_index"
const val ANIME_DETAILS = "anime_details"
const val LAST_EPISODES = "last_episodes" const val LAST_EPISODES = "last_episodes"
const val ANIME_RANKING = "anime_ranking" const val ANIME_RANKING = "anime_ranking"
const val MANGA_RANKING = "manga_ranking" const val MANGA_RANKING = "manga_ranking"
const val PEOPLE_RANKING = "people_ranking" const val PEOPLE_RANKING = "people_ranking"
const val ANIME_DIRECTORY = "anime_directory"
const val CHARACTER_RANKING = "character_ranking" const val CHARACTER_RANKING = "character_ranking"
const val ANIME_PICTURES_QUERY = "anime_pictures_query" const val ANIME_PICTURES_QUERY = "anime_pictures_query"
const val ANIME_PICTURES_RECENT = "anime_pictures_recent" const val ANIME_PICTURES_RECENT = "anime_pictures_recent"

@ -1,96 +1,104 @@
package com.jeluchu.features.anime.mappers package com.jeluchu.features.anime.mappers
import com.jeluchu.features.themes.models.anime.AnimeThemeEntry
import com.jeluchu.core.extensions.* import com.jeluchu.core.extensions.*
import com.jeluchu.features.anime.models.anime.* import com.jeluchu.features.anime.models.anime.*
import com.jeluchu.features.anime.models.directory.AnimeTypeEntity import com.jeluchu.features.anime.models.directory.AnimeTypeEntity
import com.jeluchu.features.anime.models.lastepisodes.LastEpisodeData import com.jeluchu.features.anime.models.lastepisodes.LastEpisodeEntity
import com.jeluchu.features.rankings.models.AnimeTopEntity import com.jeluchu.features.rankings.models.AnimeTopEntity
import com.jeluchu.features.rankings.models.CharacterTopEntity import com.jeluchu.features.rankings.models.CharacterTopEntity
import com.jeluchu.features.rankings.models.MangaTopEntity import com.jeluchu.features.rankings.models.MangaTopEntity
import com.jeluchu.features.rankings.models.PeopleTopEntity import com.jeluchu.features.rankings.models.PeopleTopEntity
import com.jeluchu.features.schedule.models.DayEntity import com.jeluchu.features.schedule.models.DayEntity
import com.jeluchu.features.themes.models.anime.Anime import com.jeluchu.features.themes.models.anime.*
import com.jeluchu.features.themes.models.anime.AnimeVideoTheme
import com.jeluchu.features.themes.models.anime.AnimesEntity
import com.jeluchu.features.themes.models.anime.Video
import org.bson.Document import org.bson.Document
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
fun documentToMoreInfoEntity(doc: Document): MoreInfoEntity { fun documentToMoreInfoEntity(doc: Document): MoreInfoEntity {
return MoreInfoEntity( return MoreInfoEntity(
id = doc.getObjectId("_id").toString(), id = doc.getObjectId("_id").toString(),
malId = doc.getIntSafe("malId"), malId = doc.getIntSafe("malId"),
rank = doc.getIntSafe("rank"),
title = doc.getStringSafe("title"), title = doc.getStringSafe("title"),
episodes = doc.getIntSafe("episodes"),
episodeList = doc.getListSafe<Document>("episodeList").map { documentToEpisodeInfo(it) },
type = doc.getStringSafe("type"),
status = doc.getStringSafe("status"),
season = doc.getDocumentSafe("season")?.let { documentToSeasonalEntity(it) },
poster = doc.getStringSafe("poster"), poster = doc.getStringSafe("poster"),
cover = doc.getStringSafe("cover"), cover = doc.getStringSafe("cover"),
genres = doc.getListSafe<String>("genres"), duration = doc.getDocumentSafe("duration")?.let { documentToEpisodeDurationEntity(it) },
synopsis = doc.getStringSafe("synopsis"),
episodes = doc.getListSafe<Document>("episodes").map { documentToMergedEpisode(it) },
episodesCount = doc.getIntSafe("episodesCount", 0),
score = doc.getStringSafe("score"), score = doc.getStringSafe("score"),
staff = doc.getListSafe<Document>("staff").map { documentToStaff(it) }, titles = doc.getDocumentSafe("titles")?.let { documentToOtherTitlesEntity(it) },
characters = doc.getListSafe<Document>("characters").map { documentToCharacter(it) },
status = doc.getStringSafe("status"),
type = doc.getStringSafe("type"),
url = doc.getStringSafe("url"),
promo = doc.getDocumentSafe("promo")?.let { documentToVideoPromo(it) },
duration = doc.getStringSafe("duration"),
rank = doc.getIntSafe("rank", 0),
titles = doc.getListSafe<Document>("titles").map { documentToAlternativeTitles(it) },
airing = doc.getBooleanSafe("airing"),
aired = doc.getDocumentSafe("aired")?.let { documentToAiringTime(it) } ?: AiringTime(),
broadcast = doc.getDocumentSafe("broadcast")?.let { documentToAnimeBroadcast(it) } ?: AnimeBroadcast(),
season = doc.getStringSafe("season"),
year = doc.getIntSafe("year", 0),
external = doc.getListSafe<Document>("external").map { documentToExternalLinks(it) },
streaming = doc.getListSafe<Document>("streaming").map { documentToExternalLinks(it) },
studios = doc.getListSafe<Document>("studios").map { documentToCompanies(it) }, studios = doc.getListSafe<Document>("studios").map { documentToCompanies(it) },
licensors = doc.getListSafe<Document>("licensors").map { documentToCompanies(it) },
producers = doc.getListSafe<Document>("producers").map { documentToCompanies(it) }, producers = doc.getListSafe<Document>("producers").map { documentToCompanies(it) },
theme = doc.getDocumentSafe("theme")?.let { documentToThemes(it) } ?: Themes(), licensors = doc.getListSafe<Document>("licensors").map { documentToCompanies(it) },
relations = doc.getListSafe<Document>("relations").map { documentToRelated(it) }, relations = doc.getListSafe<Document>("relations").map { documentToRelated(it) },
stats = doc.getDocumentSafe("stats")?.let { documentToStatistics(it) } ?: Statistics(), promo = doc.getDocumentSafe("promo")?.let { documentToVideoPromo(it) },
gallery = doc.getListSafe<Document>("gallery").map { documentToImageMediaEntity(it) }, tags = doc.getDocumentSafe("genres")?.let { documentToMultipleLanguageLists(it) },
episodeSource = doc.getStringSafe("episodeSource") synopsis = doc.getDocumentSafe("synopsis")?.let { documentToMultipleLanguage(it) },
staff = doc.getListSafe<Document>("staff").map { documentToStaff(it) },
characters = doc.getListSafe<Document>("characters").map { documentToCharacter(it) },
streaming = doc.getListSafe<Document>("streaming").map { documentToExternalLinks(it) },
urls = doc.getListSafe<String>("urls").takeIf { it.isNotEmpty() } ?: listOf(doc.getStringSafe("url")).filter { it.isNotEmpty() },
broadcast = doc.getDocumentSafe("broadcast")?.let { documentToAnimeBroadcast(it) },
external = doc.getListSafe<Document>("external").map { documentToExternalLinks(it) },
stats = doc.getDocumentSafe("stats")?.let { documentToStatistics(it) },
nsfw = doc.getBooleanSafe("nsfw", false),
ageRating = doc.getStringSafe("ageRating"),
aired = doc.getDocumentSafe("aired")?.let { documentToAiringTime(it) },
themes = doc.getDocumentSafe("theme")?.let { documentToThemes(it) }
) )
} }
fun documentToActor(doc: Document): Actor { fun documentToEpisodeInfo(doc: Document): EpisodeInfo {
return Actor( return EpisodeInfo(
person = doc.getDocumentSafe("person")?.let { documentToIndividual(it) } ?: Individual(), number = doc.getIntSafe("number"),
language = doc.getStringSafe("language") seasonNumber = doc.getIntSafe("season_number"),
relativeNumber = doc.getIntSafe("relative_number"),
airdate = doc.getStringSafe("airdate"),
duration = doc.getIntSafe("duration"),
thumbnail = doc.getStringSafe("thumbnail"),
synopsis = doc.getDocumentSafe("synopsis")?.let { documentToMultipleLanguage(it) },
titles = doc.getDocumentSafe("titles")?.let { documentToMultipleLanguageTitles(it) },
score = doc.getDoubleSafe("score"),
filler = doc.getBooleanSafe("filler", false),
recap = doc.getBooleanSafe("recap", false)
) )
} }
fun documentToAiringTime(doc: Document): AiringTime { fun documentToMultipleLanguage(doc: Document): MultipleLanguage {
return AiringTime( return MultipleLanguage(
from = doc.getStringSafe("from"), es = doc.getStringSafe("es"),
to = doc.getStringSafe("to") en = doc.getStringSafe("en")
) )
} }
fun documentToAlternativeTitles(doc: Document): AlternativeTitles { fun documentToMultipleLanguageTitles(doc: Document): MultipleLanguageTitles {
return AlternativeTitles( return MultipleLanguageTitles(
title = doc.getStringSafe("title"), es = doc.getStringSafe("es"),
type = doc.getStringSafe("type") en = doc.getStringSafe("en"),
jp = doc.getStringSafe("jp"),
romaji_jp = doc.getStringSafe("romaji_jp")
) )
} }
fun documentToAnimeBroadcast(doc: Document): AnimeBroadcast { fun documentToSeasonalEntity(doc: Document): SeasonalEntity {
return AnimeBroadcast( return SeasonalEntity(
day = doc.getStringSafe("day"), station = doc.getStringSafe("station"),
time = doc.getStringSafe("time"), year = doc.getIntSafe("year")
timezone = doc.getStringSafe("timezone")
) )
} }
fun documentToCharacter(doc: Document): Character { fun documentToEpisodeDurationEntity(doc: Document): EpisodeDurationEntity {
return Character( return EpisodeDurationEntity(
character = doc.getDocumentSafe("character")?.let { documentToIndividual(it) } ?: Individual(), unit = doc.getStringSafe("unit"),
role = doc.getStringSafe("role"), value = doc.getIntSafe("value")
voiceActor = doc.getListSafe<Document>("voiceActor").map { documentToActor(it) } )
}
fun documentToOtherTitlesEntity(doc: Document): OtherTitlesEntity {
return OtherTitlesEntity(
synonyms = doc.getListSafe<String>("synonyms"),
abbreviatedTitles = doc.getListSafe<String>("abbreviated_titles")
) )
} }
@ -103,20 +111,19 @@ fun documentToCompanies(doc: Document): Companies {
) )
} }
fun documentToExternalLinks(doc: Document): ExternalLinks { fun documentToRelated(doc: Document): Related {
return ExternalLinks( return Related(
url = doc.getStringSafe("url"), entry = doc.getListSafe<Document>("entry").map { documentToCompanies(it) },
name = doc.getStringSafe("name") relation = doc.getStringSafe("relation")
) )
} }
fun documentToImageMediaEntity(doc: Document): ImageMediaEntity { fun documentToVideoPromo(doc: Document): VideoPromo {
return ImageMediaEntity( return VideoPromo(
media = doc.getStringSafe("media"), embedUrl = doc.getStringSafe("embedUrl"),
thumbnail = doc.getStringSafe("thumbnail"), url = doc.getStringSafe("url"),
width = doc.getIntSafe("width", 0), youtubeId = doc.getStringSafe("youtubeId"),
height = doc.getIntSafe("height", 0), images = doc.getDocumentSafe("images")?.let { documentToImages(it) } ?: Images()
url = doc.getStringSafe("url")
) )
} }
@ -130,51 +137,51 @@ fun documentToImages(doc: Document): Images {
) )
} }
fun documentToIndividual(doc: Document): Individual { fun documentToMultipleLanguageLists(doc: Document): MultipleLanguageLists {
return Individual( return MultipleLanguageLists(
malId = doc.getIntSafe("malId", 0), es = doc.getListSafe<String>("es"),
url = doc.getStringSafe("url"), en = doc.getListSafe<String>("en")
name = doc.getStringSafe("name"),
images = doc.getStringSafe("images")
) )
} }
fun documentToMergedEpisode(doc: Document): MergedEpisode { fun documentToStaff(doc: Document): Staff {
return MergedEpisode( return Staff(
malId = doc.getIntSafe("malId"), person = doc.getDocumentSafe("person")?.let { documentToIndividual(it) } ?: Individual(),
title = doc.getStringSafe("title"), positions = doc.getListSafe<String>("positions")
titleJapanese = doc.getStringSafe("titleJapanese"),
titleRomanji = doc.getStringSafe("titleRomanji"),
aired = doc.getStringSafe("aired", ZonedDateTime.now().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)),
score = doc.getFloatSafe("score"),
filler = doc.getBooleanSafe("filler"),
recap = doc.getBooleanSafe("recap")
) )
} }
fun documentToRelated(doc: Document): Related { fun documentToCharacter(doc: Document): Character {
return Related( return Character(
entry = doc.getListSafe<Document>("entry").map { documentToCompanies(it) }, malId = doc.getIntSafe("mal_id", 0),
relation = doc.getStringSafe("relation") url = doc.getStringSafe("url"),
name = doc.getStringSafe("name"),
images = doc.getStringSafe("images"),
role = doc.getStringSafe("role"),
voiceActor = doc.getListSafe<Document>("voice_actor").map { documentToActor(it) }
) )
} }
fun documentToScore(doc: Document): Score { fun documentToActor(doc: Document): Actor {
return Score( return Actor(
percentage = when (val value = doc["percentage"]) { person = doc.getDocumentSafe("person")?.let { documentToIndividual(it) } ?: Individual(),
is Double -> value language = doc.getStringSafe("language")
is Int -> value.toDouble()
else -> 0.0
},
score = doc.getIntSafe("score", 0),
votes = doc.getIntSafe("votes", 0)
) )
} }
fun documentToStaff(doc: Document): Staff { fun documentToIndividual(doc: Document): Individual {
return Staff( return Individual(
person = doc.get("person", Document::class.java)?.let { documentToIndividual(it) } ?: Individual(), malId = doc.getIntSafe("malId", 0),
positions = doc.getListSafe<String>("positions") url = doc.getStringSafe("url"),
name = doc.getStringSafe("name"),
images = doc.getStringSafe("images")
)
}
fun documentToExternalLinks(doc: Document): ExternalLinks {
return ExternalLinks(
url = doc.getStringSafe("url"),
name = doc.getStringSafe("name")
) )
} }
@ -190,19 +197,37 @@ fun documentToStatistics(doc: Document): Statistics {
) )
} }
fun documentToAiringTime(doc: Document): AiringTime {
return AiringTime(
from = doc.getStringSafe("from"),
to = doc.getStringSafe("to")
)
}
fun documentToThemes(doc: Document): Themes { fun documentToThemes(doc: Document): Themes {
return Themes( return Themes(
endings = doc.getListSafe<String>("endings"), openings = doc.getListSafe<String>("openings"),
openings = doc.getListSafe<String>("openings") endings = doc.getListSafe<String>("endings")
) )
} }
fun documentToVideoPromo(doc: Document): VideoPromo { fun documentToAnimeBroadcast(doc: Document): AnimeBroadcast {
return VideoPromo( return AnimeBroadcast(
embedUrl = doc.getStringSafe("embedUrl"), day = doc.getStringSafe("day"),
url = doc.getStringSafe("url"), time = doc.getStringSafe("time"),
youtubeId = doc.getStringSafe("youtubeId"), timezone = doc.getStringSafe("timezone")
images = doc.get("images", Document::class.java)?.let { documentToImages(it) } ?: Images() )
}
fun documentToScore(doc: Document): Score {
return Score(
percentage = when (val value = doc["percentage"]) {
is Double -> value
is Int -> value.toDouble()
else -> 0.0
},
score = doc.getIntSafe("score", 0),
votes = doc.getIntSafe("votes", 0)
) )
} }
@ -228,7 +253,7 @@ fun documentToAnimeTopEntity(doc: Document) = AnimeTopEntity(
subtype = doc.getStringSafe("subtype"), subtype = doc.getStringSafe("subtype"),
) )
fun documentToAnimeLastEpisodeEntity(doc: Document) = LastEpisodeData( fun documentToAnimeLastEpisodeEntity(doc: Document) = LastEpisodeEntity(
malId = doc.getIntSafe("malId"), malId = doc.getIntSafe("malId"),
title = doc.getStringSafe("title"), title = doc.getStringSafe("title"),
image = doc.getStringSafe("image"), image = doc.getStringSafe("image"),
@ -290,15 +315,6 @@ fun documentToAnimeDirectoryEntity(doc: Document) = AnimeTypeEntity(
season = doc.getStringSafe("season") season = doc.getStringSafe("season")
) )
fun documentToAnimesEntity(doc: Document) = AnimesEntity(
year = doc.getIntSafe("year"),
slug = doc.getStringSafe("slug"),
name = doc.getStringSafe("name"),
image = doc.getStringSafe("image"),
season = doc.getStringSafe("season")
)
fun documentToAnimesThemeEntity(doc: Document) = Anime( fun documentToAnimesThemeEntity(doc: Document) = Anime(
year = doc.getIntSafe("year"), year = doc.getIntSafe("year"),
slug = doc.getStringSafe("slug"), slug = doc.getStringSafe("slug"),

@ -1,16 +0,0 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class AlternativeTitles(
/**
* Title for anime.
*/
val title: String = "",
/**
* Title type for anime.
*/
val type: String = ""
)

@ -4,7 +4,10 @@ import kotlinx.serialization.Serializable
@Serializable @Serializable
data class Character( data class Character(
var character: Individual = Individual(), val malId: Int = 0,
val url: String = "",
val name: String = "",
val images: String = "",
var role: String = "", var role: String = "",
var voiceActor: List<Actor> = emptyList() var voiceActor: List<Actor> = emptyList()
) )

@ -0,0 +1,9 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class EpisodeDurationEntity(
var unit: String? = null,
var value: Int? = null
)

@ -0,0 +1,18 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class EpisodeInfo(
val number: Int? = null,
val seasonNumber: Int? = null,
val relativeNumber: Int? = null,
val airdate: String? = null,
val duration: Int? = null,
val thumbnail: String? = null,
val synopsis: MultipleLanguage? = null,
val titles: MultipleLanguageTitles? = null,
var score: Double? = null,
var filler: Boolean? = false,
var recap: Boolean? = false
)

@ -1,12 +0,0 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class ImageMediaEntity(
val media: String,
val thumbnail: String,
val width: Int,
val height: Int,
val url: String
)

@ -1,16 +0,0 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class MergedEpisode(
var malId: Int,
var title: String,
var titleJapanese: String,
var titleRomanji: String,
var aired: String,
var score: Float,
var filler: Boolean,
var recap: Boolean,
)

@ -1,52 +1,39 @@
package com.jeluchu.features.anime.models.anime package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.bson.Document
@Serializable @Serializable
data class MoreInfoEntity( data class MoreInfoEntity(
var malId: Int = 0, val id: String? = null,
val id: String = "", var malId: Int? = null,
val rank: Int? = null,
var title: String = "", var title: String = "",
var poster: String = "", var episodes: Int? = null,
var cover: String = "", var episodeList: List<EpisodeInfo>? = null,
var genres: List<String> = emptyList(),
var synopsis: String = "",
var episodes: List<MergedEpisode> = emptyList(),
var episodesCount: Int = 0,
var score: String = "",
var staff: List<Staff> = emptyList(),
var characters: List<Character> = emptyList(),
var status: String = "",
var type: String = "", var type: String = "",
val url: String = "", var status: String = "",
val promo: VideoPromo? = VideoPromo(), var season: SeasonalEntity? = null,
val duration: String = "", var poster: String = "",
val rank: Int = 0, var cover: String? = null,
val titles: List<AlternativeTitles> = emptyList(), var duration: EpisodeDurationEntity? = null,
val airing: Boolean = false, var score: String? = null,
val aired: AiringTime = AiringTime(), var titles: OtherTitlesEntity? = null,
val broadcast: AnimeBroadcast = AnimeBroadcast(), val studios: List<Companies>? = null,
val season: String = "", val producers: List<Companies>? = null,
val year: Int = 0, val licensors: List<Companies>? = null,
val external: List<ExternalLinks> = emptyList(), val relations: List<Related>? = null,
val streaming: List<ExternalLinks> = emptyList(), val promo: VideoPromo? = null,
val studios: List<Companies> = emptyList(), var tags: MultipleLanguageLists? = null,
val licensors: List<Companies> = emptyList(), var synopsis: MultipleLanguage? = null,
val producers: List<Companies> = emptyList(), var staff: List<Staff>? = null,
val theme: Themes = Themes(), var characters: List<Character>? = null,
val relations: List<Related> = emptyList(), val streaming: List<ExternalLinks>? = null,
val stats: Statistics = Statistics(), val urls: List<String>? = null,
val gallery: List<ImageMediaEntity> = emptyList(), val broadcast: AnimeBroadcast? = null,
val episodeSource: String = "" val external: List<ExternalLinks>? = null,
) { val stats: Statistics? = null,
fun toDocument(): Document = Document.parse(Json.encodeToString(this)) val nsfw: Boolean = false,
val ageRating: String? = null,
companion object { val aired: AiringTime? = null,
private val json = Json { ignoreUnknownKeys = true } val themes: Themes? = null
)
fun fromDocument(document: Document): MoreInfoEntity = json.decodeFromString(document.toJson())
}
}

@ -3,8 +3,7 @@ package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@Serializable @Serializable
data class AnimeSource( data class MultipleLanguage(
val id: String, val es: String? = null,
val source: String val en: String? = null
) )

@ -0,0 +1,9 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class MultipleLanguageLists(
val es: List<String>? = null,
val en: List<String>? = null
)

@ -0,0 +1,11 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class MultipleLanguageTitles(
val es: String? = null,
val en: String? = null,
val jp: String? = null,
val romaji_jp: String? = null,
)

@ -0,0 +1,9 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class OtherTitlesEntity(
var synonyms: List<String>? = null,
var abbreviatedTitles: List<String>? = null
)

@ -0,0 +1,9 @@
package com.jeluchu.features.anime.models.anime
import kotlinx.serialization.Serializable
@Serializable
data class SeasonalEntity(
var station: String? = null,
var year: Int? = null
)

@ -0,0 +1,15 @@
package com.jeluchu.features.anime.models.episodes
import com.jeluchu.core.models.jikan.anime.AnimeData
import kotlinx.serialization.Serializable
@Serializable
data class EpisodeEntity(
val malId: Int = 0,
val title: String?,
val score: String?,
val image: String?,
val day: String?,
val time: String?,
val timezone: String?,
)

@ -4,7 +4,7 @@ import com.jeluchu.core.models.jikan.anime.AnimeData
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@Serializable @Serializable
data class LastEpisodeData( data class LastEpisodeEntity(
val malId: Int = 0, val malId: Int = 0,
val title: String?, val title: String?,
val score: String?, val score: String?,
@ -14,7 +14,7 @@ data class LastEpisodeData(
val timezone: String?, val timezone: String?,
) { ) {
companion object { companion object {
fun AnimeData.toLastEpisodeData() = LastEpisodeData( fun AnimeData.toLastEpisodeData() = LastEpisodeEntity(
malId = malId ?: 0, malId = malId ?: 0,
day = broadcast?.day.orEmpty(), day = broadcast?.day.orEmpty(),
time = broadcast?.time.orEmpty(), time = broadcast?.time.orEmpty(),

@ -8,8 +8,8 @@ import com.jeluchu.core.extensions.update
import com.jeluchu.core.messages.ErrorMessages import com.jeluchu.core.messages.ErrorMessages
import com.jeluchu.core.models.ErrorResponse import com.jeluchu.core.models.ErrorResponse
import com.jeluchu.core.models.PaginationResponse import com.jeluchu.core.models.PaginationResponse
import com.jeluchu.features.anime.models.lastepisodes.LastEpisodeData import com.jeluchu.features.anime.models.lastepisodes.LastEpisodeEntity
import com.jeluchu.features.anime.models.lastepisodes.LastEpisodeData.Companion.toLastEpisodeData import com.jeluchu.features.anime.models.lastepisodes.LastEpisodeEntity.Companion.toLastEpisodeData
import com.jeluchu.core.models.jikan.search.AnimeSearch import com.jeluchu.core.models.jikan.search.AnimeSearch
import com.jeluchu.core.utils.BaseUrls import com.jeluchu.core.utils.BaseUrls
import com.jeluchu.core.utils.Collections import com.jeluchu.core.utils.Collections
@ -35,8 +35,7 @@ class AnimeService(
private val database: MongoDatabase private val database: MongoDatabase
) { ) {
private val timers = database.getCollection(Collections.TIMERS) private val timers = database.getCollection(Collections.TIMERS)
private val directoryCollection = database.getCollection(Collections.ANIME_DETAILS) private val directoryCollection = database.getCollection(Collections.ANIME_DIRECTORY)
private val lastEpisodesCollection = database.getCollection(Collections.LAST_EPISODES)
suspend fun getDirectory(call: RoutingCall) = try { suspend fun getDirectory(call: RoutingCall) = try {
val type = call.request.queryParameters["type"].orEmpty() val type = call.request.queryParameters["type"].orEmpty()
@ -116,7 +115,7 @@ class AnimeService(
AnimeSearch.serializer() AnimeSearch.serializer()
) )
val animes = mutableListOf<LastEpisodeData>() val animes = mutableListOf<LastEpisodeEntity>()
val totalPage = response.pagination?.lastPage ?: 0 val totalPage = response.pagination?.lastPage ?: 0
response.data?.map { it.toLastEpisodeData() }.orEmpty().let { animes.addAll(it) } response.data?.map { it.toLastEpisodeData() }.orEmpty().let { animes.addAll(it) }
@ -130,7 +129,7 @@ class AnimeService(
delay(1000) delay(1000)
} }
val documentsToInsert = parseDataToDocuments(animes, LastEpisodeData.serializer()) val documentsToInsert = parseDataToDocuments(animes, LastEpisodeEntity.serializer())
if (documentsToInsert.isNotEmpty()) collection.insertMany(documentsToInsert) if (documentsToInsert.isNotEmpty()) collection.insertMany(documentsToInsert)
timers.update(timerKey) timers.update(timerKey)

@ -8,7 +8,6 @@ import com.jeluchu.core.models.PaginationResponse
import com.jeluchu.core.utils.Collections import com.jeluchu.core.utils.Collections
import com.jeluchu.core.utils.TimerKey import com.jeluchu.core.utils.TimerKey
import com.jeluchu.features.anime.mappers.documentToAnimeDirectoryEntity import com.jeluchu.features.anime.mappers.documentToAnimeDirectoryEntity
import com.jeluchu.features.anime.mappers.documentToAnimeTypeEntity
import com.mongodb.client.MongoCollection import com.mongodb.client.MongoCollection
import com.mongodb.client.MongoDatabase import com.mongodb.client.MongoDatabase
import com.mongodb.client.model.Filters import com.mongodb.client.model.Filters
@ -23,7 +22,7 @@ import org.bson.conversions.Bson
class DirectoryService( class DirectoryService(
private val database: MongoDatabase, private val database: MongoDatabase,
private val timers: MongoCollection<Document> = database.getCollection(Collections.TIMERS), private val timers: MongoCollection<Document> = database.getCollection(Collections.TIMERS),
private val directory: MongoCollection<Document> = database.getCollection(Collections.ANIME_DETAILS) private val directory: MongoCollection<Document> = database.getCollection(Collections.ANIME_DIRECTORY)
) { ) {
suspend fun getAnimeByType(call: RoutingCall) { suspend fun getAnimeByType(call: RoutingCall) {
val param = call.getStringSafeParam("type").uppercase() val param = call.getStringSafeParam("type").uppercase()

@ -5,7 +5,6 @@ import com.jeluchu.core.extensions.getIntSafeQueryParam
import com.jeluchu.core.messages.ErrorMessages import com.jeluchu.core.messages.ErrorMessages
import com.jeluchu.core.models.PaginationResponse import com.jeluchu.core.models.PaginationResponse
import com.jeluchu.core.utils.Collections import com.jeluchu.core.utils.Collections
import com.jeluchu.features.anime.mappers.documentToAnimesEntity
import com.jeluchu.features.anime.mappers.documentToAnimesThemeEntity import com.jeluchu.features.anime.mappers.documentToAnimesThemeEntity
import com.mongodb.client.MongoDatabase import com.mongodb.client.MongoDatabase
import io.ktor.http.* import io.ktor.http.*

Loading…
Cancel
Save