TourIAm/TIAMMobileApp/Services/TransferDataService.cs

61 lines
2.1 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;
namespace TIAMMobileApp.Services
{
public class TransferDataService : ITransferDataService
{
private readonly HttpClient http;
public TransferDataService(HttpClient http)
{
this.http = http;
}
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;
}
/// <summary>
/// calls the TransferDataAPI to get the list of destinations
public async Task<TransferDestination[]?> GetDestinationsAsync()
{
var url = $"{Setting.BaseUrl}/{APIUrls.GetTransferDestinations}";
return await http.GetFromJsonAsync<TransferDestination[]>(url);
}
public Task<TransferDestination> GetTransferDestinationbyAddressAsync(string destinationId)
{
throw new NotImplementedException();
}
public async Task<TransferDestination?> GetTransferDestinationbyCoordinatesAsync(string destinationId)
{
var url = $"{Setting.BaseUrl}/{APIUrls.GetTransferDestinationByCoordinates}";
return await http.GetFromJsonAsync<TransferDestination>(url);
}
}
}