Created
May 3, 2024 15:01
-
-
Save andrebaltieri/5cf0d70aa52b6624811c3cff03c62774 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net.Http.Json; | |
using FinaFlow.Core.Entities; | |
namespace FinaFlow.Services; | |
public class CategoryService( | |
IHttpClientFactory httpClientFactory) | |
{ | |
public async Task CreateAsync( | |
Category category) | |
{ | |
var client = httpClientFactory.CreateClient(Configuration.HttpClientName); | |
await client.PostAsJsonAsync($"v1/categories/", category); | |
} | |
public async Task UpdateAsync(uint id, Category category) | |
{ | |
var client = httpClientFactory.CreateClient(Configuration.HttpClientName); | |
await client.PutAsJsonAsync($"v1/categories/{id}", category); | |
} | |
public async Task<List<Category>> GetAsync() | |
{ | |
var client = httpClientFactory.CreateClient(Configuration.HttpClientName); | |
return await client.GetFromJsonAsync<List<Category>>("v1/categories") ?? []; | |
} | |
public async Task<Category?> GetByIdAsync(uint id) | |
{ | |
var client = httpClientFactory.CreateClient(Configuration.HttpClientName); | |
return await client.GetFromJsonAsync<Category>($"v1/categories/{id}") ?? null; | |
} | |
public async Task DeleteAsync(uint id) | |
{ | |
var client = httpClientFactory.CreateClient(Configuration.HttpClientName); | |
await client.DeleteAsync($"v1/categories/{id}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment