64 lines
2.4 KiB
C#
64 lines
2.4 KiB
C#
using System.Net.Http.Json;
|
|
using TIAM.Entities.TransferDestinations;
|
|
using TIAMWebApp.Shared.Application.Interfaces;
|
|
using TIAMWebApp.Shared.Application.Models;
|
|
using TIAMWebApp.Shared.Application.Models.ClientSide;
|
|
using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels;
|
|
using TIAMWebApp.Shared.Application.Utility;
|
|
|
|
namespace TIAMWebApp.Client.Services
|
|
{
|
|
public class TransferDataService : ITransferDataService
|
|
{
|
|
private readonly HttpClient http;
|
|
private readonly LogToBrowserConsole logToBrowserConsole;
|
|
|
|
public TransferDataService(HttpClient http, LogToBrowserConsole logToBrowserConsole)
|
|
{
|
|
this.http = http;
|
|
this.logToBrowserConsole = logToBrowserConsole;
|
|
}
|
|
|
|
public async Task<TransferDestination[]?> GetDestinationsAsync()
|
|
{
|
|
|
|
var url = $"{Setting.BaseUrl}/{APIUrls.GetTransferDestinations}";
|
|
logToBrowserConsole.LogToBC(url);
|
|
return await http.GetFromJsonAsync<TransferDestination[]>(url);
|
|
}
|
|
|
|
public async Task<TransferDestination?> GetTransferDestinationbyCoordinatesAsync(string destinationId)
|
|
{
|
|
var url = $"{Setting.BaseUrl}/{APIUrls.GetTransferDestinationByCoordinates}";
|
|
return await http.GetFromJsonAsync<TransferDestination>(url);
|
|
}
|
|
|
|
public async Task<TransferDestination?> GetTransferDestinationbyAddressAsync(string destinationId)
|
|
{
|
|
var url = $"{Setting.BaseUrl}/{APIUrls.GetTransferDestinationByAddress}";
|
|
return await http.GetFromJsonAsync<TransferDestination>(url);
|
|
}
|
|
|
|
public async Task<TransferDestination?> CreateTransferDestination(TransferDestinationWizardModel model)
|
|
{
|
|
var url = $"{Setting.BaseUrl}/{APIUrls.CreateTransferDestination}";
|
|
var response = await http.PostAsJsonAsync(url, model);
|
|
|
|
//var result = new WizardProcessorResult();
|
|
|
|
//if (response.IsSuccessStatusCode)
|
|
//{
|
|
// result.IsSucces = true;
|
|
// result.ResultJson = await response.Content.ReadAsStringAsync();
|
|
//}
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
return null;
|
|
|
|
var result = (TransferDestination)(await response.Content.ReadFromJsonAsync(typeof(TransferDestination)))!;
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|