Init
This commit is contained in:
30
Prefab.Web.Client/Services/ICategoriesPageService.cs
Normal file
30
Prefab.Web.Client/Services/ICategoriesPageService.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
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<Result<CategoriesPageModel>> GetPage(CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
public sealed class CategoriesPageService(HttpClient httpClient) : ICategoriesPageService
|
||||
{
|
||||
public async Task<Result<CategoriesPageModel>> GetPage(CancellationToken cancellationToken)
|
||||
{
|
||||
using var response = await httpClient.GetAsync("bff/categories/page", cancellationToken);
|
||||
|
||||
var result = await response.Content.ReadFromJsonAsync<Result<CategoriesPageModel>>(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<CategoriesPageModel>.Failure(unexpectedProblem);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user