Skip to content

Commit 02125b1

Browse files
committed
Include Ranking Endpoints (Anime, Manga, People and Characters)
1 parent a980780 commit 02125b1

28 files changed

+617
-58
lines changed

src/main/kotlin/com/jeluchu/core/enums/AnimeFilterTypes.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ enum class AnimeFilterTypes {
1010
FAVORITE,
1111
}
1212

13-
fun parseFilterType(type: String) = AnimeFilterTypes.entries.firstOrNull { it.name.equals(type, ignoreCase = true) }
13+
val animeFilterTypesErrorList = AnimeFilterTypes.entries.joinToString(", ") { it.name.lowercase() }
14+
fun parseAnimeFilterType(type: String) = AnimeFilterTypes.entries.firstOrNull { it.name.equals(type, ignoreCase = true) }

src/main/kotlin/com/jeluchu/core/enums/AnimeTypes.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ enum class AnimeTypes {
1515
TV_SPECIAL,
1616
}
1717

18-
fun parseType(type: String) = AnimeTypes.entries.firstOrNull { it.name.equals(type, ignoreCase = true) }
18+
val animeTypesErrorList = AnimeTypes.entries.joinToString(", ") { it.name.lowercase() }
19+
fun parseAnimeType(type: String) = AnimeTypes.entries.firstOrNull { it.name.equals(type, ignoreCase = true) }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.jeluchu.core.enums
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
enum class MangaFilterTypes {
7+
PUBLISHING,
8+
UPCOMING,
9+
BYPOPULARITY,
10+
FAVORITE,
11+
}
12+
13+
val mangaFilterTypesErrorList = MangaFilterTypes.entries.joinToString(", ") { it.name.lowercase() }
14+
fun parseMangaFilterType(type: String) = MangaFilterTypes.entries.firstOrNull { it.name.equals(type, ignoreCase = true) }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.jeluchu.core.enums
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
enum class MangaTypes {
7+
MANGA,
8+
NOVEL,
9+
LIGHTNOVEL,
10+
ONESHOT,
11+
DOUJIN,
12+
MANHWA,
13+
MANHUA
14+
}
15+
16+
val mangaTypesErrorList = MangaTypes.entries.joinToString(", ") { it.name.lowercase() }
17+
fun parseMangaType(type: String) = MangaTypes.entries.firstOrNull { it.name.equals(type, ignoreCase = true) }

src/main/kotlin/com/jeluchu/core/extensions/RoutesExtensions.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,11 @@ fun Route.getToJson(
1111
): Route = get(path) {
1212
call.response.headers.append(HttpHeaders.ContentType, ContentType.Application.Json.toString())
1313
withContext(Dispatchers.IO) { request() }
14+
}
15+
16+
fun Route.getToJson(
17+
request: suspend RoutingContext.() -> Unit
18+
): Route = get {
19+
call.response.headers.append(HttpHeaders.ContentType, ContentType.Application.Json.toString())
20+
withContext(Dispatchers.IO) { request() }
1421
}

src/main/kotlin/com/jeluchu/core/extensions/UpdatingExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fun MongoCollection<Document>.update(key: String) {
3838
.append(TimerKey.LAST_UPDATED, Date.from(currentTime))
3939

4040
replaceOne(
41-
eq(TimerKey.KEY, TimerKey.SCHEDULE),
41+
eq(TimerKey.KEY, key),
4242
newTimestampDocument,
4343
ReplaceOptions().upsert(true)
4444
)
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package com.jeluchu.core.messages
22

3-
import com.jeluchu.core.enums.Day
3+
import com.jeluchu.core.enums.*
44

55
sealed class ErrorMessages(val message: String) {
66
data object NotFound : ErrorMessages("Nyaaaaaaaan! This request has not been found by our alpaca-neko")
77
data object AnimeNotFound : ErrorMessages("This malId is not in our database")
88
data object InvalidMalId : ErrorMessages("The provided id of malId is invalid")
99
data object InvalidDay : ErrorMessages("Invalid 'day' parameter. Valid values are: ${Day.entries.joinToString(", ") { it.name.lowercase() }}")
10+
data object InvalidTopAnimeType : ErrorMessages("Invalid 'type' parameter. Valid values are: $animeTypesErrorList")
11+
data object InvalidTopAnimeFilterType : ErrorMessages("Invalid 'type' parameter. Valid values are: $animeFilterTypesErrorList")
12+
data object InvalidTopMangaType : ErrorMessages("Invalid 'type' parameter. Valid values are: $mangaTypesErrorList")
13+
data object InvalidTopMangaFilterType : ErrorMessages("Invalid 'type' parameter. Valid values are: $mangaFilterTypesErrorList")
1014
data object InvalidInput : ErrorMessages("Invalid input provided")
1115
data object UnauthorizedMongo : ErrorMessages("Check the MongoDb Connection String to be able to correctly access this request.")
1216
}

src/main/kotlin/com/jeluchu/core/models/jikan/anime/AnimeData.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package com.jeluchu.core.models.jikan.anime
22

33
import com.jeluchu.core.enums.Day
44
import com.jeluchu.core.utils.toVideoPromo
5-
import com.jeluchu.features.rankings.models.TopEntity
5+
import com.jeluchu.features.rankings.models.AnimeTopEntity
6+
import com.jeluchu.features.rankings.models.MangaTopEntity
67
import com.jeluchu.features.schedule.models.DayEntity
78
import kotlinx.serialization.SerialName
89
import kotlinx.serialization.Serializable
@@ -284,12 +285,12 @@ data class AnimeData(
284285
title = titles?.first()?.title.orEmpty()
285286
)
286287

287-
fun AnimeData.toTopEntity(
288+
fun AnimeData.toAnimeTopEntity(
288289
page: Int,
289-
rank: Int,
290+
top: String,
290291
type: String,
291292
subType: String,
292-
) = TopEntity(
293+
) = AnimeTopEntity(
293294
malId = malId,
294295
rank = rank,
295296
score = score,
@@ -300,6 +301,7 @@ data class AnimeData(
300301
season = season,
301302
year = year,
302303
airing = airing,
304+
top = top,
303305
type = type,
304306
subtype = subType,
305307
page = page
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package fordelete
2+
3+
import com.jeluchu.core.models.jikan.anime.Images
4+
import com.jeluchu.core.models.jikan.people.PeopleData
5+
import com.jeluchu.features.rankings.models.CharacterTopEntity
6+
import com.jeluchu.features.rankings.models.PeopleTopEntity
7+
import kotlinx.serialization.SerialName
8+
import kotlinx.serialization.Serializable
9+
10+
@Serializable
11+
data class CharacterData(
12+
@SerialName("mal_id")
13+
val malId: Int? = 0,
14+
15+
@SerialName("about")
16+
val about: String? = "",
17+
18+
@SerialName("favorites")
19+
val favorites: Int? = 0,
20+
21+
@SerialName("images")
22+
val images: Images? = Images(),
23+
24+
@SerialName("name")
25+
val name: String? = "",
26+
27+
@SerialName("name_kanji")
28+
val nameKanji: String? = "",
29+
30+
@SerialName("nicknames")
31+
val nicknames: List<String>? = emptyList(),
32+
33+
@SerialName("url")
34+
val url: String? = ""
35+
) {
36+
companion object {
37+
fun CharacterData.toCharacterTopEntity(
38+
page: Int,
39+
top: String
40+
) = CharacterTopEntity(
41+
malId = malId,
42+
image = images?.webp?.large.orEmpty(),
43+
name = name,
44+
nameKanji = nameKanji,
45+
top = top,
46+
page = page
47+
)
48+
}
49+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.jeluchu.core.models.jikan.character
2+
3+
import com.jeluchu.core.models.jikan.search.Pagination
4+
import fordelete.CharacterData
5+
import kotlinx.serialization.SerialName
6+
import kotlinx.serialization.Serializable
7+
8+
@Serializable
9+
data class CharacterSearch(
10+
@SerialName("data")
11+
val data: List<CharacterData>? = emptyList(),
12+
13+
@SerialName("pagination")
14+
val pagination: Pagination? = Pagination()
15+
)

0 commit comments

Comments
 (0)