WASM Mode activated
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using System.Net.Http.Json;
|
||||
using timetracker.Shared;
|
||||
|
||||
namespace timetracker.Client.Services;
|
||||
|
||||
public class ClientHolidayService : IHolidayService
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
|
||||
public ClientHolidayService(HttpClient http)
|
||||
{
|
||||
_http = http;
|
||||
}
|
||||
|
||||
public async Task<List<PublicHoliday>> GetHolidaysAsync(int year, string? stateCode = null)
|
||||
{
|
||||
var url = $"api/holidays?year={year}";
|
||||
if (!string.IsNullOrEmpty(stateCode))
|
||||
{
|
||||
url += $"&stateCode={stateCode}";
|
||||
}
|
||||
return await _http.GetFromJsonAsync<List<PublicHoliday>>(url) ?? [];
|
||||
}
|
||||
|
||||
public async Task<(bool Success, string Message)> FetchAndStoreAsync(int year)
|
||||
{
|
||||
var response = await _http.PostAsync($"api/holidays/fetch/{year}", null);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var result = await response.Content.ReadFromJsonAsync<FetchResponse>();
|
||||
if (result != null)
|
||||
{
|
||||
return (result.Success, result.Message);
|
||||
}
|
||||
}
|
||||
return (false, "Fehler beim Abrufen der Feiertage.");
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(int id)
|
||||
{
|
||||
await _http.DeleteAsync($"api/holidays/{id}");
|
||||
}
|
||||
|
||||
private class FetchResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string Message { get; set; } = "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user