LANCommander/LANCommander.SDK/Services/DepotService.cs
Pat Hartl f52e0349a5 Fix depot list API, gracefully handle depot errors
- Depot endpoint was doing an improper operation to get a user by username
- Failure to get depot results will result in a graceful error handling
- Depot will now show a no results error if nothing is available
- Depot will now show a no results message if there are no results in the applied filter

Fixes #210
2025-03-14 02:19:11 -05:00

46 lines
1.1 KiB
C#

using Force.Crc32;
using LANCommander.SDK.Extensions;
using LANCommander.SDK.Helpers;
using LANCommander.SDK.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using LANCommander.SDK.Exceptions;
namespace LANCommander.SDK.Services
{
public class DepotService
{
private readonly ILogger Logger;
private readonly Client Client;
public DepotService(Client client)
{
Client = client;
}
public DepotService(Client client, ILogger logger)
{
Client = client;
Logger = logger;
}
public async Task<DepotResults> GetAsync()
{
var results = await Client.GetRequestAsync<DepotResults>("/api/Depot");
if (results == null)
throw new DepotNoResultsException("Did not find any depot results");
return results;
}
public async Task<DepotGame> GetGameAsync(Guid gameId)
{
return await Client.GetRequestAsync<DepotGame>($"/api/Depot/Games/{gameId}");
}
}
}