mirror of
https://github.com/ultrasn0w/app.git
synced 2025-12-13 19:09:53 +01:00
32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
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<List<SeasonAnime>?> GetSeason()
|
|
{
|
|
var resp = await Client.GetAsync(ApiBaseUrl + "season");
|
|
if (!resp.IsSuccessStatusCode) return null;
|
|
return await resp.Content.ReadFromJsonAsync<List<SeasonAnime>>(JsonSerializerOptions);
|
|
}
|
|
|
|
internal static async Task<User?> 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<ICollection<User>>(JsonSerializerOptions);
|
|
return users?.SingleOrDefault();
|
|
}
|
|
}
|