From 8d98193e50e511ca659a23ac9909b9fde52b82e5 Mon Sep 17 00:00:00 2001 From: JoKeRZH429 <83122870+JoKeRZH429@users.noreply.github.com> Date: Sat, 27 Jun 2026 01:52:47 +0500 Subject: [PATCH] chore: extract the leaderboard endpoints into appsettings --- .../ExternalLeaderboardsClient.cs | 28 +++++++++++-------- GenOnlineService/appsettings.json | 5 ++-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/GenOnlineService/ExternalLeaderboardsClient.cs b/GenOnlineService/ExternalLeaderboardsClient.cs index ca8078f..2f80d42 100644 --- a/GenOnlineService/ExternalLeaderboardsClient.cs +++ b/GenOnlineService/ExternalLeaderboardsClient.cs @@ -29,9 +29,10 @@ public class EloRefreshEntry public static class ExternalLeaderboardsClient { - private static void GetExternalLeaderboardsConfig(out string baseUrl, out string postToken, out string getToken) + private static void GetExternalLeaderboardsConfig(out string postUrl, out string getUrl, out string postToken, out string getToken) { - baseUrl = string.Empty; + postUrl = string.Empty; + getUrl = string.Empty; postToken = string.Empty; getToken = string.Empty; @@ -46,13 +47,19 @@ private static void GetExternalLeaderboardsConfig(out string baseUrl, out string throw new Exception("ExternalLeaderboards section missing in config"); } - string? sectionBaseUrl = configSection.GetValue("BaseUrl"); + string? sectionPostUrl = configSection.GetValue("PostUrl"); + string? sectionGetUrl = configSection.GetValue("GetUrl"); string? sectionPostToken = configSection.GetValue("PostToken"); string? sectionGetToken = configSection.GetValue("GetToken"); - if (string.IsNullOrEmpty(sectionBaseUrl)) + if (string.IsNullOrEmpty(sectionPostUrl)) { - throw new Exception("ExternalLeaderboards BaseUrl missing in config"); + throw new Exception("ExternalLeaderboards PostUrl missing in config"); + } + + if (string.IsNullOrEmpty(sectionGetUrl)) + { + throw new Exception("ExternalLeaderboards GetUrl missing in config"); } if (string.IsNullOrEmpty(sectionPostToken)) @@ -65,7 +72,8 @@ private static void GetExternalLeaderboardsConfig(out string baseUrl, out string throw new Exception("ExternalLeaderboards GetToken missing in config"); } - baseUrl = sectionBaseUrl; + postUrl = sectionPostUrl; + getUrl = sectionGetUrl; postToken = sectionPostToken; getToken = sectionGetToken; } @@ -103,9 +111,7 @@ public static async Task PostMatchResultAsync(AppDbContext db, Lobby lobby) try { - GetExternalLeaderboardsConfig(out string baseUrl, out string postToken, out _); - - string postUrl = $"{baseUrl.TrimEnd('/')}/matches/ingest"; + GetExternalLeaderboardsConfig(out string postUrl, out _, out string postToken, out _); // Load the match payload var matchEntry = await Database.MatchHistory.LoadMatchHistoryEntryAsync(db, (long)lobby.MatchID); @@ -209,9 +215,9 @@ await retryPolicy.ExecuteAsync(async () => { try { - GetExternalLeaderboardsConfig(out string baseUrl, out _, out string getToken); + GetExternalLeaderboardsConfig(out _, out string getUrl, out _, out string getToken); - string requestUrl = $"{baseUrl.TrimEnd('/')}/players/{playerId}/leagues/1/rating"; + string requestUrl = getUrl.Replace("{playerId}", playerId.ToString()); using (var handler = CreateLeaderboardsHandler()) using (var client = new HttpClient(handler)) diff --git a/GenOnlineService/appsettings.json b/GenOnlineService/appsettings.json index 4e53e57..92079ed 100644 --- a/GenOnlineService/appsettings.json +++ b/GenOnlineService/appsettings.json @@ -77,8 +77,9 @@ "issuer": null }, "ExternalLeaderboards": { - "BaseUrl": null, + "PostUrl": null, + "GetUrl": null, "GetToken": null, - "PostToken": null, + "PostToken": null } }