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 _logger; public ModeusApiClient(HttpClient http, IConfiguration config, ILogger logger) { _http = http; _logger = logger; var apiKey = config["ModeusApi:ApiKey"]; if (!string.IsNullOrEmpty(apiKey)) _http.DefaultRequestHeaders.Add("X-API-Key", apiKey); } public async Task 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() ?? new(new()); } public async Task SearchRoomsAsync() { var response = await _http.PostAsJsonAsync("/api/proxy/rooms/search", new { }); response.EnsureSuccessStatusCode(); return await response.Content.ReadFromJsonAsync() ?? new(new()); } public async Task> SearchEmployeeAsync(string fullname) { var response = await _http.GetFromJsonAsync>( $"/api/schedule/searchemployee?fullname={Uri.EscapeDataString(fullname)}"); return response ?? new(); } }