From 9121a6341c6f478df79391d0ae718fbe1a12c650 Mon Sep 17 00:00:00 2001 From: Mitchell Syer Date: Tue, 23 Jan 2024 18:48:47 -0500 Subject: [PATCH] Fix Tracker Status and Scores (#843) --- .../graphql/dataLoaders/TrackDataLoader.kt | 31 +++++++++++++++++++ .../TachideskDataLoaderRegistryFactory.kt | 4 +++ .../tachidesk/graphql/types/TrackType.kt | 13 ++++++++ .../tachidesk/manga/impl/track/Track.kt | 5 +-- .../impl/track/tracker/anilist/Anilist.kt | 12 +++---- .../track/tracker/myanimelist/MyAnimeList.kt | 12 +++---- 6 files changed, 63 insertions(+), 14 deletions(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/dataLoaders/TrackDataLoader.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/dataLoaders/TrackDataLoader.kt index 2af1cc06a..eefa78798 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/dataLoaders/TrackDataLoader.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/dataLoaders/TrackDataLoader.kt @@ -17,6 +17,7 @@ import org.jetbrains.exposed.sql.transactions.transaction import suwayomi.tachidesk.graphql.types.TrackRecordNodeList import suwayomi.tachidesk.graphql.types.TrackRecordNodeList.Companion.toNodeList import suwayomi.tachidesk.graphql.types.TrackRecordType +import suwayomi.tachidesk.graphql.types.TrackStatusType import suwayomi.tachidesk.graphql.types.TrackerType import suwayomi.tachidesk.manga.impl.track.tracker.TrackerManager import suwayomi.tachidesk.manga.impl.track.tracker.model.toTrack @@ -36,6 +37,36 @@ class TrackerDataLoader : KotlinDataLoader { } } +class TrackerStatusesDataLoader : KotlinDataLoader> { + override val dataLoaderName = "TrackerStatusesDataLoader" + + override fun getDataLoader(): DataLoader> = + DataLoaderFactory.newDataLoader { ids -> + future { + ids.map { id -> + TrackerManager.getTracker(id)?.let { tracker -> + tracker.getStatusList().map { + TrackStatusType(it, tracker.getStatus(it)!!) + } + } + } + } + } +} + +class TrackerScoresDataLoader : KotlinDataLoader> { + override val dataLoaderName = "TrackerStatusesDataLoader" + + override fun getDataLoader(): DataLoader> = + DataLoaderFactory.newDataLoader { ids -> + future { + ids.map { id -> + TrackerManager.getTracker(id)?.getScoreList() + } + } + } +} + class TrackRecordsForMangaIdDataLoader : KotlinDataLoader { override val dataLoaderName = "TrackRecordsForMangaIdDataLoader" diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskDataLoaderRegistryFactory.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskDataLoaderRegistryFactory.kt index 572896aed..8240d9061 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskDataLoaderRegistryFactory.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/TachideskDataLoaderRegistryFactory.kt @@ -35,6 +35,8 @@ import suwayomi.tachidesk.graphql.dataLoaders.TrackRecordDataLoader import suwayomi.tachidesk.graphql.dataLoaders.TrackRecordsForMangaIdDataLoader import suwayomi.tachidesk.graphql.dataLoaders.TrackRecordsForTrackerIdDataLoader import suwayomi.tachidesk.graphql.dataLoaders.TrackerDataLoader +import suwayomi.tachidesk.graphql.dataLoaders.TrackerScoresDataLoader +import suwayomi.tachidesk.graphql.dataLoaders.TrackerStatusesDataLoader import suwayomi.tachidesk.graphql.dataLoaders.UnreadChapterCountForMangaDataLoader class TachideskDataLoaderRegistryFactory { @@ -65,6 +67,8 @@ class TachideskDataLoaderRegistryFactory { ExtensionDataLoader(), ExtensionForSourceDataLoader(), TrackerDataLoader(), + TrackerStatusesDataLoader(), + TrackerScoresDataLoader(), TrackRecordsForMangaIdDataLoader(), DisplayScoreForTrackRecordDataLoader(), TrackRecordsForTrackerIdDataLoader(), diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/TrackType.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/TrackType.kt index 17aeb2eee..b00a6695f 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/TrackType.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/TrackType.kt @@ -38,11 +38,24 @@ class TrackerType( }, ) + fun statuses(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture> { + return dataFetchingEnvironment.getValueFromDataLoader>("TrackerStatusesDataLoader", id) + } + + fun scores(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture> { + return dataFetchingEnvironment.getValueFromDataLoader>("TrackerScoresDataLoader", id) + } + fun trackRecords(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture { return dataFetchingEnvironment.getValueFromDataLoader("TrackRecordsForTrackerIdDataLoader", id) } } +class TrackStatusType( + val value: Int, + val name: String, +) + class TrackRecordType( val id: Int, val mangaId: Int, diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/Track.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/Track.kt index d93704d04..fb791a42a 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/Track.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/Track.kt @@ -99,7 +99,7 @@ object Track { name = it.name, icon = proxyThumbnailUrl(it.id), statusList = it.getStatusList(), - statusTextMap = it.getStatusList().associateWith { k -> it.getStatus(k) ?: "" }, + statusTextMap = it.getStatusList().associateWith { k -> it.getStatus(k).orEmpty() }, scoreList = it.getScoreList(), record = record, ) @@ -223,7 +223,8 @@ object Track { } if (input.scoreString != null) { val score = tracker.indexToScore(tracker.getScoreList().indexOf(input.scoreString)) - recordDb[TrackRecordTable.score] = score.toDouble() + // conversion issues between Float <-> Double so convert to string before double + recordDb[TrackRecordTable.score] = score.toString().toDouble() } if (input.startDate != null) { recordDb[TrackRecordTable.startDate] = input.startDate diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/tracker/anilist/Anilist.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/tracker/anilist/Anilist.kt index 04f6b627b..64f3a6a55 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/tracker/anilist/Anilist.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/tracker/anilist/Anilist.kt @@ -50,12 +50,12 @@ class Anilist(id: Int) : Tracker(id, "AniList"), DeletableTrackService { @StringRes override fun getStatus(status: Int): String? = when (status) { - READING -> "reading" - PLAN_TO_READ -> "plan_to_read" - COMPLETED -> "completed" - ON_HOLD -> "on_hold" - DROPPED -> "dropped" - REREADING -> "repeating" + READING -> "Reading" + PLAN_TO_READ -> "Plan to read" + COMPLETED -> "Completed" + ON_HOLD -> "On hold" + DROPPED -> "Dropped" + REREADING -> "Rereading" else -> null } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/tracker/myanimelist/MyAnimeList.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/tracker/myanimelist/MyAnimeList.kt index 0df53c652..4fc707d62 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/tracker/myanimelist/MyAnimeList.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/tracker/myanimelist/MyAnimeList.kt @@ -46,12 +46,12 @@ class MyAnimeList(id: Int) : Tracker(id, "MyAnimeList"), DeletableTrackService { @StringRes override fun getStatus(status: Int): String? = when (status) { - READING -> "reading" - PLAN_TO_READ -> "plan_to_read" - COMPLETED -> "completed" - ON_HOLD -> "on_hold" - DROPPED -> "dropped" - REREADING -> "repeating" + READING -> "Reading" + PLAN_TO_READ -> "Plan to read" + COMPLETED -> "Completed" + ON_HOLD -> "On hold" + DROPPED -> "Dropped" + REREADING -> "Rereading" else -> null }