using System; using System.Collections.Generic; using System.Threading.Tasks; namespace Marechai.App.Services; /// /// Service for fetching and managing news from the Marechai API /// public class NewsService { private readonly ApiClient _apiClient; private readonly ILogger _logger; public NewsService(ApiClient apiClient, ILogger logger) { _apiClient = apiClient; _logger = logger; } /// /// Fetches the latest news from the API /// /// List of latest news items, or empty list if API call fails public async Task> GetLatestNewsAsync() { try { _logger.LogInformation("Fetching latest news from API"); List news = await _apiClient.News.Latest.GetAsync(); _logger.LogInformation("Successfully fetched {Count} news items", news?.Count ?? 0); return news ?? new List(); } catch(Exception ex) { _logger.LogError(ex, "Error fetching latest news from API"); return new List(); } } }