using CityInfo.WEB.Models; using System.Net.Http.Json; namespace CityInfo.WEB.Services { public class PointOfInterestDataService : IPointOfInterestDataService { private readonly HttpClient _httpClient; private readonly ILogger _logger; public PointOfInterestDataService( HttpClient httpClient, ILogger logger) { _httpClient = httpClient; _logger = logger; } public Task CreatePointOfInterest(int cityId, PointOfInterest pointOfInterest) { throw new NotImplementedException(); } public Task DeletePointOfInterest(int cityId, int pointOfInterestId) { throw new NotImplementedException(); } public async Task GetPointOfInterest(int cityId, int pointOfInterestId) { try { var response = await _httpClient.GetAsync($"/api/cities/{cityId}/pointsofinterest/{pointOfInterestId}"); if (response.IsSuccessStatusCode) { return await response.Content.ReadFromJsonAsync(); } if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { return null; } _logger.LogWarning($"Erreur HTTP {response.StatusCode} lors du chargement du point d'intéret {pointOfInterestId}", response.StatusCode, cityId); return null; } catch (Exception ex) { _logger.LogError(ex, $"Erreur lors de la récupération du point d'intéret {pointOfInterestId}", cityId); return null; } } public async Task> GetPointsOfInterest(int cityId) { try { return await _httpClient.GetFromJsonAsync>($"api/cities/{cityId}/pointsofinterest/") ?? Enumerable.Empty(); } catch (Exception ex) { _logger.LogError(ex, "Erreur lors de la récupération des Points d'intérets."); return Enumerable.Empty(); } } public Task UpdatePointOfInterest(int cityId, PointOfInterest pointOfInterest) { throw new NotImplementedException(); } } }