using System.Net.Http.Json; using System.Text.Json; using APP.DTO; namespace APP.Utility; internal static class BackendComms { private const string ApiBaseUrl = "https://huso.hanami.family/api/"; private static readonly HttpClient Client = new(); private static readonly JsonSerializerOptions JsonSerializerOptions = new() {PropertyNameCaseInsensitive = true}; internal static async Task?> GetSeason() { var resp = await Client.GetAsync(ApiBaseUrl + "season"); if (!resp.IsSuccessStatusCode) return null; return await resp.Content.ReadFromJsonAsync>(JsonSerializerOptions); } internal static async Task GetUser(string username) { if (string.IsNullOrWhiteSpace(username)) { return null; } var resp = await Client.GetAsync(ApiBaseUrl + "user/"+username); if (!resp.IsSuccessStatusCode) return null; var users = await resp.Content.ReadFromJsonAsync>(JsonSerializerOptions); return users?.SingleOrDefault(); } }