Skip to content

Commit

Permalink
Include Ranking Endpoints (Anime, Manga, People and Characters)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeluchu committed Nov 29, 2024
1 parent a980780 commit 02125b1
Show file tree
Hide file tree
Showing 28 changed files with 617 additions and 58 deletions.
3 changes: 2 additions & 1 deletion src/main/kotlin/com/jeluchu/core/enums/AnimeFilterTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ enum class AnimeFilterTypes {
FAVORITE,
}

fun parseFilterType(type: String) = AnimeFilterTypes.entries.firstOrNull { it.name.equals(type, ignoreCase = true) }
val animeFilterTypesErrorList = AnimeFilterTypes.entries.joinToString(", ") { it.name.lowercase() }
fun parseAnimeFilterType(type: String) = AnimeFilterTypes.entries.firstOrNull { it.name.equals(type, ignoreCase = true) }
3 changes: 2 additions & 1 deletion src/main/kotlin/com/jeluchu/core/enums/AnimeTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ enum class AnimeTypes {
TV_SPECIAL,
}

fun parseType(type: String) = AnimeTypes.entries.firstOrNull { it.name.equals(type, ignoreCase = true) }
val animeTypesErrorList = AnimeTypes.entries.joinToString(", ") { it.name.lowercase() }
fun parseAnimeType(type: String) = AnimeTypes.entries.firstOrNull { it.name.equals(type, ignoreCase = true) }
14 changes: 14 additions & 0 deletions src/main/kotlin/com/jeluchu/core/enums/MangaFilterTypes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.jeluchu.core.enums

import kotlinx.serialization.Serializable

@Serializable
enum class MangaFilterTypes {
PUBLISHING,
UPCOMING,
BYPOPULARITY,
FAVORITE,
}

val mangaFilterTypesErrorList = MangaFilterTypes.entries.joinToString(", ") { it.name.lowercase() }
fun parseMangaFilterType(type: String) = MangaFilterTypes.entries.firstOrNull { it.name.equals(type, ignoreCase = true) }
17 changes: 17 additions & 0 deletions src/main/kotlin/com/jeluchu/core/enums/MangaTypes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jeluchu.core.enums

import kotlinx.serialization.Serializable

@Serializable
enum class MangaTypes {
MANGA,
NOVEL,
LIGHTNOVEL,
ONESHOT,
DOUJIN,
MANHWA,
MANHUA
}

val mangaTypesErrorList = MangaTypes.entries.joinToString(", ") { it.name.lowercase() }
fun parseMangaType(type: String) = MangaTypes.entries.firstOrNull { it.name.equals(type, ignoreCase = true) }
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ fun Route.getToJson(
): Route = get(path) {
call.response.headers.append(HttpHeaders.ContentType, ContentType.Application.Json.toString())
withContext(Dispatchers.IO) { request() }
}

