From e0cabfefcf3045751c58078bab2c79700838e7f5 Mon Sep 17 00:00:00 2001 From: Stedoss <29103029+Stedoss@users.noreply.github.com> Date: Sun, 17 Nov 2024 00:26:31 +0000 Subject: [PATCH] Implement `getUserBeatmapScores` --- .../main/kotlin/com/nisemoe/nise/osu/OsuApi.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/nise-backend/src/main/kotlin/com/nisemoe/nise/osu/OsuApi.kt b/nise-backend/src/main/kotlin/com/nisemoe/nise/osu/OsuApi.kt index 6291213..0346bfb 100644 --- a/nise-backend/src/main/kotlin/com/nisemoe/nise/osu/OsuApi.kt +++ b/nise-backend/src/main/kotlin/com/nisemoe/nise/osu/OsuApi.kt @@ -214,6 +214,20 @@ class OsuApi( } } + fun getUserBeatmapScores(userId: Long, beatmapId: Int): OsuApiModels.BeatmapScores? { + val response = doRequest("https://osu.ppy.sh/api/v2/beatmaps/$beatmapId/scores/users/$userId/all", mapOf()) + + if(response == null) { + this.logger.info("Error getting scores on beatmap $beatmapId for user $userId") + return null + } + + return when (response.statusCode()) { + 200 -> serializer.decodeFromString(response.body()) + else -> null + } + } + fun searchBeatmapsets(cursor: OsuApiModels.BeatmapsetSearchResultCursor?): OsuApiModels.BeatmapsetSearchResult? { val queryParams = mutableMapOf( "s" to "ranked", // Status [only ranked] @@ -294,7 +308,7 @@ class OsuApi( } } - fun getUserMostPlayed(userId: Int, limit: Int? = null, offset: Int? = null): List? { + fun getUserMostPlayed(userId: Long, limit: Int? = null, offset: Int? = null): List? { val queryParams = mapOf( "limit" to limit, "offset" to offset,