API: Setup controllers & services | Blazor: Setup default blazor layout.

This commit is contained in:
Max 2023-09-06 21:06:13 +02:00
parent 1a686219ff
commit 62244750de
19 changed files with 94 additions and 220 deletions

View File

@ -1,17 +0,0 @@
namespace SharpRSS.API.Contracts.DTO
{
public record ApiKey()
{
public string Key { get; }
public string Usage { get; }
public KeyStatus Status { get; }
public string Message { get; }
}
public enum KeyStatus
{
Active,
Disabled,
Unavailable
}
}

View File

@ -1,10 +0,0 @@
namespace SharpRSS.API.Contracts
{
public class RssConnection
{
public RssConnection(string connection, string apiKey)
{
// Identify with server
}
}
}

View File

@ -13,6 +13,7 @@
<ItemGroup>
<Folder Include="Auth" />
<Folder Include="DTO" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,16 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace SharpRSS.API.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class AuthController : ControllerBase
{
[HttpGet("authenticate")]
public async Task<ActionResult<string>> Authenticate()
{
return "Authenticated!";
}
}
}

View File

@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Mvc;
namespace SharpRSS.API.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class RssController
{
}
}

View File

@ -1,37 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace SharpRSS.API.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}

View File

@ -0,0 +1,7 @@
namespace SharpRSS.API.Data
{
public class AuthenticationService
{
}
}

View File

@ -0,0 +1,7 @@
namespace SharpRSS.API.Data
{
public class SharpRssService
{
}
}

View File

@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Formatting.Compact;
using SharpRSS.API.Data;
using ToolQit;
using ToolQit.Logging.Serilog;
@ -17,6 +18,8 @@ builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddScoped<AuthenticationService>();
builder.Services.AddScoped<SharpRssService>();
var app = builder.Build();

View File

@ -22,4 +22,8 @@
<ProjectReference Include="..\ToolQit\ToolQit\ToolQit.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models" />
</ItemGroup>
</Project>

View File

@ -1,15 +0,0 @@
using System;
namespace SharpRSS.API
{
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

View File

@ -1,15 +0,0 @@
using System;
namespace SharpRSS.Blazor.Data
{
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

View File

@ -1,24 +0,0 @@
using System;
using System.Linq;
using System.Threading.Tasks;
namespace SharpRSS.Blazor.Data
{
public class WeatherForecastService
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
public Task<WeatherForecast[]> GetForecastAsync(DateOnly startDate)
{
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}).ToArray());
}
}
}

View File

@ -1,19 +0,0 @@
@page "/counter"
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}

View File

@ -1,9 +1,10 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace SharpRSS.Blazor.Pages;
namespace SharpRSS.Blazor.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
@ -24,3 +25,4 @@ public class ErrorModel : PageModel
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}

View File

@ -1,50 +0,0 @@
@page "/fetchdata"
@using SharpRSS.Blazor.Data
@inject WeatherForecastService ForecastService
<PageTitle>Weather forecast</PageTitle>
<h1>Weather forecast</h1>
<p>This component demonstrates fetching data from a service.</p>
@if (forecasts == null)
{
<p>
<em>Loading...</em>
</p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}
@code {
private WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync()
{
forecasts = await ForecastService.GetForecastAsync(DateOnly.FromDateTime(DateTime.Now));
}
}

View File

@ -4,7 +4,6 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using MudBlazor.Services;
using SharpRSS.Blazor.Data;
using Serilog;
using Serilog.Formatting.Compact;
using ToolQit;
@ -17,7 +16,6 @@ builder.Logging.AddSerilog();
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddMudServices();
builder.Services.AddSingleton<WeatherForecastService>();
var app = builder.Build();

View File

@ -1,24 +1,32 @@
@inherits LayoutComponentBase
<MudThemeProvider/>
<MudThemeProvider @bind-IsDarkMode="@_isDarkTheme" Theme="_theme"/>
<MudDialogProvider/>
<MudSnackbarProvider/>
<PageTitle>SharpRSS.Blazor</PageTitle>
<div class="page">
<div class="sidebar">
<NavMenu/>
</div>
<main>
<div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
</div>
<article class="content px-4">
<MudLayout>
<MudAppBar>
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@((e) => ToggleDrawer())"/>
<MudText Typo="Typo.h6">SharpRSS</MudText>
<MudSpacer/>
<MudToggleIconButton @bind-Toggled="_isDarkTheme" Icon="@Icons.Material.Filled.DarkMode" ToggledIcon="@Icons.Material.Filled.LightMode"/>
</MudAppBar>
<MudDrawer @bind-Open="@_drawerOpen" ClipMode="DrawerClipMode.Always">
<MudNavLink Href="/" Icon="@Icons.Material.Filled.Home">Home</MudNavLink>
</MudDrawer>
<MudMainContent>
@Body
</article>
</main>
</div>
</MudMainContent>
</MudLayout>
@code
{
readonly MudTheme _theme = new MudTheme();
bool _drawerOpen = true;
bool _isDarkTheme = true;
void ToggleDrawer() => _drawerOpen = !_drawerOpen;
}

View File

@ -21,4 +21,8 @@
<ProjectReference Include="..\ToolQit\ToolQit\ToolQit.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Data" />
</ItemGroup>
</Project>