using System.Net.Http.Json; using Prefab.Web.Client.Models.Shared; using Prefab.Web.Client.Pages; namespace Prefab.Web.Client.Services; public interface ICategoriesPageService { Task> GetPage(CancellationToken cancellationToken); } public sealed class CategoriesPageService(HttpClient httpClient) : ICategoriesPageService { public async Task> GetPage(CancellationToken cancellationToken) { using var response = await httpClient.GetAsync("bff/categories/page", cancellationToken); var result = await response.Content.ReadFromJsonAsync>(cancellationToken); if (result is not null) { return result; } var exception = new InvalidOperationException($"Response {(int)response.StatusCode} did not contain a valid payload."); var unexpectedProblem = ResultProblem.Unexpected("Failed to retrieve categories.", exception, response.StatusCode); return Result.Failure(unexpectedProblem); } }