eShopOnContainers/src/Web/WebMVC/Services/LocationService.cs
hfz-r 85aea20046
Fix for Campaigns exception and SignalR 401 Unauthorized (#1374)
* update API Gateway - /locations-api/ @ webmarketing/envoy.yaml

* updated signalr services

- envoy: webmarketingapigw
- latest client: webmvc
- service hub: ordering-signalrhub

Co-authored-by: hfz-r <hafiz.roslan@hartalega.com.my>
2020-08-27 15:27:18 +05:30

39 lines
1.4 KiB
C#

using Microsoft.eShopOnContainers.WebMVC;
using Microsoft.eShopOnContainers.WebMVC.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System.Net.Http;
using System.Threading.Tasks;
using WebMVC.Infrastructure;
using WebMVC.Services.ModelDTOs;
namespace WebMVC.Services
{
public class LocationService : ILocationService
{
private readonly IOptions<AppSettings> _settings;
private readonly HttpClient _httpClient;
private readonly ILogger<CampaignService> _logger;
private readonly string _remoteServiceBaseUrl;
public LocationService(HttpClient httpClient, IOptions<AppSettings> settings, ILogger<CampaignService> logger)
{
_httpClient = httpClient;
_settings = settings;
_logger = logger;
_remoteServiceBaseUrl = $"{_settings.Value.MarketingUrl}/l/api/v1/locations/";
}
public async Task CreateOrUpdateUserLocation(LocationDTO location)
{
var uri = API.Locations.CreateOrUpdateUserLocation(_remoteServiceBaseUrl);
var locationContent = new StringContent(JsonConvert.SerializeObject(location), System.Text.Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync(uri, locationContent);
response.EnsureSuccessStatusCode();
}
}
}