mirror of
https://github.com/ultrasn0w/app.git
synced 2025-12-13 23:09:52 +01:00
First stuff
This commit is contained in:
31
APP/Utility/BackendComms.cs
Normal file
31
APP/Utility/BackendComms.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user