fun Route.getToJson(
request: suspend RoutingContext.() -> Unit
): Route = get {
call.response.headers.append(HttpHeaders.ContentType, ContentType.Application.Json.toString())
withContext(Dispatchers.IO) { request() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fun MongoCollection<Document>.update(key: String) {
.append(TimerKey.LAST_UPDATED, Date.from(currentTime))

replaceOne(
eq(TimerKey.KEY, TimerKey.SCHEDULE),
eq(TimerKey.KEY, key),
newTimestampDocument,
ReplaceOptions().upsert(true)
)
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/com/jeluchu/core/messages/ErrorMessages.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.jeluchu.core.messages

import com.jeluchu.core.enums.Day
import com.jeluchu.core.enums.*

sealed class ErrorMessages(val message: String) {
data object NotFound : ErrorMessages("Nyaaaaaaaan! This request has not been found by our alpaca-neko")
data object AnimeNotFound : ErrorMessages("This malId is not in our database")
data object InvalidMalId : ErrorMessages("The provided id of malId is invalid")
data object InvalidDay : ErrorMessages("Invalid 'day' parameter. Valid values are: ${Day.entries.joinToString(", ") { it.name.lowercase() }}")
data object InvalidTopAnimeType : ErrorMessages("Invalid 'type' parameter. Valid values are: $animeTypesErrorList")
data object InvalidTopAnimeFilterType : ErrorMessages("Invalid 'type' parameter. Valid values are: $animeFilterTypesErrorList")
data object InvalidTopMangaType : ErrorMessages("Invalid 'type' parameter. Valid values are: $mangaTypesErrorList")
data object InvalidTopMangaFilterType : ErrorMessages("Invalid 'type' parameter. Valid values are: $mangaFilterTypesErrorList")
data object InvalidInput : ErrorMessages("Invalid input provided")
data object UnauthorizedMongo : ErrorMessages("Check the MongoDb Connection String to be able to correctly access this request.")
}
10 changes: 6 additions & 4 deletions src/main/kotlin/com/jeluchu/core/models/jikan/anime/AnimeData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package com.jeluchu.core.models.jikan.anime

import com.jeluchu.core.enums.Day
import com.jeluchu.core.utils.toVideoPromo
import com.jeluchu.features.rankings.models.TopEntity
import com.jeluchu.features.rankings.models.AnimeTopEntity
import com.jeluchu.features.rankings.models.MangaTopEntity
import com.jeluchu.features.schedule.models.DayEntity
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -284,12 +285,12 @@ data class AnimeData(
title = titles?.first()?.title.orEmpty()
)

fun AnimeData.toTopEntity(
fun AnimeData.toAnimeTopEntity(
page: Int,
rank: Int,
top: String,
type: String,
subType: String,
) = TopEntity(
) = AnimeTopEntity(
malId = malId,
rank = rank,
score = score,
Expand All @@ -300,6 +301,7 @@ data class AnimeData(
season = season,
year = year,
airing = airing,
top = top,
type = type,
subtype = subType,
page = page
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package fordelete

import com.jeluchu.core.models.jikan.anime.Images
import com.jeluchu.core.models.jikan.people.PeopleData
import com.jeluchu.features.rankings.models.CharacterTopEntity
import com.jeluchu.features.rankings.models.PeopleTopEntity
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class CharacterData(
@SerialName("mal_id")
val malId: Int? = 0,

@SerialName("about")
val about: String? = "",

@SerialName("favorites")
val favorites: Int? = 0,

@SerialName("images")
val images: Images? = Images(),

@SerialName("name")
val name: String? = "",

@SerialName("name_kanji")
val nameKanji: String? = "",

@SerialName("nicknames")
val nicknames: List<String>? = emptyList(),

@SerialName("url")
val url: String? = ""
) {
companion object {
fun CharacterData.toCharacterTopEntity(
page: Int,
top: String
) = CharacterTopEntity(
malId = malId,
image = images?.webp?.large.orEmpty(),
name = name,
nameKanji = nameKanji,
top = top,
page = page
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.jeluchu.core.models.jikan.character

import com.jeluchu.core.models.jikan.search.Pagination
import fordelete.CharacterData
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class CharacterSearch(
@SerialName("data")
val data: List<CharacterData>? = emptyList(),

@SerialName("pagination")
val pagination: Pagination? = Pagination()
)
126 changes: 126 additions & 0 deletions src/main/kotlin/com/jeluchu/core/models/jikan/manga/MangaData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.jeluchu.core.models.jikan.manga

import com.jeluchu.core.models.jikan.anime.*
import com.jeluchu.features.rankings.models.MangaTopEntity
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class MangaData(
@SerialName("approved")
val approved: Boolean? = false,

@SerialName("authors")
val authors: List<Demographic>? = emptyList(),

@SerialName("background")
val background: String? = "",

@SerialName("chapters")
val chapters: Int? = 0,

@SerialName("demographics")
val demographics: List<Demographic>? = emptyList(),

@SerialName("explicit_genres")
val explicitGenres: List<Genre>? = emptyList(),

@SerialName("favorites")
val favorites: Int? = 0,

@SerialName("genres")
val genres: List<Genre>? = emptyList(),

@SerialName("images")
val images: Images? = Images(),

@SerialName("mal_id")
val malId: Int? = 0,

@SerialName("members")
val members: Int? = 0,

@SerialName("popularity")
val popularity: Int? = 0,

@SerialName("published")
val published: Published? = Published(),

@SerialName("publishing")
val publishing: Boolean? = false,

@SerialName("rank")
val rank: Int? = 0,

@SerialName("score")
val score: Double? = 0.0,

@SerialName("scored")
val scored: Double? = 0.0,

@SerialName("scored_by")
val scoredBy: Int? = 0,

@SerialName("serializations")
val serializations: List<Demographic>? = emptyList(),

@SerialName("status")
val status: String? = "",

@SerialName("synopsis")
val synopsis: String? = "",

@SerialName("themes")
val themes: List<Themes>? = emptyList(),

@Deprecated("Use 'titles: List<Title>' to get the title")
@SerialName("title")
val title: String? = "",

@Deprecated("Use 'titles: List<Title>' to get the title")
@SerialName("title_english")
val titleEnglish: String? = "",

@Deprecated("Use 'titles: List<Title>' to get the title")
@SerialName("title_japanese")
val titleJapanese: String? = "",

@Deprecated("Use 'titles: List<Title>' to get the title")
@SerialName("title_synonyms")
val titleSynonyms: List<String>? = emptyList(),

@SerialName("titles")
val titles: List<Title>? = emptyList(),

@SerialName("type")
val type: String? = "",

@SerialName("url")
val url: String? = "",

@SerialName("volumes")
val volumes: Int? = 0
) {
companion object {
fun MangaData.toMangaTopEntity(
page: Int,
top: String,
type: String,
subType: String,
) = MangaTopEntity(
malId = malId,
rank = rank,
score = score,
image = images?.webp?.large.orEmpty(),
title = titles?.first()?.title.orEmpty(),
url = url,
status = status,
volumes = volumes,
chapters = chapters,
top = top,
type = type,
subtype = subType,
page = page
)
}
}
20 changes: 20 additions & 0 deletions src/main/kotlin/com/jeluchu/core/models/jikan/manga/Published.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.jeluchu.core.models.jikan.manga

import com.jeluchu.core.models.jikan.anime.Prop
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class Published(
@SerialName("from")
val from: String? = "",

@SerialName("prop")
val prop: Prop? = Prop(),

@SerialName("string")
val string: String? = "",

@SerialName("to")
val to: String? = ""
)
Loading

0 comments on commit 02125b1

Please sign in to comment.