39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
|
using System.Net.Http.Json;
|
||
|
using Demo.Domain.Models;
|
||
|
using presence_client.DTO;
|
||
|
using Microsoft.Extensions.Logging;
|
||
|
using presence_client.ApiClients.Interfaces;
|
||
|
|
||
|
namespace presence_client.ApiClients;
|
||
|
|
||
|
public class PresenceApiClient : BaseApiClient, IPresenceApiClient
|
||
|
{
|
||
|
private const string BasePath = "api/Presence";
|
||
|
|
||
|
public PresenceApiClient(IHttpClientFactory httpClientFactory, ILogger<PresenceApiClient> logger)
|
||
|
: base(httpClientFactory, logger)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
public async Task<PresenceResponse?> GetPresenceAsync(int groupId, string startDate, string endDate)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var url = $"{BasePath}?groupID={groupId}&start={startDate}&end={endDate}";
|
||
|
_logger.LogInformation($"Sending request to: {url}");
|
||
|
|
||
|
return await _httpClient.GetFromJsonAsync<PresenceResponse>(url);
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
_logger.LogError(ex, "GetPresenceAsync error");
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public async Task<bool> DeletePresenceRecords(string date, int lessonNumder, Guid userGuid)
|
||
|
{
|
||
|
return await DeleteAsync($"{BasePath}/records/?date={date}&lessonNumber={lessonNumder}&userGuid={userGuid}");
|
||
|
}
|
||
|
}
|