add doc for DataApiService

master
remrem 2 years ago
parent 7a16a683f3
commit 763b94cb11

@ -3,16 +3,27 @@ using Blazor.Factories;
using Blazor.Models; using Blazor.Models;
namespace Blazor.Services namespace Blazor.Services
{ {
/// <summary>
/// Service for interacting with a data API.
/// </summary>
public class DataApiService : IDataService public class DataApiService : IDataService
{ {
private readonly HttpClient _http; private readonly HttpClient _http;
/// <summary>
/// Constructor for DataApiService.
/// </summary>
/// <param name="http">HttpClient for making API requests.</param>
public DataApiService(HttpClient http) public DataApiService(HttpClient http)
{ {
_http = http; _http = http;
} }
/// <summary>
/// Add a new item to the API.
/// </summary>
/// <param name="model">Model containing data for the new item.</param>
public async Task Add(ItemModel model) public async Task Add(ItemModel model)
{ {
// Get the item // Get the item
@ -22,26 +33,50 @@ namespace Blazor.Services
await _http.PostAsJsonAsync("https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/", item); await _http.PostAsJsonAsync("https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/", item);
} }
/// <summary>
/// Get the number of items in the API.
/// </summary>
/// <returns>Task representing the asynchronous operation, returning the number of items.</returns>
public async Task<int> Count() public async Task<int> Count()
{ {
return await _http.GetFromJsonAsync<int>("https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/count"); return await _http.GetFromJsonAsync<int>("https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/count");
} }
/// <summary>
/// Get a list of items from the API, paginated.
/// </summary>
/// <param name="currentPage">The current page number.</param>
/// <param name="pageSize">The number of items per page.</param>
/// <returns>Task representing the asynchronous operation, returning a list of items.</returns>
public async Task<List<Item>> List(int currentPage, int pageSize) public async Task<List<Item>> List(int currentPage, int pageSize)
{ {
return await _http.GetFromJsonAsync<List<Item>>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}"); return await _http.GetFromJsonAsync<List<Item>>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}");
} }
/// <summary>
/// Get a list of all items from the API.
/// </summary>
/// <returns>Task representing the asynchronous operation, returning a list of items.</returns>
public async Task<List<Item>> getAll() public async Task<List<Item>> getAll()
{ {
return await _http.GetFromJsonAsync<List<Item>>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/all"); return await _http.GetFromJsonAsync<List<Item>>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/all");
} }
/// <summary>
/// Get a single item from the API by its ID.
/// </summary>
/// <param name="id">The ID of the item to retrieve.</param>
/// <returns>Task representing the asynchronous operation, returning the item with the specified ID.</returns>
public async Task<Item> GetById(int id) public async Task<Item> GetById(int id)
{ {
return await _http.GetFromJsonAsync<Item>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}"); return await _http.GetFromJsonAsync<Item>($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}");
} }
/// <summary>
/// Update an existing item in the API.
/// </summary>
/// <param name="id">The ID of the item to update.</param>
/// <param name="model">Model containing the updated data for the item.</param>
public async Task Update(int id, ItemModel model) public async Task Update(int id, ItemModel model)
{ {
// Get the item // Get the item
@ -50,11 +85,19 @@ namespace Blazor.Services
await _http.PutAsJsonAsync($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}", item); await _http.PutAsJsonAsync($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}", item);
} }
/// <summary>
/// Delete an existing item from the API.
/// </summary>
/// <param name="id">The ID of the item to delete.</param>
public async Task Delete(int id) public async Task Delete(int id)
{ {
await _http.DeleteAsync($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}"); await _http.DeleteAsync($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}");
} }
/// <summary>
/// Get a list of crafting recipes from the API.
/// </summary>
/// <returns>Task representing the asynchronous operation, returning a list of crafting recipes.</returns>
public async Task<List<CraftingRecipe>> GetRecipes() public async Task<List<CraftingRecipe>> GetRecipes()
{ {
return await _http.GetFromJsonAsync<List<CraftingRecipe>>("https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/recipe"); return await _http.GetFromJsonAsync<List<CraftingRecipe>>("https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/recipe");

Loading…
Cancel
Save