Skip to content

Commit

Permalink
Fixed Directory endpoint and improve anime endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jeluchu committed Dec 19, 2024
1 parent 02125b1 commit f948ca6
Show file tree
Hide file tree
Showing 28 changed files with 55 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ out/
gradlew

gradlew.bat

.kotlin/
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.jeluchu.core.models.jikan.anime

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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.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
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
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

Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/com/jeluchu/core/utils/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ object BaseUrls {
}

object Endpoints {
const val FULL = "full"
const val ANIME = "anime/"
const val SCHEDULES = "schedules"
const val TOP_ANIME = "top/anime"
const val TOP_MANGA = "top/manga"
const val TOP_PEOPLE = "top/people"
const val STATISTICS = "statistics"
const val CHARACTERS = "characters"
const val TOP_CHARACTER = "top/characters"
}

Expand Down Expand Up @@ -41,5 +45,6 @@ object Collections {
const val ANIME_RANKING = "anime_ranking"
const val MANGA_RANKING = "manga_ranking"
const val PEOPLE_RANKING = "people_ranking"
const val ANIME_DIRECTORY = "anime_directory"
const val CHARACTER_RANKING = "character_ranking"
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/jeluchu/core/utils/Mappers.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.jeluchu.core.utils

import com.example.models.VideoPromo
import com.jeluchu.core.models.jikan.anime.ImageFormat
import com.jeluchu.core.models.jikan.anime.Trailer
import com.jeluchu.features.anime.models.anime.Images
import com.jeluchu.features.anime.models.anime.VideoPromo

fun Trailer.toVideoPromo() = VideoPromo(
url = url.orEmpty(),
Expand Down
19 changes: 13 additions & 6 deletions src/main/kotlin/com/jeluchu/features/anime/mappers/AnimeMappers.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.jeluchu.features.anime.mappers

import com.example.models.*
import com.jeluchu.core.extensions.*
import com.jeluchu.features.anime.models.anime.Images
import com.jeluchu.features.anime.models.anime.*
import com.jeluchu.features.anime.models.directory.AnimeDirectoryEntity
import com.jeluchu.features.rankings.models.AnimeTopEntity
import com.jeluchu.features.schedule.models.DayEntity
import org.bson.Document
import java.sql.Timestamp
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter

fun documentToAnimeDirectoryEntity(doc: Document) = AnimeDirectoryEntity(
rank = doc.getIntSafe("rank"),
Expand All @@ -26,7 +28,7 @@ fun documentToAnimeDirectoryEntity(doc: Document) = AnimeDirectoryEntity(

fun documentToMoreInfoEntity(doc: Document): MoreInfoEntity {
return MoreInfoEntity(
id = doc.getLongSafe("id"),
id = doc.getObjectId("_id").toString(),
malId = doc.getIntSafe("malId"),
title = doc.getStringSafe("title"),
poster = doc.getStringSafe("poster"),
Expand Down Expand Up @@ -155,9 +157,14 @@ fun documentToIndividual(doc: Document): Individual {

fun documentToMergedEpisode(doc: Document): MergedEpisode {
return MergedEpisode(
number = doc.getIntSafe("number", 0),
ids = doc.getListSafe<Document>("ids").map { documentToAnimeSource(it) }.toMutableList(),
nextEpisodeDate = doc.getStringSafe("nextEpisodeDate")
malId = doc.getIntSafe("malId"),
title = doc.getStringSafe("title"),
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")
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

@Serializable
data class MergedEpisode(
var number: Int,
var ids: MutableList<AnimeSource> = mutableListOf(),
var nextEpisodeDate: String = ""
var malId: Int,
var title: String,
var titleJapanese: String,
var titleRomanji: String,
var aired: String,
var score: Float,
var filler: Boolean,
var recap: Boolean,
)

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
Expand All @@ -7,8 +7,8 @@ import org.bson.Document

@Serializable
data class MoreInfoEntity(
val id: Long? = null,
var malId: Int = 0,
val id: String = "",
var title: String = "",
var poster: String = "",
var cover: String = "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.models
package com.jeluchu.features.anime.models.anime

import com.jeluchu.features.anime.models.anime.Images
import kotlinx.serialization.Serializable

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import io.ktor.server.routing.*

fun Route.animeEndpoints(
mongoDatabase: MongoDatabase,
service: AnimeService = AnimeService(mongoDatabase)
service: AnimeService = AnimeService(mongoDatabase),
) {
getToJson(Routes.DIRECTORY) { service.getDirectory(call) }
getToJson(Routes.ANIME_DETAILS) { service.getAnimeByMalId(call) }
route(Routes.DIRECTORY) {
getToJson { service.getDirectory(call) }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.jeluchu.features.rankings.models

import com.example.models.VideoPromo
import com.jeluchu.features.anime.models.anime.VideoPromo
import kotlinx.serialization.Serializable

@Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jeluchu.features.schedule.models

import com.jeluchu.core.models.jikan.search.Pagination
import com.jeluchu.core.models.jikan.anime.AnimeData
import com.jeluchu.core.models.jikan.search.Pagination
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand Down

0 comments on commit f948ca6

Please sign in to comment.