♻️ Use existing service, use corresponding models

pull/2/head
Alexis Drai 2 years ago
parent 4ad36965fa
commit c7a2856a4a

@ -1,11 +1,6 @@
using Microsoft.AspNetCore.Components; using blazor_lab.Services;
using Microsoft.AspNetCore.Components;
using Minecraft.Crafting.Api.Models; 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 namespace blazor_lab.Components
@ -16,17 +11,19 @@ namespace blazor_lab.Components
[Parameter] [Parameter]
public List<InventoryModel> Inventory { get; set; } public List<InventoryModel> Inventory { get; set; }
public List<Item> Items { get; set; } = new List<Item>(); public List<Models.Item> Items { get; set; } = new List<Models.Item>();
[Inject] [Inject]
public HttpClient HttpClient { get; set; } public IConfiguration Config { get; set; }
[Inject] [Inject]
public IConfiguration Config { get; set; } private DataApiService dataApiService { get; set; }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
Items = await HttpClient.GetFromJsonAsync<List<Item>>($"{Config["CraftingApi:BaseUrl"]}/api/Crafting/all"); Items = await dataApiService.All();
} }
public string GetItemImageBase64(string displayName) public string GetItemImageBase64(string displayName)

@ -28,6 +28,11 @@ namespace blazor_lab.Services
return await _http.GetFromJsonAsync<int>("https://localhost:7234/api/Crafting/count"); return await _http.GetFromJsonAsync<int>("https://localhost:7234/api/Crafting/count");
} }
public async Task<List<Item>> All()
{
return await _http.GetFromJsonAsync<List<Item>>($"https://localhost:7234/api/Crafting/all");
}
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://localhost:7234/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}"); return await _http.GetFromJsonAsync<List<Item>>($"https://localhost:7234/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}");

Loading…
Cancel
Save