Добавил слой Infrastructure
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using System.Net.Http.Json;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using UniVerse.Application.DTOs.Sync;
|
||||
using UniVerse.Application.Interfaces;
|
||||
|
||||
namespace UniVerse.Infrastructure.ExternalServices;
|
||||
|
||||
public class ModeusApiClient : IModeusApiClient
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
private readonly ILogger<ModeusApiClient> _logger;
|
||||
|
||||
public ModeusApiClient(HttpClient http, IConfiguration config, ILogger<ModeusApiClient> logger)
|
||||
{
|
||||
_http = http; _logger = logger;
|
||||
var apiKey = config["ModeusApi:ApiKey"];
|
||||
if (!string.IsNullOrEmpty(apiKey))
|
||||
_http.DefaultRequestHeaders.Add("X-API-Key", apiKey);
|
||||
}
|
||||
|
||||
public async Task<ModeusEventsResponse> SearchEventsAsync(SyncScheduleRequest request)
|
||||
{
|
||||
var body = new { specialtyCode = request.SpecialtyCode, timeMin = request.TimeMin, timeMax = request.TimeMax, typeId = request.TypeId };
|
||||
var response = await _http.PostAsJsonAsync("/api/proxy/events/search", body);
|
||||
response.EnsureSuccessStatusCode();
|
||||
return await response.Content.ReadFromJsonAsync<ModeusEventsResponse>() ?? new(new());
|
||||
}
|
||||
|
||||
public async Task<ModeusRoomsResponse> SearchRoomsAsync()
|
||||
{
|
||||
var response = await _http.PostAsJsonAsync("/api/proxy/rooms/search", new { });
|
||||
response.EnsureSuccessStatusCode();
|
||||
return await response.Content.ReadFromJsonAsync<ModeusRoomsResponse>() ?? new(new());
|
||||
}
|
||||
|
||||
public async Task<List<ModeusEmployee>> SearchEmployeeAsync(string fullname)
|
||||
{
|
||||
var response = await _http.GetFromJsonAsync<List<ModeusEmployee>>(
|
||||
$"/api/schedule/searchemployee?fullname={Uri.EscapeDataString(fullname)}");
|
||||
return response ?? new();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user