60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using System.Net.Http;
|
|
using System.Net.Http.Json;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Configuration;
|
|
using AccessQueueService.Models;
|
|
using AccessQueueService.Services;
|
|
|
|
namespace AccessQueuePlayground.Services
|
|
{
|
|
public class AccessQueueApiService : IAccessService
|
|
{
|
|
private readonly HttpClient _httpClient;
|
|
private readonly string _serviceUrl;
|
|
|
|
public AccessQueueStatus Status => throw new NotImplementedException();
|
|
|
|
public AccessQueueApiService(HttpClient httpClient, IConfiguration config)
|
|
{
|
|
_httpClient = httpClient;
|
|
_serviceUrl = config["AccessQueuePlayground:ServiceUrl"]?.TrimEnd('/') ?? "https://localhost:7291";
|
|
}
|
|
|
|
public async Task<AccessResponse> RequestAccess(string userId)
|
|
{
|
|
return await _httpClient.GetFromJsonAsync<AccessResponse>($"{_serviceUrl}/access/{userId}");
|
|
}
|
|
|
|
public async Task<bool> RevokeAccess(string userId)
|
|
{
|
|
var response = await _httpClient.DeleteAsync($"{_serviceUrl}/access/{userId}");
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var result = await response.Content.ReadFromJsonAsync<bool>();
|
|
return result;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public Task<int> DeleteExpiredTickets()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public AccessQueueConfig GetConfiguration()
|
|
{
|
|
return _httpClient.GetFromJsonAsync<AccessQueueConfig>($"{_serviceUrl}/config").Result;
|
|
}
|
|
|
|
public void UpdateConfiguration(AccessQueueConfig config)
|
|
{
|
|
_ = _httpClient.PostAsJsonAsync($"{_serviceUrl}/config", config).Result;
|
|
}
|
|
|
|
public void PatchConfiguration(AccessQueueConfig partialConfig)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|