Files
Portfolio/src/Portfolio.Web/Services/TimelineRepository.cs
2025-01-26 14:20:50 +01:00

24 lines
1001 B
C#

using Portfolio.Shared.Models;
using Portfolio.Shared.Services;
namespace Portfolio.Web.Services;
internal sealed class TimelineRepository(IHttpClientFactory factory) : ITimelineRepository {
public async Task<IEnumerable<TimelineEntry>> GetTimeline(TimelineEntryType type, CancellationToken ct) {
var client = factory.CreateClient("api");
var result = await client.GetAsync($"api/timeline/{type}", ct);
if (!result.IsSuccessStatusCode) return [];
var data = await result.Content.ReadFromJsonAsync<IEnumerable<TimelineEntry>>(ct);
return data ?? [];
}
public async Task<IEnumerable<TimelineEntry>> GetFeaturedTimeline(CancellationToken ct) {
var client = factory.CreateClient("api");
var result = await client.GetAsync("api/timeline/featured", ct);
if (!result.IsSuccessStatusCode) return [];
var data = await result.Content.ReadFromJsonAsync<IEnumerable<TimelineEntry>>(ct);
return data ?? [];
}
}