Finalizing base dependency injection.

This commit is contained in:
Kira Jiroux 2025-02-17 14:34:08 -05:00
parent 14ebe20a56
commit 82edd11e08
6 changed files with 14475 additions and 41 deletions

View File

@ -15,13 +15,19 @@
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="weather">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Weather
<NavLink class="nav-link" href="articles">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-journal-richtext" viewBox="0 0 16 16">
<path d="M7.5 3.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m-.861 1.542 1.33.886 1.854-1.855a.25.25 0 0 1 .289-.047L11 4.75V7a.5.5 0 0 1-.5.5h-5A.5.5 0 0 1 5 7v-.5s1.54-1.274 1.639-1.208M5 9.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 0 1h-2a.5.5 0 0 1-.5-.5" />
<path d="M3 0h10a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2v-1h1v1a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v1H1V2a2 2 0 0 1 2-2" />
<path d="M1 5v-.5a.5.5 0 0 1 1 0V5h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1zm0 3v-.5a.5.5 0 0 1 1 0V8h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1zm0 3v-.5a.5.5 0 0 1 1 0v.5h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1z" />
</svg> Articles
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="pokemonsleep">
<span class="bi bi-p-circle-fill" aria-hidden="true"></span> Pokemon Sleep
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-p-circle-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0M5.5 4.002V12h1.283V9.164h1.668C10.033 9.164 11 8.08 11 6.586c0-1.482-.955-2.584-2.538-2.584zm2.77 4.072c.893 0 1.419-.545 1.419-1.488s-.526-1.482-1.42-1.482H6.778v2.97z" />
</svg> Pokemon Sleep
</NavLink>
</div>
</nav>

View File

@ -0,0 +1,33 @@
@page "/articles"
@inject IArticleService ArticleService
<PageTitle>Articles</PageTitle>
<h3>Articles</h3>
@if(articles.Count == 0)
{
<p><em>Loading...</em></p>
}
else
{
@foreach(var article in articles)
{
<h4>@article.Title</h4>
<p>@article.Content</p>
<small>@article.DatePublished</small>
}
}
@code {
private List<Article> articles = new List<Article>();
protected override void OnInitialized()
{
var result = ArticleService.GetAllArticles();
if (result is not null)
{
articles = result;
}
}
}

View File

@ -1,64 +1,90 @@
@page "/pokemonsleep"
@inject IPokemonService PokemonService
@attribute [StreamRendering]
<PageTitle>Pokemon Sleep</PageTitle>
<h1>Pokemon Sleep</h1>
<p>This component will eventually show data from the PokemonSleepAPI. For right now it copies Weather.</p>
@if (forecasts == null)
@if (pokemons == null)
{
<p><em>Loading...</em></p>
}
else
{
<div class="card shadow border-0 mt-4" style ="margin: auto; width: 900px; max-width: 60%; ">
<div class="card-header bg-secondary bg-gradient ml-0 py-3">
<div class="row">
<div class="col-12 text-center">
<h1 class="text-info">Available Pokemon</h1>
</div>
</div>
</div>
<div class="card-body p-4">
<div class="row pb-3">
<div class="col-6">
</div>
<div class="col-6 text-end">
<a asp-controller="Pokemon" asp-action="PokemonCreate" class="btn btn-outline-primary"><i class="bi bi-plus-square"></i> Add New Pokemon</a>
</div>
</div>
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
<th scope="col" style="width: 50%;"></th>
<th scope="col">#</th>
<th scope="col">Pokemon</th>
<th scope="col">Sleep Type</th>
<th scope="col" style="padding-right: 30px;">Speciality</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
@foreach (var pokemon in pokemons)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
string URL = "https://www.serebii.net/pokemonsleep/pokemon/" + pokemon.Id + ".png";
string ShinyURL = "https://www.serebii.net/pokemonsleep/pokemon/shiny/" + pokemon.Id + ".png";
<tr style=" text-align: center; margin:0; padding: 0;">
<td style="display: block; margin:0; padding: 0;">
<img style=" width: 90px; height: 90px; " src=@URL />
<img style=" width: 90px; height: 90px; " src=@ShinyURL />
</td>
<th scope="row">@pokemon.Id</th>
<td> @pokemon.PokemonName</td>
<td>@pokemon.SleepType</td>
<td style="padding-right: 30px;">@pokemon.Speciality</td>
<td>
<a asp-controller="Pokemon" asp-action="PokemonDelete" asp-route-Id="@pokemon.Id" class="btn btn-danger">
<i class="bi bi-trash"></i>
</a>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
}
@code {
private WeatherForecast[]? forecasts;
private List<Pokemon> pokemons;
protected override async Task OnInitializedAsync()
{
// Simulate asynchronous loading to demonstrate streaming rendering
await Task.Delay(500);
var startDate = DateOnly.FromDateTime(DateTime.Now);
var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
var result = PokemonService.GetAllPokemon();
if (result is not null)
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = summaries[Random.Shared.Next(summaries.Length)]
}).ToArray();
pokemons = result;
}
private class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public string? Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}

View File

@ -8,3 +8,8 @@
@using Microsoft.JSInterop
@using Portfolio.WebUI.Server
@using Portfolio.WebUI.Server.Components
@using Portfolio.Domain.Features.Articles
@using Portfolio.Domain.Features.Pokemon
@using Portfolio.Application.Services.Articles
@using Portfolio.Application.Services.PokemonService

View File

@ -1,10 +1,12 @@
using Portfolio.WebUI.Server.Components;
using Portfolio.Application;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents();
builder.Services.AddApplication();
var app = builder.Build();

File diff suppressed because it is too large Load Diff