118 lines
No EOL
4.1 KiB
C#
118 lines
No EOL
4.1 KiB
C#
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.Extensions.Options;
|
|
using Wonky.Entity.Configuration;
|
|
using Wonky.Entity.DTO;
|
|
|
|
namespace Wonky.Client.HttpRepository;
|
|
|
|
public class SystemLabelsRepository : ISystemLabelsRepository
|
|
{
|
|
private readonly JsonSerializerOptions? _options = new JsonSerializerOptions
|
|
{
|
|
PropertyNameCaseInsensitive = true
|
|
};
|
|
|
|
private readonly NavigationManager _navigation;
|
|
private ILogger<SystemLabelsRepository> _logger;
|
|
private readonly HttpClient _client;
|
|
private readonly ApiConfig _api;
|
|
|
|
public SystemLabelsRepository(HttpClient client, ILogger<SystemLabelsRepository> logger,
|
|
NavigationManager navigation, IOptions<ApiConfig> configuration)
|
|
{
|
|
_client = client;
|
|
_logger = logger;
|
|
_navigation = navigation;
|
|
_api = configuration.Value;
|
|
}
|
|
|
|
public async Task<KrvEmergencyLabels> GetKrvEmergencyLabels()
|
|
{
|
|
var result = await _client.GetFromJsonAsync<KrvEmergencyLabels>($"{_api.SystemLabels}/emergency", _options);
|
|
return result ?? new KrvEmergencyLabels();
|
|
}
|
|
|
|
public async Task UpdateKrvEmergencyLabels(KrvEmergencyLabels model)
|
|
{
|
|
await _client.PutAsJsonAsync($"{_api.SystemLabels}/emergency", model, _options);
|
|
}
|
|
|
|
public async Task<KrvFirstAidLabels> GetKrvFirstAidLabels()
|
|
{
|
|
var result = await _client.GetFromJsonAsync<KrvFirstAidLabels>($"{_api.SystemLabels}/firstaid", _options);
|
|
return result ?? new KrvFirstAidLabels();
|
|
}
|
|
|
|
public async Task UpdateKrvFirstAidLabels(KrvFirstAidLabels model)
|
|
{
|
|
await _client.PutAsJsonAsync($"{_api.SystemLabels}/firstaid", model, _options);
|
|
}
|
|
|
|
public async Task<KrvKapvLabels> GetKrvKapvLabels()
|
|
{
|
|
var result = await _client.GetFromJsonAsync<KrvKapvLabels>($"{_api.SystemLabels}/kapv", _options);
|
|
return result ?? new KrvKapvLabels();
|
|
}
|
|
|
|
public async Task UpdateKrvKapvLabels(KrvKapvLabels model)
|
|
{
|
|
await _client.PutAsJsonAsync($"{_api.SystemLabels}/kapv", model, _options);
|
|
}
|
|
|
|
public async Task<KrvProductLabels> GetKrvProductLabels()
|
|
{
|
|
var result = await _client.GetFromJsonAsync<KrvProductLabels>($"{_api.SystemLabels}/product", _options);
|
|
return result ?? new KrvProductLabels();
|
|
}
|
|
|
|
public async Task UpdateKrvProductLabels(KrvProductLabels model)
|
|
{
|
|
await _client.PutAsJsonAsync($"{_api.SystemLabels}/product", model, _options);
|
|
}
|
|
|
|
public async Task<KrvProtectionLabels> GetKrvProtectionLabels()
|
|
{
|
|
var result = await _client.GetFromJsonAsync<KrvProtectionLabels>($"{_api.SystemLabels}/protection", _options);
|
|
return result ?? new KrvProtectionLabels();
|
|
}
|
|
|
|
public async Task UpdateKrvProtectionLabels(KrvProtectionLabels model)
|
|
{
|
|
await _client.PutAsJsonAsync($"{_api.SystemLabels}/protection", model, _options);
|
|
}
|
|
|
|
public async Task<KrvSignatureLabels> GetKrvSignatureLabels()
|
|
{
|
|
var result = await _client.GetFromJsonAsync<KrvSignatureLabels>($"{_api.SystemLabels}/signature", _options);
|
|
return result ?? new KrvSignatureLabels();
|
|
}
|
|
|
|
public async Task UpdateKrvSignatureLabels(KrvSignatureLabels model)
|
|
{
|
|
await _client.PutAsJsonAsync($"{_api.SystemLabels}/signature", model, _options);
|
|
}
|
|
|
|
public async Task<KrvWasteLabels> GetKrvWasteLabels()
|
|
{
|
|
var result = await _client.GetFromJsonAsync<KrvWasteLabels>($"{_api.SystemLabels}/waste", _options);
|
|
return result ?? new KrvWasteLabels();
|
|
}
|
|
|
|
public async Task UpdateKrvWasteLabels(KrvWasteLabels model)
|
|
{
|
|
await _client.PutAsJsonAsync($"{_api.SystemLabels}/waste", model, _options);
|
|
}
|
|
|
|
public async Task<SystemQuoteLabels> GetSystemQuoteLabels()
|
|
{
|
|
var result = await _client.GetFromJsonAsync<SystemQuoteLabels>($"{_api.SystemLabels}/quote", _options);
|
|
return result ?? new SystemQuoteLabels();
|
|
}
|
|
|
|
public async Task UpdateSystemQuoteLabels(SystemQuoteLabels model)
|
|
{
|
|
await _client.PutAsJsonAsync($"{_api.SystemLabels}/quote", model, _options);
|
|
}
|
|
} |