Switch to local api, still have error
continuous-integration/drone/push Build is failing Details

Projet
Dorian HODIN 2 years ago
parent 279d5ed734
commit 580778c86f

Binary file not shown.

Binary file not shown.

@ -51,9 +51,16 @@ namespace ProjetBlazor.Components
public IModalService Modal { get; set; }
public object Action { get; internal set; }
public ItemsList()
{
Actions = new ObservableCollection<ActionInInventory>();
Actions.CollectionChanged += OnActionsCollectionChanged;
}
protected override async Task OnInitializedAsync()
{
items = await DataService.getAll();
items = await DataService.GetAll();
totalItem = await DataService.Count();
await base.OnInitializedAsync();
}

@ -6,6 +6,7 @@ using ProjetBlazor.Services;
using Blazored.Modal;
using Microsoft.AspNetCore.Localization;
using System.Globalization;
using Blazor.Services;
using Microsoft.Extensions.Options;
var builder = WebApplication.CreateBuilder(args);

@ -1,9 +1,15 @@
using ProjetBlazor.Components;
using ProjetBlazor.Models;
using ProjetBlazor.Factories;
using ProjetBlazor.Models;
using ProjetBlazor.Services;
namespace ProjetBlazor.Services
namespace Blazor.Services
{
/// <summary>
/// Service for interacting with a data API.
/// </summary>
public class DataApiService : IDataService
{
private readonly HttpClient _http;
@ -17,26 +23,13 @@ namespace ProjetBlazor.Services
_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)
{
// Get the item
var item = ItemFactory.Create(model);
// Save the data
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()
{
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://localhost:7234/api/Crafting/count");
}
/// <summary>
@ -54,9 +47,9 @@ namespace ProjetBlazor.Services
/// 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://localhost:7234/api/Crafting/all");
}
/// <summary>
@ -68,27 +61,5 @@ namespace ProjetBlazor.Services
{
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)
{
// Get the item
var item = ItemFactory.Create(model);
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)
{
await _http.DeleteAsync($"https://codefirst.iut.uca.fr/containers/container-blazor-web-api-marcchevaldonne/api/Crafting/{id}");
}
}
}

@ -5,18 +5,13 @@ namespace ProjetBlazor.Services
{
public interface IDataService
{
Task Add(ItemModel model);
Task<int> Count();
Task<List<Item>> List(int currentPage, int pageSize);
Task<Item> GetById(int id);
Task<List<Item>> getAll();
Task Update(int id, ItemModel model);
Task<List<Item>> GetAll();
Task Delete(int id);
}
}

Loading…
Cancel
Save