Added client side repos
This commit is contained in:
20
src/Portfolio.Web/Services/AboutRepository.cs
Normal file
20
src/Portfolio.Web/Services/AboutRepository.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Portfolio.Shared.Models;
|
||||
using Portfolio.Shared.Services;
|
||||
|
||||
namespace Portfolio.Web.Services;
|
||||
|
||||
internal sealed class AboutRepository(IHttpClientFactory factory) : IAboutRepository {
|
||||
private About DefaultValue => new() {
|
||||
AboutMe = string.Empty,
|
||||
Future = string.Empty
|
||||
};
|
||||
|
||||
public async Task<About> GetAbout(CancellationToken ct) {
|
||||
var client = factory.CreateClient("api");
|
||||
var response = await client.GetAsync("api/about", ct);
|
||||
if (!response.IsSuccessStatusCode) return DefaultValue;
|
||||
|
||||
var data = await response.Content.ReadFromJsonAsync<About>(ct);
|
||||
return data ?? DefaultValue;
|
||||
}
|
||||
}
|
||||
15
src/Portfolio.Web/Services/ProjectRepository.cs
Normal file
15
src/Portfolio.Web/Services/ProjectRepository.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Portfolio.Shared.Models;
|
||||
using Portfolio.Shared.Services;
|
||||
|
||||
namespace Portfolio.Web.Services;
|
||||
|
||||
internal sealed class ProjectRepository(IHttpClientFactory factory) : IProjectRepository {
|
||||
public async Task<IEnumerable<Project>> GetProjects(CancellationToken ct) {
|
||||
var client = factory.CreateClient("api");
|
||||
var response = await client.GetAsync("api/projects", ct);
|
||||
if (!response.IsSuccessStatusCode) return [];
|
||||
|
||||
var data = await response.Content.ReadFromJsonAsync<IEnumerable<Project>>(ct);
|
||||
return data ?? [];
|
||||
}
|
||||
}
|
||||
15
src/Portfolio.Web/Services/TechnologyRepository.cs
Normal file
15
src/Portfolio.Web/Services/TechnologyRepository.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Portfolio.Shared.Models;
|
||||
using Portfolio.Shared.Services;
|
||||
|
||||
namespace Portfolio.Web.Services;
|
||||
|
||||
internal sealed class TechnologyRepository(IHttpClientFactory factory) : ITechnologyRepository {
|
||||
public async Task<IEnumerable<Technology>> GetTechnologies(CancellationToken ct) {
|
||||
var client = factory.CreateClient("api");
|
||||
var response = await client.GetAsync("api/technologies", ct);
|
||||
if (!response.IsSuccessStatusCode) return [];
|
||||
|
||||
var data = await response.Content.ReadFromJsonAsync<IEnumerable<Technology>>(ct);
|
||||
return data ?? [];
|
||||
}
|
||||
}
|
||||
15
src/Portfolio.Web/Services/TimelineRepository.cs
Normal file
15
src/Portfolio.Web/Services/TimelineRepository.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
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 ?? [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user