2025-11-14 15:18:30 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Marechai.App.Services;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Service for fetching and managing news from the Marechai API
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class NewsService
|
|
|
|
|
{
|
|
|
|
|
private readonly ApiClient _apiClient;
|
|
|
|
|
private readonly ILogger<NewsService> _logger;
|
|
|
|
|
|
|
|
|
|
public NewsService(ApiClient apiClient, ILogger<NewsService> logger)
|
|
|
|
|
{
|
|
|
|
|
_apiClient = apiClient;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches the latest news from the API
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>List of latest news items, or empty list if API call fails</returns>
|
|
|
|
|
public async Task<List<NewsDto>> GetLatestNewsAsync()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Fetching latest news from API");
|
|
|
|
|
List<NewsDto> news = await _apiClient.News.Latest.GetAsync();
|
|
|
|
|
_logger.LogInformation("Successfully fetched {Count} news items", news?.Count ?? 0);
|
|
|
|
|
|
2025-11-15 02:38:47 +00:00
|
|
|
return news ?? [];
|
2025-11-14 15:18:30 +00:00
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Error fetching latest news from API");
|
|
|
|
|
|
2025-11-15 02:38:47 +00:00
|
|
|
return [];
|
2025-11-14 15:18:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|