From c7a2856a4a0a0bde5e4d3028535f25e642e7c64b Mon Sep 17 00:00:00 2001 From: Alexis DRAI Date: Sat, 25 Feb 2023 15:15:57 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Use=20existing=20service,?= =?UTF-8?q?=20use=20corresponding=20models?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blazor_lab/Components/InventoryGrid.razor.cs | 19 ++++++++----------- blazor_lab/Services/DataApiService.cs | 5 +++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/blazor_lab/Components/InventoryGrid.razor.cs b/blazor_lab/Components/InventoryGrid.razor.cs index 87a879b..8f4f551 100644 --- a/blazor_lab/Components/InventoryGrid.razor.cs +++ b/blazor_lab/Components/InventoryGrid.razor.cs @@ -1,11 +1,6 @@ -using Microsoft.AspNetCore.Components; +using blazor_lab.Services; +using Microsoft.AspNetCore.Components; using Minecraft.Crafting.Api.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Json; -using System.Threading.Tasks; namespace blazor_lab.Components @@ -16,17 +11,19 @@ namespace blazor_lab.Components [Parameter] public List Inventory { get; set; } - public List Items { get; set; } = new List(); + public List Items { get; set; } = new List(); [Inject] - public HttpClient HttpClient { get; set; } + public IConfiguration Config { get; set; } + [Inject] - public IConfiguration Config { get; set; } + private DataApiService dataApiService { get; set; } + protected override async Task OnInitializedAsync() { - Items = await HttpClient.GetFromJsonAsync>($"{Config["CraftingApi:BaseUrl"]}/api/Crafting/all"); + Items = await dataApiService.All(); } public string GetItemImageBase64(string displayName) diff --git a/blazor_lab/Services/DataApiService.cs b/blazor_lab/Services/DataApiService.cs index afc9ecb..4b90f17 100644 --- a/blazor_lab/Services/DataApiService.cs +++ b/blazor_lab/Services/DataApiService.cs @@ -28,6 +28,11 @@ namespace blazor_lab.Services return await _http.GetFromJsonAsync("https://localhost:7234/api/Crafting/count"); } + public async Task> All() + { + return await _http.GetFromJsonAsync>($"https://localhost:7234/api/Crafting/all"); + } + public async Task> List(int currentPage, int pageSize) { return await _http.GetFromJsonAsync>($"https://localhost:7234/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}");