LANCommander/LANCommander.SDK/Clients/LibraryClient.cs
Pat Hartl 38db011de8 Show library before it's fully imported
Loads the user's library from the /Library/Games endpoint and displays it immediately. This route returns a full data set for the user's games. Images are rendered directly from the server. The import still runs in the background, preserving any offline functionality.
2026-07-04 03:33:13 -05:00

69 lines
2.1 KiB
C#

using LANCommander.SDK.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using LANCommander.SDK.Factories;
namespace LANCommander.SDK.Services
{
public class LibraryClient(ApiRequestFactory apiRequestFactory)
{
public async Task<IEnumerable<EntityReference>> GetAsync()
{
var results = await apiRequestFactory
.Create()
.UseAuthenticationToken()
.UseVersioning()
.UseRoute("/api/Library")
.GetAsync<IEnumerable<EntityReference>>();
return results ?? [];
}
public async Task<IEnumerable<Game>> GetGamesAsync()
{
var results = await apiRequestFactory
.Create()
.UseAuthenticationToken()
.UseVersioning()
.UseRoute("/api/Library/Games")
.GetAsync<IEnumerable<Game>>();
return results ?? [];
}
public async Task<bool> AddToLibrary(Guid gameId)
{
return await apiRequestFactory
.Create()
.UseAuthenticationToken()
.UseVersioning()
.UseRoute($"/api/Library/AddToLibrary/{gameId}")
.PostAsync<bool>();
}
public async Task<bool> RemoveFromLibrary(Guid gameId)
{
return await apiRequestFactory
.Create()
.UseAuthenticationToken()
.UseVersioning()
.UseRoute($"/api/Library/RemoveFromLibrary/{gameId}")
.PostAsync<bool>();
}
public async Task<bool> RemoveFromLibrary(Guid gameId, Guid[] addonIds)
{
return await apiRequestFactory
.Create()
.UseAuthenticationToken()
.UseVersioning()
.UseRoute($"/api/Library/RemoveFromLibrary/{gameId}/addons")
.AddBody(new GenericGuidsRequest
{
Guids = addonIds
})
.PostAsync<bool>();
}
}
}