added multithreaded api calling on homepage
This commit is contained in:
@@ -13,4 +13,10 @@ public class ProjectController(IProjectRepository repository) : ControllerBase {
|
|||||||
return Ok(projects);
|
return Ok(projects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("featured")]
|
||||||
|
public async Task<IActionResult> GetFeaturedProjects(CancellationToken ct) {
|
||||||
|
var projects = await repository.GetFeaturedProjects(ct);
|
||||||
|
return Ok(projects);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,4 +13,10 @@ public class TechnologyController(ITechnologyRepository repository) : Controller
|
|||||||
return Ok(technologies);
|
return Ok(technologies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("featured")]
|
||||||
|
public async Task<IActionResult> GetFeaturedTechnologies(CancellationToken ct) {
|
||||||
|
var technologies = await repository.GetFeaturedTechnologies(ct);
|
||||||
|
return Ok(technologies);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="13.0.2" />
|
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="13.0.2" />
|
||||||
<PackageReference Include="Aspire.StackExchange.Redis.OutputCaching" Version="13.0.2" />
|
<PackageReference Include="Aspire.StackExchange.Redis.OutputCaching" Version="13.0.2" />
|
||||||
<PackageReference Include="HopFrame.Web" Version="3.2.0" />
|
<PackageReference Include="HopFrame.Web" Version="3.3.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.11" />
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.11" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ builder.Services.AddHopFrame(options => {
|
|||||||
.IsTextArea(true);
|
.IsTextArea(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
options.AddExporters();
|
||||||
});
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|||||||
@@ -13,4 +13,12 @@ internal sealed class ProjectRepository(DatabaseContext context) : IProjectRepos
|
|||||||
.ToArrayAsync(ct);
|
.ToArrayAsync(ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Project>> GetFeaturedProjects(CancellationToken ct) {
|
||||||
|
return await context.Projects
|
||||||
|
.Include(p => p.Languages)
|
||||||
|
.Where(p => p.Featured)
|
||||||
|
.OrderByDescending(p => p.OrderIndex)
|
||||||
|
.ToArrayAsync(ct);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,4 +10,10 @@ internal sealed class TechnologyRepository(DatabaseContext context) : ITechnolog
|
|||||||
return await context.Technologies.ToArrayAsync(ct);
|
return await context.Technologies.ToArrayAsync(ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Technology>> GetFeaturedTechnologies(CancellationToken ct) {
|
||||||
|
return await context.Technologies
|
||||||
|
.Where(t => t.Featured)
|
||||||
|
.ToArrayAsync(ct);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,4 +6,6 @@ public interface IProjectRepository {
|
|||||||
|
|
||||||
Task<IEnumerable<Project>> GetProjects(CancellationToken ct);
|
Task<IEnumerable<Project>> GetProjects(CancellationToken ct);
|
||||||
|
|
||||||
|
Task<IEnumerable<Project>> GetFeaturedProjects(CancellationToken ct);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,4 +6,6 @@ public interface ITechnologyRepository {
|
|||||||
|
|
||||||
Task<IEnumerable<Technology>> GetTechnologies(CancellationToken ct);
|
Task<IEnumerable<Technology>> GetTechnologies(CancellationToken ct);
|
||||||
|
|
||||||
|
Task<IEnumerable<Technology>> GetFeaturedTechnologies(CancellationToken ct);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,6 @@
|
|||||||
if (displayElement.innerText !== jobs.display)
|
if (displayElement.innerText !== jobs.display)
|
||||||
displayElement.innerText = jobs.display;
|
displayElement.innerText = jobs.display;
|
||||||
}, 50)
|
}, 50)
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@inherits CancellableComponent
|
@inherits CancellableComponent
|
||||||
@@ -98,13 +97,15 @@
|
|||||||
private IEnumerable<TimelineEntry> _timeline = [];
|
private IEnumerable<TimelineEntry> _timeline = [];
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync() {
|
protected override async Task OnInitializedAsync() {
|
||||||
var projects = await ProjectRepository.GetProjects(TokenSource.Token);
|
var projectsTask = ProjectRepository.GetFeaturedProjects(TokenSource.Token);
|
||||||
_projects = projects.Where(p => p.Featured);
|
var technologiesTask = TechnologyRepository.GetFeaturedTechnologies(TokenSource.Token);
|
||||||
|
var timelineTask = TimelineRepository.GetFeaturedTimeline(TokenSource.Token);
|
||||||
|
|
||||||
var technologies = await TechnologyRepository.GetTechnologies(TokenSource.Token);
|
await Task.WhenAll(projectsTask, technologiesTask, timelineTask);
|
||||||
_technologies = technologies.Where(t => t.Featured);
|
|
||||||
|
|
||||||
_timeline = await TimelineRepository.GetFeaturedTimeline(TokenSource.Token);
|
_projects = projectsTask.Result;
|
||||||
|
_technologies = technologiesTask.Result;
|
||||||
|
_timeline = timelineTask.Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,4 +12,13 @@ internal sealed class ProjectRepository(IHttpClientFactory factory) : IProjectRe
|
|||||||
var data = await response.Content.ReadFromJsonAsync<IEnumerable<Project>>(ct);
|
var data = await response.Content.ReadFromJsonAsync<IEnumerable<Project>>(ct);
|
||||||
return data?.OrderByDescending(p => p.OrderIndex) ?? Enumerable.Empty<Project>();
|
return data?.OrderByDescending(p => p.OrderIndex) ?? Enumerable.Empty<Project>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Project>> GetFeaturedProjects(CancellationToken ct) {
|
||||||
|
var client = factory.CreateClient("api");
|
||||||
|
var response = await client.GetAsync("api/projects/featured", ct);
|
||||||
|
if (!response.IsSuccessStatusCode) return [];
|
||||||
|
|
||||||
|
var data = await response.Content.ReadFromJsonAsync<IEnumerable<Project>>(ct);
|
||||||
|
return data?.OrderByDescending(p => p.OrderIndex) ?? Enumerable.Empty<Project>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -12,4 +12,13 @@ internal sealed class TechnologyRepository(IHttpClientFactory factory) : ITechno
|
|||||||
var data = await response.Content.ReadFromJsonAsync<IEnumerable<Technology>>(ct);
|
var data = await response.Content.ReadFromJsonAsync<IEnumerable<Technology>>(ct);
|
||||||
return data ?? [];
|
return data ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Technology>> GetFeaturedTechnologies(CancellationToken ct) {
|
||||||
|
var client = factory.CreateClient("api");
|
||||||
|
var response = await client.GetAsync("api/technologies/featured", ct);
|
||||||
|
if (!response.IsSuccessStatusCode) return [];
|
||||||
|
|
||||||
|
var data = await response.Content.ReadFromJsonAsync<IEnumerable<Technology>>(ct);
|
||||||
|
return data ?? [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user