3 Commits

Author SHA1 Message Date
Samuele Locatelli 018733e918 Merge branch 'develop' into WasmTest 2026-05-06 11:17:05 +02:00
Samuele E. Locatelli (W11-AI) 18579f792a Merge branch 'develop' of https://gitlab.steamware.net/egalware-web/gest/gpw_next into develop 2026-03-31 18:25:03 +02:00
Samuele E. Locatelli (W11-AI) f9e40a90de Implementazione interfaccia servizi CoreSmart server e x WASM, bozza metodi x WASM http calls 2026-03-31 18:24:59 +02:00
3 changed files with 471 additions and 1 deletions
@@ -0,0 +1,341 @@
using GPW.CORE.Data.DbModels;
using GPW.CORE.Data.DTO;
using GPW.CORE.Smart8.Shared.Services;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
namespace GPW.CORE.Smart8.Client.Services
{
/// <summary>
/// Implementazione di ISmartRepository per il client WASM.
/// Effettua chiamate HTTP agli API endpoint del server.
/// </summary>
public class SmartRepositoryApiClient : ISmartRepository
{
private readonly HttpClient _httpClient;
private readonly JsonSerializerSettings _jsonSettings = new()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
public SmartRepositoryApiClient(HttpClient httpClient)
{
_httpClient = httpClient;
}
#region Anagrafiche Chiave
public async Task<List<AnagKeyValueModel>?> AKVList()
{
var response = await _httpClient.GetAsync("api/smart/akvlist");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<AnagKeyValueModel>>(content);
}
public async Task<List<AnagClientiModel>> AnagClientiAll()
{
var response = await _httpClient.GetAsync("api/smart/anagclientiall");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<AnagClientiModel>>(content) ?? new List<AnagClientiModel>();
}
public async Task<List<AnagFasiModel>> AnagFasiAll()
{
var response = await _httpClient.GetAsync("api/smart/anagfasiall");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<AnagFasiModel>>(content) ?? new List<AnagFasiModel>();
}
public async Task<AnagFasiModel?> AnagFasiByKey(int idxFase)
{
var response = await _httpClient.GetAsync($"api/smart/anagfasibykey?idxFase={idxFase}");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<AnagFasiModel>(content);
}
public async Task<List<AnagFasiModel>?> AnagFasiByProj(int idxProj)
{
var response = await _httpClient.GetAsync($"api/smart/anagfasibyproj?idxProj={idxProj}");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<AnagFasiModel>>(content);
}
public async Task<List<AnagGiustModel>?> AnagGiust()
{
var response = await _httpClient.GetAsync("api/smart/anaggiust");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<AnagGiustModel>>(content);
}
public async Task<List<AnagGruppiModel>> AnagGruppiUser(int idxDipendente)
{
var response = await _httpClient.GetAsync($"api/smart/anaggruppiuser?idxDipendente={idxDipendente}");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<AnagGruppiModel>>(content) ?? new List<AnagGruppiModel>();
}
public async Task<List<AnagOrariModel>> AnagOrarioAll()
{
var response = await _httpClient.GetAsync("api/smart/anagorarioall");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<AnagOrariModel>>(content) ?? new List<AnagOrariModel>();
}
public async Task<AnagOrariModel> AnagOrarioByDip(int idxDip)
{
var response = await _httpClient.GetAsync($"api/smart/anagorariobydip?idxDip={idxDip}");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<AnagOrariModel>(content) ?? new AnagOrariModel();
}
#endregion
#region Progetti e Fasi
public async Task<List<AnagProgettiModel>> AnagProjAll()
{
var response = await _httpClient.GetAsync("api/smart/anagprojall");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<AnagProgettiModel>>(content) ?? new List<AnagProgettiModel>();
}
#endregion
#region Calendario
public async Task<List<CalFesteFerieModel>> CalFestFeriePeriodo(DateTime dtStart, DateTime dtEnd)
{
var response = await _httpClient.GetAsync($"api/smart/calfestferieperiodo?dtStart={dtStart:yyyy-MM-dd}&dtEnd={dtEnd:yyyy-MM-dd}");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<CalFesteFerieModel>>(content) ?? new List<CalFesteFerieModel>();
}
#endregion
#region Controlli VC19
public async Task<List<CheckVc19Model>> CheckVC19List(int idxDipendente, DateTime dtInizio, DateTime dtFine)
{
var response = await _httpClient.GetAsync($"api/smart/checkvc19list?idxDipendente={idxDipendente}&dtInizio={dtInizio:yyyy-MM-dd}&dtFine={dtFine:yyyy-MM-dd}");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<CheckVc19Model>>(content) ?? new List<CheckVc19Model>();
}
#endregion
#region Configurazione
public async Task<List<ConfigModel>> ConfigGetAll()
{
var response = await _httpClient.GetAsync("api/smart/configgetall");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<ConfigModel>>(content) ?? new List<ConfigModel>();
}
public async Task<ConfigModel?> ConfigGetKey(string chiave)
{
var response = await _httpClient.GetAsync($"api/smart/configgetkey?chiave={Uri.EscapeDataString(chiave)}");
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
return null;
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<ConfigModel>(content);
}
#endregion
#region Timbrature
public async Task<bool> TimbratureUpdate(TimbratureModel record)
{
var response = await _httpClient.PostAsJsonAsync("api/smart/timbratura/update", record);
return response.IsSuccessStatusCode;
}
public async Task<List<TimbratureModel>> TimbratureDay(DateTime day, int idxDipendente)
{
var response = await _httpClient.GetAsync($"api/smart/timbraturaday?day={day:yyyy-MM-dd}&idxDipendente={idxDipendente}");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<TimbratureModel>>(content) ?? new List<TimbratureModel>();
}
public async Task<bool> TimbratureInsRichiesta(TimbratureModel record)
{
var response = await _httpClient.PostAsJsonAsync("api/smart/timbratura/insrichiesta", record);
return response.IsSuccessStatusCode;
}
public async Task<TimbratureModel> RegAttLastByDip(int IdxDipendente, bool onlyActive)
{
var response = await _httpClient.GetAsync($"api/smart/regattlastbydip?IdxDipendente={IdxDipendente}&onlyActive={onlyActive}");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<TimbratureModel>(content) ?? new TimbratureModel();
}
#endregion
#region Dipendenti e Device
public async Task<List<Dipendenti2RuoliModel>> Dip2RuoliGetAll()
{
var response = await _httpClient.GetAsync("api/smart/dip2ruoliall");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<Dipendenti2RuoliModel>>(content) ?? new List<Dipendenti2RuoliModel>();
}
public async Task<List<DipendentiModel>> DipendentiGetAll()
{
var response = await _httpClient.GetAsync("api/smart/dipendentigetall");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<DipendentiModel>>(content) ?? new List<DipendentiModel>();
}
public async Task<bool> DipendentiUpdate(DipendentiModel currItem)
{
var response = await _httpClient.PutAsJsonAsync("api/smart/dipendentiupdate", currItem);
return response.IsSuccessStatusCode;
}
public async Task<AnagDeviceModel?> DeviceBySecret(string devSecret)
{
var response = await _httpClient.GetAsync($"api/smart/devicebysecret?devSecret={Uri.EscapeDataString(devSecret)}");
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
return null;
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<AnagDeviceModel>(content);
}
public async Task<bool> DeviceInsert(AnagDeviceModel newRecord)
{
var response = await _httpClient.PostAsJsonAsync("api/smart/deviceinsert", newRecord);
return response.IsSuccessStatusCode;
}
#endregion
#region Attività (RegAttivita)
public async Task<bool> RegAttDelete(RegAttivitaModel currItem)
{
var response = await _httpClient.DeleteAsJsonAsync("api/smart/regattdelete", currItem);
return response.IsSuccessStatusCode;
}
public async Task<bool> RegAttUpdate(RegAttivitaModel currItem)
{
var response = await _httpClient.PutAsJsonAsync("api/smart/regattupdate", currItem);
return response.IsSuccessStatusCode;
}
public async Task<List<DailyDataDTO>> DailyDetails(int idxDipendente, DateTime dtInizio, DateTime dtFine)
{
var response = await _httpClient.GetAsync($"api/smart/dailydetails?idxDipendente={idxDipendente}&dtInizio={dtInizio:yyyy-MM-dd}&dtFine={dtFine:yyyy-MM-dd}");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<DailyDataDTO>>(content) ?? new List<DailyDataDTO>();
}
#endregion
#region Malattie (RegMalattie)
public async Task<bool> RegMalattieDelete(RegMalattieModel currItem)
{
var response = await _httpClient.DeleteAsJsonAsync("api/smart/regmalattiedelete", currItem);
return response.IsSuccessStatusCode;
}
public async Task<List<RegMalattieModel>> RegMalattieGetAll(int maxRecord)
{
var response = await _httpClient.GetAsync($"api/smart/regmalattiegetall?maxRecord={maxRecord}");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<RegMalattieModel>>(content) ?? new List<RegMalattieModel>();
}
public async Task<List<RegMalattieModel>> RegMalattieGetByDip(int idxDipendente, int maxRecord)
{
var response = await _httpClient.GetAsync($"api/smart/regmalattiegetbydip?idxDipendente={idxDipendente}&maxRecord={maxRecord}");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<RegMalattieModel>>(content) ?? new List<RegMalattieModel>();
}
public async Task<bool> RegMalattieUpsert(RegMalattieModel currItem)
{
var response = await _httpClient.PostAsJsonAsync("api/smart/regmalattieupsert", currItem);
return response.IsSuccessStatusCode;
}
#endregion
#region Richieste (RegRichieste)
public async Task<bool> RegRichiesteDelete(RegRichiesteModel currItem)
{
var response = await _httpClient.DeleteAsJsonAsync("api/smart/regrichiestedelete", currItem);
return response.IsSuccessStatusCode;
}
public async Task<List<RegRichiesteModel>> RegRichiesteGetByDip(int idxDipendente, DateTime dtFrom, DateTime dtTo)
{
var response = await _httpClient.GetAsync($"api/smart/regrichiestegetbydip?idxDipendente={idxDipendente}&dtFrom={dtFrom:yyyy-MM-dd}&dtTo={dtTo:yyyy-MM-dd}");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<List<RegRichiesteModel>>(content) ?? new List<RegRichiesteModel>();
}
public async Task<bool> RegRichiesteUpsert(RegRichiesteModel currItem)
{
var response = await _httpClient.PostAsJsonAsync("api/smart/regrichiesteupsert", currItem);
return response.IsSuccessStatusCode;
}
#endregion
#region Cache e Utility
public async Task<bool> FlushRedisCache()
{
var response = await _httpClient.PostAsync("api/cache/flush", null);
return response.IsSuccessStatusCode;
}
public string DecriptData(string encData)
{
throw new NotImplementedException("DecriptData non supportata dal client WASM. Usare il server per decrittazione.");
}
public string EncriptData(string rawData)
{
throw new NotImplementedException("EncriptData non supportata dal client WASM. Usare il server per crittografia.");
}
#endregion
public void Dispose()
{
// HttpClient viene gestito da Dependency Injection, non disporrere qui
}
}
}
@@ -0,0 +1,128 @@
using GPW.CORE.Data.DbModels;
using GPW.CORE.Data.DTO;
namespace GPW.CORE.Smart8.Shared.Services
{
/// <summary>
/// Repository interface per operazioni di business condivise tra Server e WASM Client.
/// Implementata da CoreSmartDataService (Server) e SmartRepositoryApiClient (WASM).
/// </summary>
public interface ISmartRepository : IDisposable
{
#region Anagrafiche Chiave
Task<List<AnagKeyValueModel>?> AKVList();
Task<List<AnagClientiModel>> AnagClientiAll();
Task<List<AnagFasiModel>> AnagFasiAll();
Task<AnagFasiModel?> AnagFasiByKey(int idxFase);
Task<List<AnagFasiModel>?> AnagFasiByProj(int idxProj);
Task<List<AnagGiustModel>?> AnagGiust();
Task<List<AnagGruppiModel>> AnagGruppiUser(int idxDipendente);
Task<List<AnagOrariModel>> AnagOrarioAll();
Task<AnagOrariModel> AnagOrarioByDip(int idxDip);
#endregion
#region Progetti e Fasi
Task<List<AnagProgettiModel>> AnagProjAll();
#endregion
#region Calendario
Task<List<CalFesteFerieModel>> CalFestFeriePeriodo(DateTime dtStart, DateTime dtEnd);
#endregion
#region Controlli VC19
Task<List<CheckVc19Model>> CheckVC19List(int idxDipendente, DateTime dtInizio, DateTime dtFine);
#endregion
#region Configurazione
Task<List<ConfigModel>> ConfigGetAll();
Task<ConfigModel?> ConfigGetKey(string chiave);
#endregion
#region Timbrature
Task<bool> TimbratureUpdate(TimbratureModel record);
Task<List<TimbratureModel>> TimbratureDay(DateTime day, int idxDipendente);
Task<bool> TimbratureInsRichiesta(TimbratureModel record);
Task<TimbratureModel> RegAttLastByDip(int IdxDipendente, bool onlyActive);
#endregion
#region Dipendenti e Device
Task<List<Dipendenti2RuoliModel>> Dip2RuoliGetAll();
Task<List<DipendentiModel>> DipendentiGetAll();
Task<bool> DipendentiUpdate(DipendentiModel currItem);
Task<AnagDeviceModel?> DeviceBySecret(string devSecret);
Task<bool> DeviceInsert(AnagDeviceModel newRecord);
#endregion
#region Attività (RegAttivita)
Task<bool> RegAttDelete(RegAttivitaModel currItem);
Task<bool> RegAttUpdate(RegAttivitaModel currItem);
Task<List<DailyDataDTO>> DailyDetails(int idxDipendente, DateTime dtInizio, DateTime dtFine);
#endregion
#region Malattie (RegMalattie)
Task<bool> RegMalattieDelete(RegMalattieModel currItem);
Task<List<RegMalattieModel>> RegMalattieGetAll(int maxRecord);
Task<List<RegMalattieModel>> RegMalattieGetByDip(int idxDipendente, int maxRecord);
Task<bool> RegMalattieUpsert(RegMalattieModel currItem);
#endregion
#region Richieste (RegRichieste)
Task<bool> RegRichiesteDelete(RegRichiesteModel currItem);
Task<List<RegRichiesteModel>> RegRichiesteGetByDip(int idxDipendente, DateTime dtFrom, DateTime dtTo);
Task<bool> RegRichiesteUpsert(RegRichiesteModel currItem);
#endregion
#region Cache e Utility
Task<bool> FlushRedisCache();
string DecriptData(string encData);
string EncriptData(string rawData);
#endregion
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
using GPW.CORE.Data;
using GPW.CORE.Data.DbModels;
using GPW.CORE.Data.DTO;
using GPW.CORE.Smart8.Shared.Services;
using Microsoft.AspNetCore.Identity.UI.Services;
using Newtonsoft.Json;
using NLog;
@@ -11,7 +12,7 @@ using System.Text;
namespace GPW.CORE.Smart8.Data
{
public class CoreSmartDataService : IDisposable
public class CoreSmartDataService : ISmartRepository, IDisposable
{
#region Public Fields