Compare commits
87 Commits
main
...
feature/ad
Author | SHA1 | Date | |
---|---|---|---|
06b6a6bf08 | |||
6f1cd303f3 | |||
9ea4425c26 | |||
d7bc6a368c | |||
1862fa3ab4 | |||
869ee77446 | |||
c1d27dc151 | |||
dd2438153c | |||
430ab2b50e | |||
ecf31568c8 | |||
a312281c22 | |||
1946690bd9 | |||
25a73bce0f | |||
e5eeb5eaa2 | |||
910e025fd0 | |||
8dfc06e6d2 | |||
97466ba84b | |||
ab76264cd0 | |||
b24e24f3f7 | |||
9ceec5ca1a | |||
d98875ebdc | |||
1588f6c8f6 | |||
652550a2fe | |||
81f101e337 | |||
a3d941d6a2 | |||
8a098c1275 | |||
c260f1b5a0 | |||
b86f933171 | |||
f949bded9b | |||
e11c8327ec | |||
0a86721db2 | |||
148e7eb218 | |||
c0efc90c31 | |||
caaba043a5 | |||
9c3bf6e5a2 | |||
af2857103b | |||
5b4696e6ec | |||
5ab6745a24 | |||
e800504651 | |||
28c7f7ce78 | |||
3c88bde0d1 | |||
72946ac625 | |||
417d9cae7e | |||
fa87d808dc | |||
71b1ff32c4 | |||
5b236da2e3 | |||
8f09197de6 | |||
8925f07f31 | |||
8d47060c08 | |||
5d7c2c3b50 | |||
7cb6e9d463 | |||
593036a712 | |||
6efbd749be | |||
4b2223634e | |||
aae7f504e9 | |||
97170dcb44 | |||
faf3c4c3a8 | |||
d38167bb97 | |||
caceb0fe4c | |||
8f96251f94 | |||
2431eda6f5 | |||
c1e5227289 | |||
eb4777e330 | |||
0fbb94b86e | |||
b6d3eb72fe | |||
a1a7d6dd96 | |||
926e0a718e | |||
c5a4ac37b2 | |||
6db3aba1c2 | |||
3917dda658 | |||
9a447db891 | |||
6db9537206 | |||
1d1acd2a40 | |||
9593979d7b | |||
2a16c185fe | |||
9c938bc730 | |||
e21dfd17ff | |||
0837092d5f | |||
278c807fa3 | |||
14d73851ea | |||
fa394480b1 | |||
d0142ec5cf | |||
951500ca91 | |||
0d670554e6 | |||
8ef34d014b | |||
bd55ac28e3 | |||
8fda2e9907 |
11
.github/workflows/dotnet.yml
vendored
11
.github/workflows/dotnet.yml
vendored
@ -10,19 +10,16 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 8.0.x
|
||||
|
||||
- name: Add NuGet source
|
||||
run: dotnet nuget add source --username oliverbooth --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/oliverbooth/index.json"
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
- name: Build
|
||||
run: dotnet build --no-restore --configuration Release
|
||||
|
||||
- name: Test
|
||||
run: dotnet test --no-build --verbosity normal
|
||||
|
7
.github/workflows/prerelease.yml
vendored
7
.github/workflows/prerelease.yml
vendored
@ -12,13 +12,16 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 8.0.x
|
||||
|
||||
- name: Add GitHub NuGet source
|
||||
run: dotnet nuget add source --username oliverbooth --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/oliverbooth/index.json"
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
|
7
.github/workflows/release.yml
vendored
7
.github/workflows/release.yml
vendored
@ -12,13 +12,16 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 8.0.x
|
||||
|
||||
- name: Add GitHub NuGet source
|
||||
run: dotnet nuget add source --username oliverbooth --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/oliverbooth/index.json"
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
|
54
Gulpfile.js
54
Gulpfile.js
@ -1,54 +0,0 @@
|
||||
const gulp = require('gulp');
|
||||
const sass = require('gulp-sass')(require('sass'));
|
||||
const cleanCSS = require('gulp-clean-css');
|
||||
const rename = require('gulp-rename');
|
||||
const ts = require('gulp-typescript');
|
||||
const terser = require('gulp-terser');
|
||||
const webpack = require('webpack-stream');
|
||||
|
||||
const srcDir = 'src';
|
||||
const destDir = 'OliverBooth/wwwroot';
|
||||
|
||||
function compileSCSS() {
|
||||
return gulp.src(`${srcDir}/scss/**/*.scss`)
|
||||
.pipe(sass().on('error', sass.logError))
|
||||
.pipe(cleanCSS({ compatibility: 'ie11' }))
|
||||
.pipe(rename({ suffix: '.min' }))
|
||||
.pipe(gulp.dest(`${destDir}/css`));
|
||||
}
|
||||
|
||||
function compileTS() {
|
||||
return gulp.src(`${srcDir}/ts/**/*.ts`)
|
||||
.pipe(ts("tsconfig.json"))
|
||||
.pipe(terser())
|
||||
.pipe(gulp.dest(`tmp/js`));
|
||||
}
|
||||
|
||||
function bundleJS() {
|
||||
return gulp.src('tmp/js/*.js')
|
||||
.pipe(webpack({ mode: 'production', output: { filename: 'app.min.js' } }))
|
||||
.pipe(gulp.dest(`${destDir}/js`));
|
||||
}
|
||||
|
||||
function copyJS() {
|
||||
return gulp.src(`${srcDir}/ts/**/*.js`)
|
||||
.pipe(rename({ suffix: '.min' }))
|
||||
.pipe(gulp.dest(`${destDir}/js`));
|
||||
}
|
||||
|
||||
function copyCSS() {
|
||||
return gulp.src(`${srcDir}/scss/**/*.css`)
|
||||
.pipe(rename({ suffix: '.min' }))
|
||||
.pipe(gulp.dest(`${destDir}/css`));
|
||||
}
|
||||
|
||||
function copyImages() {
|
||||
return gulp.src(`${srcDir}/img/**/*.*`)
|
||||
.pipe(gulp.dest(`${destDir}/img`));
|
||||
}
|
||||
|
||||
exports.assets = copyImages;
|
||||
exports.styles = gulp.parallel(compileSCSS, copyCSS);
|
||||
exports.scripts = gulp.parallel(copyJS, gulp.series(compileTS, bundleJS));
|
||||
|
||||
exports.default = gulp.parallel(exports.styles, exports.scripts, exports.assets);
|
99
Gulpfile.mjs
Normal file
99
Gulpfile.mjs
Normal file
@ -0,0 +1,99 @@
|
||||
import fs from "fs";
|
||||
import gulp from "gulp";
|
||||
import cleanCSS from "gulp-clean-css";
|
||||
import {deleteSync} from "del";
|
||||
import noop from "gulp-noop";
|
||||
import rename from "gulp-rename";
|
||||
import gulpSass from "gulp-sass";
|
||||
import * as nodeSass from "sass";
|
||||
const sass = gulpSass(nodeSass);
|
||||
import sourcemaps from "gulp-sourcemaps";
|
||||
import ts from "gulp-typescript";
|
||||
import webpack from "webpack-stream";
|
||||
import vinylPaths from "vinyl-paths";
|
||||
|
||||
const srcDir = "src";
|
||||
const tmpDir = "tmp";
|
||||
const destDir = "OliverBooth/wwwroot";
|
||||
const isDevelopment = !!process.env.DEVELOPMENT;
|
||||
|
||||
function cleanTMP() {
|
||||
return gulp.src(tmpDir, {allowEmpty: true})
|
||||
.pipe(vinylPaths(deleteSync));
|
||||
}
|
||||
|
||||
function cleanWWWRoot() {
|
||||
return gulp.src(destDir, {allowEmpty: true})
|
||||
.pipe(vinylPaths(deleteSync));
|
||||
}
|
||||
|
||||
function compileSCSS() {
|
||||
return gulp.src(`${srcDir}/scss/**/*.scss`)
|
||||
.pipe(isDevelopment ? sourcemaps.init() : noop())
|
||||
.pipe(sass().on("error", sass.logError))
|
||||
.pipe(cleanCSS({compatibility: "ie11"}))
|
||||
.pipe(rename({suffix: ".min"}))
|
||||
.pipe(isDevelopment ? sourcemaps.write() : noop())
|
||||
.pipe(gulp.dest(`${destDir}/css`));
|
||||
}
|
||||
|
||||
function compileTS() {
|
||||
return gulp.src(`${srcDir}/ts/**/*.ts`)
|
||||
.pipe(isDevelopment ? sourcemaps.init() : noop())
|
||||
.pipe(ts("tsconfig.json"))
|
||||
.pipe(isDevelopment ? sourcemaps.write("./", { includeContent: true }) : noop())
|
||||
.pipe(gulp.dest(`${tmpDir}/js`));
|
||||
}
|
||||
|
||||
function bundleJS(done) {
|
||||
const tasks = fs.readdirSync(`${tmpDir}/js`, {withFileTypes: true})
|
||||
.filter(dirent => dirent.isDirectory())
|
||||
.map(d => bundleDir(d.name));
|
||||
return gulp.parallel(...tasks, writeSourcemaps)(done);
|
||||
|
||||
function bundleDir(directory) {
|
||||
return () => gulp.src(`${tmpDir}/js/${directory}/${directory}.js`)
|
||||
.pipe(isDevelopment ? sourcemaps.init() : noop())
|
||||
.pipe(webpack({mode: "production", output: {filename: `${directory}.min.js`}, devtool: "source-map"}))
|
||||
.pipe(isDevelopment ? sourcemaps.write("./", { includeContent: true }) : noop())
|
||||
.pipe(gulp.dest(`${destDir}/js`));
|
||||
}
|
||||
|
||||
function writeSourcemaps() {
|
||||
return gulp.src(`${destDir}/js/**/*.js`)
|
||||
.pipe(isDevelopment ? sourcemaps.init({ loadMaps: true }) : noop())
|
||||
.pipe(isDevelopment ? sourcemaps.write("./", { includeContent: true }) : noop())
|
||||
.pipe(gulp.dest(`${destDir}/js`));
|
||||
}
|
||||
}
|
||||
|
||||
function copyJS() {
|
||||
return gulp.src(`${srcDir}/ts/**/*.js`)
|
||||
.pipe(rename({suffix: ".min"}))
|
||||
.pipe(gulp.dest(`${destDir}/js`));
|
||||
}
|
||||
|
||||
function copyCSS() {
|
||||
return gulp.src(`${srcDir}/scss/**/*.css`)
|
||||
.pipe(rename({suffix: ".min"}))
|
||||
.pipe(gulp.dest(`${destDir}/css`));
|
||||
}
|
||||
|
||||
function copyImages() {
|
||||
return gulp.src(`${srcDir}/img/**/*.*`)
|
||||
.pipe(gulp.dest(`${destDir}/img`));
|
||||
}
|
||||
|
||||
function exists(path) {
|
||||
try {
|
||||
return fs.existsSync(path);
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
gulp.task("clean", gulp.parallel(cleanTMP, cleanWWWRoot));
|
||||
gulp.task("assets", copyImages);
|
||||
gulp.task("styles", gulp.parallel(compileSCSS, copyCSS));
|
||||
gulp.task("scripts", gulp.parallel(copyJS, gulp.series(compileTS, bundleJS)));
|
||||
gulp.task("default", gulp.series("clean", gulp.parallel("styles", "scripts", "assets"), cleanTMP));
|
22
OliverBooth.Admin/Dockerfile
Normal file
22
OliverBooth.Admin/Dockerfile
Normal file
@ -0,0 +1,22 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
USER $APP_UID
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["OliverBooth.Admin/OliverBooth.Admin.csproj", "OliverBooth.Admin/"]
|
||||
COPY . .
|
||||
|
||||
WORKDIR "/src/OliverBooth.Admin"
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "OliverBooth.Admin.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "OliverBooth.Admin.dll"]
|
37
OliverBooth.Admin/OliverBooth.Admin.csproj
Normal file
37
OliverBooth.Admin/OliverBooth.Admin.csproj
Normal file
@ -0,0 +1,37 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<VersionPrefix>1.0.0</VersionPrefix>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(VersionSuffix)' != '' And '$(BuildNumber)' == ''">
|
||||
<Version>$(VersionPrefix)-$(VersionSuffix)</Version>
|
||||
<AssemblyVersion>$(VersionPrefix).0</AssemblyVersion>
|
||||
<FileVersion>$(VersionPrefix).0</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(VersionSuffix)' != '' And '$(BuildNumber)' != ''">
|
||||
<Version>$(VersionPrefix)-$(VersionSuffix).$(BuildNumber)</Version>
|
||||
<AssemblyVersion>$(VersionPrefix).$(BuildNumber)</AssemblyVersion>
|
||||
<FileVersion>$(VersionPrefix).$(BuildNumber)</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(VersionSuffix)' == ''">
|
||||
<Version>$(VersionPrefix)</Version>
|
||||
<AssemblyVersion>$(VersionPrefix).0</AssemblyVersion>
|
||||
<FileVersion>$(VersionPrefix).0</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OliverBooth.Common\OliverBooth.Common.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Properties\launchSettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
26
OliverBooth.Admin/Pages/Error.cshtml
Normal file
26
OliverBooth.Admin/Pages/Error.cshtml
Normal file
@ -0,0 +1,26 @@
|
||||
@page
|
||||
@model ErrorModel
|
||||
@{
|
||||
ViewData["Title"] = "Error";
|
||||
}
|
||||
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (Model.ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
<h3>Development Mode</h3>
|
||||
<p>
|
||||
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
|
||||
</p>
|
||||
<p>
|
||||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
|
||||
It can result in displaying sensitive information from exceptions to end users.
|
||||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
||||
and restarting the app.
|
||||
</p>
|
26
OliverBooth.Admin/Pages/Error.cshtml.cs
Normal file
26
OliverBooth.Admin/Pages/Error.cshtml.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace OliverBooth.Admin.Pages;
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public class ErrorModel : PageModel
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
private readonly ILogger<ErrorModel> _logger;
|
||||
|
||||
public ErrorModel(ILogger<ErrorModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||
}
|
||||
}
|
10
OliverBooth.Admin/Pages/Index.cshtml
Normal file
10
OliverBooth.Admin/Pages/Index.cshtml
Normal file
@ -0,0 +1,10 @@
|
||||
@page
|
||||
@model IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Home page";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Welcome</h1>
|
||||
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
||||
</div>
|
18
OliverBooth.Admin/Pages/Index.cshtml.cs
Normal file
18
OliverBooth.Admin/Pages/Index.cshtml.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace OliverBooth.Admin.Pages;
|
||||
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private readonly ILogger<IndexModel> _logger;
|
||||
|
||||
public IndexModel(ILogger<IndexModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
8
OliverBooth.Admin/Pages/Privacy.cshtml
Normal file
8
OliverBooth.Admin/Pages/Privacy.cshtml
Normal file
@ -0,0 +1,8 @@
|
||||
@page
|
||||
@model PrivacyModel
|
||||
@{
|
||||
ViewData["Title"] = "Privacy Policy";
|
||||
}
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<p>Use this page to detail your site's privacy policy.</p>
|
18
OliverBooth.Admin/Pages/Privacy.cshtml.cs
Normal file
18
OliverBooth.Admin/Pages/Privacy.cshtml.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace OliverBooth.Admin.Pages;
|
||||
|
||||
public class PrivacyModel : PageModel
|
||||
{
|
||||
private readonly ILogger<PrivacyModel> _logger;
|
||||
|
||||
public PrivacyModel(ILogger<PrivacyModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
51
OliverBooth.Admin/Pages/Shared/_Layout.cshtml
Normal file
51
OliverBooth.Admin/Pages/Shared/_Layout.cshtml
Normal file
@ -0,0 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>@ViewData["Title"] - OliverBooth.Admin</title>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css"/>
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>
|
||||
<link rel="stylesheet" href="~/OliverBooth.Admin.styles.css" asp-append-version="true"/>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" asp-area="" asp-page="/Index">OliverBooth.Admin</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container">
|
||||
<main role="main" class="pb-3">
|
||||
@RenderBody()
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2024 - OliverBooth.Admin - <a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
48
OliverBooth.Admin/Pages/Shared/_Layout.cshtml.css
Normal file
48
OliverBooth.Admin/Pages/Shared/_Layout.cshtml.css
Normal file
@ -0,0 +1,48 @@
|
||||
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||
for details on configuring this project to bundle and minify static web assets. */
|
||||
|
||||
a.navbar-brand {
|
||||
white-space: normal;
|
||||
text-align: center;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #0077cc;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
color: #fff;
|
||||
background-color: #1b6ec2;
|
||||
border-color: #1861ac;
|
||||
}
|
||||
|
||||
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
|
||||
color: #fff;
|
||||
background-color: #1b6ec2;
|
||||
border-color: #1861ac;
|
||||
}
|
||||
|
||||
.border-top {
|
||||
border-top: 1px solid #e5e5e5;
|
||||
}
|
||||
.border-bottom {
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.box-shadow {
|
||||
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
|
||||
}
|
||||
|
||||
button.accept-policy {
|
||||
font-size: 1rem;
|
||||
line-height: inherit;
|
||||
}
|
||||
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
white-space: nowrap;
|
||||
line-height: 60px;
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
|
||||
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
|
3
OliverBooth.Admin/Pages/_ViewImports.cshtml
Normal file
3
OliverBooth.Admin/Pages/_ViewImports.cshtml
Normal file
@ -0,0 +1,3 @@
|
||||
@using OliverBooth.Admin
|
||||
@namespace OliverBooth.Admin.Pages
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
3
OliverBooth.Admin/Pages/_ViewStart.cshtml
Normal file
3
OliverBooth.Admin/Pages/_ViewStart.cshtml
Normal file
@ -0,0 +1,3 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
41
OliverBooth.Admin/Program.cs
Normal file
41
OliverBooth.Admin/Program.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using Serilog;
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.Console()
|
||||
.WriteTo.File("logs/latest.log", rollingInterval: RollingInterval.Day)
|
||||
#if DEBUG
|
||||
.MinimumLevel.Debug()
|
||||
#endif
|
||||
.CreateLogger();
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
builder.Configuration.AddTomlFile("data/config.toml", true, true);
|
||||
builder.Logging.ClearProviders();
|
||||
builder.Logging.AddSerilog();
|
||||
|
||||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddControllersWithViews();
|
||||
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
|
||||
builder.Services.AddServerSideBlazor().AddInteractiveServerComponents();
|
||||
builder.Services.AddRouting(options => options.LowercaseUrls = true);
|
||||
|
||||
WebApplication app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
app.MapRazorPages();
|
||||
app.MapBlazorHub();
|
||||
|
||||
app.Run();
|
22
OliverBooth.Admin/wwwroot/css/site.css
Normal file
22
OliverBooth.Admin/wwwroot/css/site.css
Normal file
@ -0,0 +1,22 @@
|
||||
html {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
html {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
|
||||
box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
|
||||
}
|
||||
|
||||
html {
|
||||
position: relative;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
margin-bottom: 60px;
|
||||
}
|
BIN
OliverBooth.Admin/wwwroot/favicon.ico
Normal file
BIN
OliverBooth.Admin/wwwroot/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
4
OliverBooth.Admin/wwwroot/js/site.js
Normal file
4
OliverBooth.Admin/wwwroot/js/site.js
Normal file
@ -0,0 +1,4 @@
|
||||
// Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||
// for details on configuring this project to bundle and minify static web assets.
|
||||
|
||||
// Write your JavaScript code.
|
22
OliverBooth.Admin/wwwroot/lib/bootstrap/LICENSE
Normal file
22
OliverBooth.Admin/wwwroot/lib/bootstrap/LICENSE
Normal file
@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2011-2021 Twitter, Inc.
|
||||
Copyright (c) 2011-2021 The Bootstrap Authors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
@ -0,0 +1,23 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) .NET Foundation and Contributors
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
435
OliverBooth.Admin/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js
vendored
Normal file
435
OliverBooth.Admin/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js
vendored
Normal file
@ -0,0 +1,435 @@
|
||||
/**
|
||||
* @license
|
||||
* Unobtrusive validation support library for jQuery and jQuery Validate
|
||||
* Copyright (c) .NET Foundation. All rights reserved.
|
||||
* Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
* @version v4.0.0
|
||||
*/
|
||||
|
||||
/*jslint white: true, browser: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: false */
|
||||
/*global document: false, jQuery: false */
|
||||
|
||||
(function (factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define("jquery.validate.unobtrusive", ['jquery-validation'], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// CommonJS-like environments that support module.exports
|
||||
module.exports = factory(require('jquery-validation'));
|
||||
} else {
|
||||
// Browser global
|
||||
jQuery.validator.unobtrusive = factory(jQuery);
|
||||
}
|
||||
}(function ($) {
|
||||
var $jQval = $.validator,
|
||||
adapters,
|
||||
data_validation = "unobtrusiveValidation";
|
||||
|
||||
function setValidationValues(options, ruleName, value) {
|
||||
options.rules[ruleName] = value;
|
||||
if (options.message) {
|
||||
options.messages[ruleName] = options.message;
|
||||
}
|
||||
}
|
||||
|
||||
function splitAndTrim(value) {
|
||||
return value.replace(/^\s+|\s+$/g, "").split(/\s*,\s*/g);
|
||||
}
|
||||
|
||||
function escapeAttributeValue(value) {
|
||||
// As mentioned on http://api.jquery.com/category/selectors/
|
||||
return value.replace(/([!"#$%&'()*+,./:;<=>?@\[\\\]^`{|}~])/g, "\\$1");
|
||||
}
|
||||
|
||||
function getModelPrefix(fieldName) {
|
||||
return fieldName.substr(0, fieldName.lastIndexOf(".") + 1);
|
||||
}
|
||||
|
||||
function appendModelPrefix(value, prefix) {
|
||||
if (value.indexOf("*.") === 0) {
|
||||
value = value.replace("*.", prefix);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function onError(error, inputElement) { // 'this' is the form element
|
||||
var container = $(this).find("[data-valmsg-for='" + escapeAttributeValue(inputElement[0].name) + "']"),
|
||||
replaceAttrValue = container.attr("data-valmsg-replace"),
|
||||
replace = replaceAttrValue ? $.parseJSON(replaceAttrValue) !== false : null;
|
||||
|
||||
container.removeClass("field-validation-valid").addClass("field-validation-error");
|
||||
error.data("unobtrusiveContainer", container);
|
||||
|
||||
if (replace) {
|
||||
container.empty();
|
||||
error.removeClass("input-validation-error").appendTo(container);
|
||||
}
|
||||
else {
|
||||
error.hide();
|
||||
}
|
||||
}
|
||||
|
||||
function onErrors(event, validator) { // 'this' is the form element
|
||||
var container = $(this).find("[data-valmsg-summary=true]"),
|
||||
list = container.find("ul");
|
||||
|
||||
if (list && list.length && validator.errorList.length) {
|
||||
list.empty();
|
||||
container.addClass("validation-summary-errors").removeClass("validation-summary-valid");
|
||||
|
||||
$.each(validator.errorList, function () {
|
||||
$("<li />").html(this.message).appendTo(list);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function onSuccess(error) { // 'this' is the form element
|
||||
var container = error.data("unobtrusiveContainer");
|
||||
|
||||
if (container) {
|
||||
var replaceAttrValue = container.attr("data-valmsg-replace"),
|
||||
replace = replaceAttrValue ? $.parseJSON(replaceAttrValue) : null;
|
||||
|
||||
container.addClass("field-validation-valid").removeClass("field-validation-error");
|
||||
error.removeData("unobtrusiveContainer");
|
||||
|
||||
if (replace) {
|
||||
container.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onReset(event) { // 'this' is the form element
|
||||
var $form = $(this),
|
||||
key = '__jquery_unobtrusive_validation_form_reset';
|
||||
if ($form.data(key)) {
|
||||
return;
|
||||
}
|
||||
// Set a flag that indicates we're currently resetting the form.
|
||||
$form.data(key, true);
|
||||
try {
|
||||
$form.data("validator").resetForm();
|
||||
} finally {
|
||||
$form.removeData(key);
|
||||
}
|
||||
|
||||
$form.find(".validation-summary-errors")
|
||||
.addClass("validation-summary-valid")
|
||||
.removeClass("validation-summary-errors");
|
||||
$form.find(".field-validation-error")
|
||||
.addClass("field-validation-valid")
|
||||
.removeClass("field-validation-error")
|
||||
.removeData("unobtrusiveContainer")
|
||||
.find(">*") // If we were using valmsg-replace, get the underlying error
|
||||
.removeData("unobtrusiveContainer");
|
||||
}
|
||||
|
||||
function validationInfo(form) {
|
||||
var $form = $(form),
|
||||
result = $form.data(data_validation),
|
||||
onResetProxy = $.proxy(onReset, form),
|
||||
defaultOptions = $jQval.unobtrusive.options || {},
|
||||
execInContext = function (name, args) {
|
||||
var func = defaultOptions[name];
|
||||
func && $.isFunction(func) && func.apply(form, args);
|
||||
};
|
||||
|
||||
if (!result) {
|
||||
result = {
|
||||
options: { // options structure passed to jQuery Validate's validate() method
|
||||
errorClass: defaultOptions.errorClass || "input-validation-error",
|
||||
errorElement: defaultOptions.errorElement || "span",
|
||||
errorPlacement: function () {
|
||||
onError.apply(form, arguments);
|
||||
execInContext("errorPlacement", arguments);
|
||||
},
|
||||
invalidHandler: function () {
|
||||
onErrors.apply(form, arguments);
|
||||
execInContext("invalidHandler", arguments);
|
||||
},
|
||||
messages: {},
|
||||
rules: {},
|
||||
success: function () {
|
||||
onSuccess.apply(form, arguments);
|
||||
execInContext("success", arguments);
|
||||
}
|
||||
},
|
||||
attachValidation: function () {
|
||||
$form
|
||||
.off("reset." + data_validation, onResetProxy)
|
||||
.on("reset." + data_validation, onResetProxy)
|
||||
.validate(this.options);
|
||||
},
|
||||
validate: function () { // a validation function that is called by unobtrusive Ajax
|
||||
$form.validate();
|
||||
return $form.valid();
|
||||
}
|
||||
};
|
||||
$form.data(data_validation, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
$jQval.unobtrusive = {
|
||||
adapters: [],
|
||||
|
||||
parseElement: function (element, skipAttach) {
|
||||
/// <summary>
|
||||
/// Parses a single HTML element for unobtrusive validation attributes.
|
||||
/// </summary>
|
||||
/// <param name="element" domElement="true">The HTML element to be parsed.</param>
|
||||
/// <param name="skipAttach" type="Boolean">[Optional] true to skip attaching the
|
||||
/// validation to the form. If parsing just this single element, you should specify true.
|
||||
/// If parsing several elements, you should specify false, and manually attach the validation
|
||||
/// to the form when you are finished. The default is false.</param>
|
||||
var $element = $(element),
|
||||
form = $element.parents("form")[0],
|
||||
valInfo, rules, messages;
|
||||
|
||||
if (!form) { // Cannot do client-side validation without a form
|
||||
return;
|
||||
}
|
||||
|
||||
valInfo = validationInfo(form);
|
||||
valInfo.options.rules[element.name] = rules = {};
|
||||
valInfo.options.messages[element.name] = messages = {};
|
||||
|
||||
$.each(this.adapters, function () {
|
||||
var prefix = "data-val-" + this.name,
|
||||
message = $element.attr(prefix),
|
||||
paramValues = {};
|
||||
|
||||
if (message !== undefined) { // Compare against undefined, because an empty message is legal (and falsy)
|
||||
prefix += "-";
|
||||
|
||||
$.each(this.params, function () {
|
||||
paramValues[this] = $element.attr(prefix + this);
|
||||
});
|
||||
|
||||
this.adapt({
|
||||
element: element,
|
||||
form: form,
|
||||
message: message,
|
||||
params: paramValues,
|
||||
rules: rules,
|
||||
messages: messages
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$.extend(rules, { "__dummy__": true });
|
||||
|
||||
if (!skipAttach) {
|
||||
valInfo.attachValidation();
|
||||
}
|
||||
},
|
||||
|
||||
parse: function (selector) {
|
||||
/// <summary>
|
||||
/// Parses all the HTML elements in the specified selector. It looks for input elements decorated
|
||||
/// with the [data-val=true] attribute value and enables validation according to the data-val-*
|
||||
/// attribute values.
|
||||
/// </summary>
|
||||
/// <param name="selector" type="String">Any valid jQuery selector.</param>
|
||||
|
||||
// $forms includes all forms in selector's DOM hierarchy (parent, children and self) that have at least one
|
||||
// element with data-val=true
|
||||
var $selector = $(selector),
|
||||
$forms = $selector.parents()
|
||||
.addBack()
|
||||
.filter("form")
|
||||
.add($selector.find("form"))
|
||||
.has("[data-val=true]");
|
||||
|
||||
$selector.find("[data-val=true]").each(function () {
|
||||
$jQval.unobtrusive.parseElement(this, true);
|
||||
});
|
||||
|
||||
$forms.each(function () {
|
||||
var info = validationInfo(this);
|
||||
if (info) {
|
||||
info.attachValidation();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
adapters = $jQval.unobtrusive.adapters;
|
||||
|
||||
adapters.add = function (adapterName, params, fn) {
|
||||
/// <summary>Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation.</summary>
|
||||
/// <param name="adapterName" type="String">The name of the adapter to be added. This matches the name used
|
||||
/// in the data-val-nnnn HTML attribute (where nnnn is the adapter name).</param>
|
||||
/// <param name="params" type="Array" optional="true">[Optional] An array of parameter names (strings) that will
|
||||
/// be extracted from the data-val-nnnn-mmmm HTML attributes (where nnnn is the adapter name, and
|
||||
/// mmmm is the parameter name).</param>
|
||||
/// <param name="fn" type="Function">The function to call, which adapts the values from the HTML
|
||||
/// attributes into jQuery Validate rules and/or messages.</param>
|
||||
/// <returns type="jQuery.validator.unobtrusive.adapters" />
|
||||
if (!fn) { // Called with no params, just a function
|
||||
fn = params;
|
||||
params = [];
|
||||
}
|
||||
this.push({ name: adapterName, params: params, adapt: fn });
|
||||
return this;
|
||||
};
|
||||
|
||||
adapters.addBool = function (adapterName, ruleName) {
|
||||
/// <summary>Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where
|
||||
/// the jQuery Validate validation rule has no parameter values.</summary>
|
||||
/// <param name="adapterName" type="String">The name of the adapter to be added. This matches the name used
|
||||
/// in the data-val-nnnn HTML attribute (where nnnn is the adapter name).</param>
|
||||
/// <param name="ruleName" type="String" optional="true">[Optional] The name of the jQuery Validate rule. If not provided, the value
|
||||
/// of adapterName will be used instead.</param>
|
||||
/// <returns type="jQuery.validator.unobtrusive.adapters" />
|
||||
return this.add(adapterName, function (options) {
|
||||
setValidationValues(options, ruleName || adapterName, true);
|
||||
});
|
||||
};
|
||||
|
||||
adapters.addMinMax = function (adapterName, minRuleName, maxRuleName, minMaxRuleName, minAttribute, maxAttribute) {
|
||||
/// <summary>Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where
|
||||
/// the jQuery Validate validation has three potential rules (one for min-only, one for max-only, and
|
||||
/// one for min-and-max). The HTML parameters are expected to be named -min and -max.</summary>
|
||||
/// <param name="adapterName" type="String">The name of the adapter to be added. This matches the name used
|
||||
/// in the data-val-nnnn HTML attribute (where nnnn is the adapter name).</param>
|
||||
/// <param name="minRuleName" type="String">The name of the jQuery Validate rule to be used when you only
|
||||
/// have a minimum value.</param>
|
||||
/// <param name="maxRuleName" type="String">The name of the jQuery Validate rule to be used when you only
|
||||
/// have a maximum value.</param>
|
||||
/// <param name="minMaxRuleName" type="String">The name of the jQuery Validate rule to be used when you
|
||||
/// have both a minimum and maximum value.</param>
|
||||
/// <param name="minAttribute" type="String" optional="true">[Optional] The name of the HTML attribute that
|
||||
/// contains the minimum value. The default is "min".</param>
|
||||
/// <param name="maxAttribute" type="String" optional="true">[Optional] The name of the HTML attribute that
|
||||
/// contains the maximum value. The default is "max".</param>
|
||||
/// <returns type="jQuery.validator.unobtrusive.adapters" />
|
||||
return this.add(adapterName, [minAttribute || "min", maxAttribute || "max"], function (options) {
|
||||
var min = options.params.min,
|
||||
max = options.params.max;
|
||||
|
||||
if (min && max) {
|
||||
setValidationValues(options, minMaxRuleName, [min, max]);
|
||||
}
|
||||
else if (min) {
|
||||
setValidationValues(options, minRuleName, min);
|
||||
}
|
||||
else if (max) {
|
||||
setValidationValues(options, maxRuleName, max);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
adapters.addSingleVal = function (adapterName, attribute, ruleName) {
|
||||
/// <summary>Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where
|
||||
/// the jQuery Validate validation rule has a single value.</summary>
|
||||
/// <param name="adapterName" type="String">The name of the adapter to be added. This matches the name used
|
||||
/// in the data-val-nnnn HTML attribute(where nnnn is the adapter name).</param>
|
||||
/// <param name="attribute" type="String">[Optional] The name of the HTML attribute that contains the value.
|
||||
/// The default is "val".</param>
|
||||
/// <param name="ruleName" type="String" optional="true">[Optional] The name of the jQuery Validate rule. If not provided, the value
|
||||
/// of adapterName will be used instead.</param>
|
||||
/// <returns type="jQuery.validator.unobtrusive.adapters" />
|
||||
return this.add(adapterName, [attribute || "val"], function (options) {
|
||||
setValidationValues(options, ruleName || adapterName, options.params[attribute]);
|
||||
});
|
||||
};
|
||||
|
||||
$jQval.addMethod("__dummy__", function (value, element, params) {
|
||||
return true;
|
||||
});
|
||||
|
||||
$jQval.addMethod("regex", function (value, element, params) {
|
||||
var match;
|
||||
if (this.optional(element)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
match = new RegExp(params).exec(value);
|
||||
return (match && (match.index === 0) && (match[0].length === value.length));
|
||||
});
|
||||
|
||||
$jQval.addMethod("nonalphamin", function (value, element, nonalphamin) {
|
||||
var match;
|
||||
if (nonalphamin) {
|
||||
match = value.match(/\W/g);
|
||||
match = match && match.length >= nonalphamin;
|
||||
}
|
||||
return match;
|
||||
});
|
||||
|
||||
if ($jQval.methods.extension) {
|
||||
adapters.addSingleVal("accept", "mimtype");
|
||||
adapters.addSingleVal("extension", "extension");
|
||||
} else {
|
||||
// for backward compatibility, when the 'extension' validation method does not exist, such as with versions
|
||||
// of JQuery Validation plugin prior to 1.10, we should use the 'accept' method for
|
||||
// validating the extension, and ignore mime-type validations as they are not supported.
|
||||
adapters.addSingleVal("extension", "extension", "accept");
|
||||
}
|
||||
|
||||
adapters.addSingleVal("regex", "pattern");
|
||||
adapters.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url");
|
||||
adapters.addMinMax("length", "minlength", "maxlength", "rangelength").addMinMax("range", "min", "max", "range");
|
||||
adapters.addMinMax("minlength", "minlength").addMinMax("maxlength", "minlength", "maxlength");
|
||||
adapters.add("equalto", ["other"], function (options) {
|
||||
var prefix = getModelPrefix(options.element.name),
|
||||
other = options.params.other,
|
||||
fullOtherName = appendModelPrefix(other, prefix),
|
||||
element = $(options.form).find(":input").filter("[name='" + escapeAttributeValue(fullOtherName) + "']")[0];
|
||||
|
||||
setValidationValues(options, "equalTo", element);
|
||||
});
|
||||
adapters.add("required", function (options) {
|
||||
// jQuery Validate equates "required" with "mandatory" for checkbox elements
|
||||
if (options.element.tagName.toUpperCase() !== "INPUT" || options.element.type.toUpperCase() !== "CHECKBOX") {
|
||||
setValidationValues(options, "required", true);
|
||||
}
|
||||
});
|
||||
adapters.add("remote", ["url", "type", "additionalfields"], function (options) {
|
||||
var value = {
|
||||
url: options.params.url,
|
||||
type: options.params.type || "GET",
|
||||
data: {}
|
||||
},
|
||||
prefix = getModelPrefix(options.element.name);
|
||||
|
||||
$.each(splitAndTrim(options.params.additionalfields || options.element.name), function (i, fieldName) {
|
||||
var paramName = appendModelPrefix(fieldName, prefix);
|
||||
value.data[paramName] = function () {
|
||||
var field = $(options.form).find(":input").filter("[name='" + escapeAttributeValue(paramName) + "']");
|
||||
// For checkboxes and radio buttons, only pick up values from checked fields.
|
||||
if (field.is(":checkbox")) {
|
||||
return field.filter(":checked").val() || field.filter(":hidden").val() || '';
|
||||
}
|
||||
else if (field.is(":radio")) {
|
||||
return field.filter(":checked").val() || '';
|
||||
}
|
||||
return field.val();
|
||||
};
|
||||
});
|
||||
|
||||
setValidationValues(options, "remote", value);
|
||||
});
|
||||
adapters.add("password", ["min", "nonalphamin", "regex"], function (options) {
|
||||
if (options.params.min) {
|
||||
setValidationValues(options, "minlength", options.params.min);
|
||||
}
|
||||
if (options.params.nonalphamin) {
|
||||
setValidationValues(options, "nonalphamin", options.params.nonalphamin);
|
||||
}
|
||||
if (options.params.regex) {
|
||||
setValidationValues(options, "regex", options.params.regex);
|
||||
}
|
||||
});
|
||||
adapters.add("fileextensions", ["extensions"], function (options) {
|
||||
setValidationValues(options, "extension", options.params.extensions);
|
||||
});
|
||||
|
||||
$(function () {
|
||||
$jQval.unobtrusive.parse(document);
|
||||
});
|
||||
|
||||
return $jQval.unobtrusive;
|
||||
}));
|
File diff suppressed because one or more lines are too long
22
OliverBooth.Admin/wwwroot/lib/jquery-validation/LICENSE.md
Normal file
22
OliverBooth.Admin/wwwroot/lib/jquery-validation/LICENSE.md
Normal file
@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
=====================
|
||||
|
||||
Copyright Jörn Zaefferer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
21
OliverBooth.Admin/wwwroot/lib/jquery/LICENSE.txt
Normal file
21
OliverBooth.Admin/wwwroot/lib/jquery/LICENSE.txt
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
Copyright OpenJS Foundation and other contributors, https://openjsf.org/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
40
OliverBooth.Api/ConfigureSwaggerOptions.cs
Normal file
40
OliverBooth.Api/ConfigureSwaggerOptions.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using Asp.Versioning.ApiExplorer;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
namespace OliverBooth.Api;
|
||||
|
||||
internal sealed class ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider)
|
||||
: IConfigureNamedOptions<SwaggerGenOptions>
|
||||
{
|
||||
public void Configure(SwaggerGenOptions options)
|
||||
{
|
||||
foreach (var description in provider.ApiVersionDescriptions)
|
||||
{
|
||||
options.SwaggerDoc(description.GroupName, CreateVersionInfo(description));
|
||||
}
|
||||
}
|
||||
|
||||
public void Configure(string? name, SwaggerGenOptions options)
|
||||
{
|
||||
Configure(options);
|
||||
}
|
||||
|
||||
private OpenApiInfo CreateVersionInfo(
|
||||
ApiVersionDescription description)
|
||||
{
|
||||
var info = new OpenApiInfo
|
||||
{
|
||||
Title = "api.oliverbooth.dev",
|
||||
Version = description.ApiVersion.ToString()
|
||||
};
|
||||
|
||||
if (description.IsDeprecated)
|
||||
{
|
||||
info.Description += " This API version has been deprecated.";
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
@ -1,13 +1,15 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Reflection;
|
||||
using System.Text.Json.Serialization;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace OliverBooth.Controllers;
|
||||
namespace OliverBooth.Api.Controllers.v1;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/badge")]
|
||||
[Route("v{version:apiVersion}/badge")]
|
||||
[Produces("application/json")]
|
||||
[ApiVersion(1)]
|
||||
public sealed class BadgeController : ControllerBase
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
@ -28,8 +30,17 @@ public sealed class BadgeController : ControllerBase
|
||||
_version = attribute?.InformationalVersion ?? "1.0.0";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a JSON object that is compatible with a shields.io custom endpoint.
|
||||
/// </summary>
|
||||
/// <param name="repo">The repository name.</param>
|
||||
/// <param name="workflow">The workflow.</param>
|
||||
/// <param name="owner">The owner. Defaults to <c>oliverbooth</c>.</param>
|
||||
/// <returns>A JSON object.</returns>
|
||||
[HttpGet("status/{repo}/{workflow}")]
|
||||
[HttpGet("status/{owner}/{repo}/{workflow}")]
|
||||
[EndpointDescription("Returns a JSON object that is compatible with a shields.io custom endpoint.")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> StatusAsync(string repo, string workflow, string owner = "oliverbooth")
|
||||
{
|
||||
string? githubToken = _configuration.GetSection("GitHub:Token").Value;
|
141
OliverBooth.Api/Controllers/v1/Blog/BlogController.cs
Normal file
141
OliverBooth.Api/Controllers/v1/Blog/BlogController.cs
Normal file
@ -0,0 +1,141 @@
|
||||
using Asp.Versioning;
|
||||
using Humanizer;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OliverBooth.Api.Data;
|
||||
using OliverBooth.Common.Data.Blog;
|
||||
using OliverBooth.Common.Data.Web.Users;
|
||||
using OliverBooth.Common.Services;
|
||||
|
||||
namespace OliverBooth.Api.Controllers.v1.Blog;
|
||||
|
||||
[ApiController]
|
||||
[Route("blog")]
|
||||
[Produces("application/json")]
|
||||
[ApiVersion(1)]
|
||||
[Obsolete("API v1 is deprecated and will be removed in future. Use /v2")]
|
||||
public sealed class BlogController : ControllerBase
|
||||
{
|
||||
private readonly IBlogPostService _blogPostService;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BlogController" /> class.
|
||||
/// </summary>
|
||||
/// <param name="blogPostService">The <see cref="IBlogPostService" />.</param>
|
||||
/// <param name="userService">The <see cref="IUserService" />.</param>
|
||||
public BlogController(IBlogPostService blogPostService, IUserService userService)
|
||||
{
|
||||
_blogPostService = blogPostService;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of publicly published blog posts.
|
||||
/// </summary>
|
||||
/// <returns>The number of publicly published blog posts.</returns>
|
||||
[HttpGet("count")]
|
||||
[EndpointDescription("Returns the number of publicly published blog posts.")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public IActionResult Count()
|
||||
{
|
||||
return Ok(new { count = _blogPostService.GetBlogPostCount() });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of all blog posts on the specified page.
|
||||
/// </summary>
|
||||
/// <param name="page">The page number.</param>
|
||||
/// <returns>An array of <see cref="IBlogPost" /> objects.</returns>
|
||||
[HttpGet("posts/{page:int?}")]
|
||||
[EndpointDescription("Returns a collection of all blog posts on the specified page.")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BlogPost[]))]
|
||||
public IActionResult GetAllBlogPosts(int page = 0)
|
||||
{
|
||||
const int itemsPerPage = 10;
|
||||
IReadOnlyList<IBlogPost> allPosts = _blogPostService.GetBlogPosts(page, itemsPerPage);
|
||||
return Ok(allPosts.Select(post => CreatePostObject(post)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of all blog posts which contain the specified tag on the specified page.
|
||||
/// </summary>
|
||||
/// <param name="tag">The tag for which to search.</param>
|
||||
/// <param name="page">The page number.</param>
|
||||
/// <returns>An array of <see cref="IBlogPost" /> objects.</returns>
|
||||
[HttpGet("posts/tagged/{tag}/{page:int?}")]
|
||||
[EndpointDescription("Returns a collection of all blog posts which contain the specified tag on the specified page.")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BlogPost[]))]
|
||||
public IActionResult GetTaggedBlogPosts(string tag, int page = 0)
|
||||
{
|
||||
const int itemsPerPage = 10;
|
||||
tag = tag.Replace('-', ' ').ToLowerInvariant();
|
||||
|
||||
IReadOnlyList<IBlogPost> allPosts = _blogPostService.GetBlogPosts(page, itemsPerPage);
|
||||
allPosts = allPosts.Where(post => post.Tags.Contains(tag)).ToList();
|
||||
return Ok(allPosts.Select(post => CreatePostObject(post)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an object representing the author with the specified ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the author.</param>
|
||||
/// <returns>An object representing the author.</returns>
|
||||
[HttpGet("author/{id:guid}")]
|
||||
[EndpointDescription("Returns an object representing the author with the specified ID.")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(Author))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public IActionResult GetAuthor(Guid id)
|
||||
{
|
||||
if (!_userService.TryGetUser(id, out IUser? author)) return NotFound();
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
id = author.Id,
|
||||
name = author.DisplayName,
|
||||
avatarUrl = author.AvatarUrl,
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an object representing the blog post with the specified ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the blog post.</param>
|
||||
/// <returns>An object representing the blog post.</returns>
|
||||
[HttpGet("post/{id:guid?}")]
|
||||
[EndpointDescription("Returns an object representing the blog post with the specified ID.")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BlogPost))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public IActionResult GetPost(Guid id)
|
||||
{
|
||||
if (!_blogPostService.TryGetPost(id, out IBlogPost? post)) return NotFound();
|
||||
return Ok(CreatePostObject(post, true));
|
||||
}
|
||||
|
||||
private object CreatePostObject(IBlogPost post, bool includeContent = false)
|
||||
{
|
||||
return new
|
||||
{
|
||||
id = post.Id,
|
||||
commentsEnabled = post.EnableComments,
|
||||
identifier = post.GetDisqusIdentifier(),
|
||||
author = post.Author.Id,
|
||||
title = post.Title,
|
||||
published = post.Published.ToUnixTimeSeconds(),
|
||||
updated = post.Updated?.ToUnixTimeSeconds(),
|
||||
formattedPublishDate = post.Published.ToString("dddd, d MMMM yyyy HH:mm"),
|
||||
formattedUpdateDate = post.Updated?.ToString("dddd, d MMMM yyyy HH:mm"),
|
||||
humanizedTimestamp = post.Updated?.Humanize() ?? post.Published.Humanize(),
|
||||
excerpt = _blogPostService.RenderExcerpt(post, out bool trimmed),
|
||||
content = includeContent ? _blogPostService.RenderPost(post) : null,
|
||||
trimmed,
|
||||
tags = post.Tags.Select(t => t.Replace(' ', '-')),
|
||||
url = new
|
||||
{
|
||||
year = post.Published.ToString("yyyy"),
|
||||
month = post.Published.ToString("MM"),
|
||||
day = post.Published.ToString("dd"),
|
||||
slug = post.Slug
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
112
OliverBooth.Api/Controllers/v2/BadgeController.cs
Normal file
112
OliverBooth.Api/Controllers/v2/BadgeController.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Reflection;
|
||||
using System.Text.Json.Serialization;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace OliverBooth.Api.Controllers.v2;
|
||||
|
||||
[ApiController]
|
||||
[Route("v{version:apiVersion}/badge")]
|
||||
[Produces("application/json")]
|
||||
[ApiVersion(2)]
|
||||
public sealed class BadgeController : ControllerBase
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly string _version;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BadgeController" /> class.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration.</param>
|
||||
/// <param name="httpClientFactory">The HTTP client factory.</param>
|
||||
public BadgeController(IConfiguration configuration, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
|
||||
var attribute = typeof(Program).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
||||
_version = attribute?.InformationalVersion ?? "1.0.0";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a JSON object that is compatible with a shields.io custom endpoint.
|
||||
/// </summary>
|
||||
/// <param name="repo">The repository name.</param>
|
||||
/// <param name="workflow">The workflow.</param>
|
||||
/// <param name="owner">The owner. Defaults to <c>oliverbooth</c>.</param>
|
||||
/// <returns>A JSON object.</returns>
|
||||
[HttpGet("status/{repo}/{workflow}")]
|
||||
[HttpGet("status/{owner}/{repo}/{workflow}")]
|
||||
[EndpointDescription("Returns a JSON object that is compatible with a shields.io custom endpoint.")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> StatusAsync(string repo, string workflow, string owner = "oliverbooth")
|
||||
{
|
||||
string? githubToken = _configuration.GetSection("GitHub:Token").Value;
|
||||
|
||||
var url = $"https://api.github.com/repos/{owner}/{repo}/actions/workflows/{workflow}/runs";
|
||||
Console.WriteLine(url);
|
||||
using HttpClient client = _httpClientFactory.CreateClient();
|
||||
using var request = new HttpRequestMessage();
|
||||
request.RequestUri = new Uri(url);
|
||||
request.Headers.Add("Accept", "application/json");
|
||||
request.Headers.Add("Authorization", $"Bearer {githubToken}");
|
||||
request.Headers.Add("X-GitHub-Api-Version", "2022-11-28");
|
||||
request.Headers.UserAgent.Add(new ProductInfoHeaderValue("oliverbooth.dev", _version));
|
||||
|
||||
using HttpResponseMessage response = await client.SendAsync(request);
|
||||
Console.WriteLine(await response.Content.ReadAsStringAsync());
|
||||
var body = await response.Content.ReadFromJsonAsync<WorkflowRunSchema>();
|
||||
WorkflowRun? run = body?.WorkflowRuns.FirstOrDefault(r => r.Status == WorkflowRunStatus.Completed);
|
||||
if (run is not null)
|
||||
{
|
||||
var color = run.Conclusion switch
|
||||
{
|
||||
WorkflowRunConclusion.Failure => "e05d44",
|
||||
WorkflowRunConclusion.Success => "44cc11",
|
||||
_ => "lightgray"
|
||||
};
|
||||
var message = run.Conclusion switch
|
||||
{
|
||||
WorkflowRunConclusion.Failure => "failing",
|
||||
WorkflowRunConclusion.Success => "passing",
|
||||
_ => "unknown"
|
||||
};
|
||||
|
||||
return Ok(new { schemaVersion = 1, label = "build", color, message });
|
||||
}
|
||||
|
||||
return Ok(new { schemaVersion = 1, label = "build", color = "lightgray", message = "unknown" });
|
||||
}
|
||||
|
||||
private class WorkflowRunSchema
|
||||
{
|
||||
[JsonPropertyName("workflow_runs"), JsonInclude]
|
||||
public WorkflowRun[] WorkflowRuns { get; set; } = Array.Empty<WorkflowRun>();
|
||||
}
|
||||
|
||||
private class WorkflowRun
|
||||
{
|
||||
[JsonPropertyName("conclusion"), JsonInclude]
|
||||
[JsonConverter(typeof(JsonStringEnumConverter<WorkflowRunConclusion>))]
|
||||
public WorkflowRunConclusion Conclusion { get; set; } = WorkflowRunConclusion.Unknown;
|
||||
|
||||
[JsonPropertyName("status"), JsonInclude]
|
||||
[JsonConverter(typeof(JsonStringEnumConverter<WorkflowRunStatus>))]
|
||||
public WorkflowRunStatus Status { get; set; } = WorkflowRunStatus.Unknown;
|
||||
}
|
||||
|
||||
private enum WorkflowRunStatus
|
||||
{
|
||||
Unknown = -1,
|
||||
Completed
|
||||
}
|
||||
|
||||
private enum WorkflowRunConclusion
|
||||
{
|
||||
Unknown = -1,
|
||||
Success,
|
||||
Failure
|
||||
}
|
||||
}
|
47
OliverBooth.Api/Controllers/v2/Blog/AuthorController.cs
Normal file
47
OliverBooth.Api/Controllers/v2/Blog/AuthorController.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OliverBooth.Api.Data;
|
||||
using OliverBooth.Common.Data.Web.Users;
|
||||
using OliverBooth.Common.Services;
|
||||
|
||||
namespace OliverBooth.Api.Controllers.v2.Blog;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an API controller which allows reading authors of blog posts.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("v{version:apiVersion}/blog/author")]
|
||||
[Produces("application/json")]
|
||||
[ApiVersion(2)]
|
||||
public sealed class AuthorController : ControllerBase
|
||||
{
|
||||
private readonly IUserService _userService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AuthorController" /> class.
|
||||
/// </summary>
|
||||
/// <param name="userService">The <see cref="IUserService" />.</param>
|
||||
public AuthorController(IUserService userService)
|
||||
{
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an object representing the author with the specified ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the author.</param>
|
||||
/// <returns>An object representing the author.</returns>
|
||||
[HttpGet("{id:guid}")]
|
||||
[EndpointDescription("Returns an object representing the author with the specified ID.")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(Author))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public IActionResult GetAuthor(Guid id)
|
||||
{
|
||||
if (!_userService.TryGetUser(id, out IUser? author))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return Ok(Author.FromUser(author));
|
||||
}
|
||||
}
|
92
OliverBooth.Api/Controllers/v2/Blog/PostController.cs
Normal file
92
OliverBooth.Api/Controllers/v2/Blog/PostController.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OliverBooth.Api.Data;
|
||||
using OliverBooth.Common.Data.Blog;
|
||||
using OliverBooth.Common.Services;
|
||||
|
||||
namespace OliverBooth.Api.Controllers.v2.Blog;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an API controller which allows reading and writing of blog posts.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("v{version:apiVersion}/blog/post")]
|
||||
[Produces("application/json")]
|
||||
[ApiVersion(2)]
|
||||
public sealed class PostController : ControllerBase
|
||||
{
|
||||
private const int ItemsPerPage = 10;
|
||||
private readonly IBlogPostService _blogPostService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PostController" /> class.
|
||||
/// </summary>
|
||||
/// <param name="blogPostService">The <see cref="IBlogPostService" />.</param>
|
||||
public PostController(IBlogPostService blogPostService)
|
||||
{
|
||||
_blogPostService = blogPostService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of all blog posts on the specified page.
|
||||
/// </summary>
|
||||
/// <param name="page">The page number.</param>
|
||||
/// <returns>An array of <see cref="IBlogPost" /> objects.</returns>
|
||||
[HttpGet("all/{page:int?}")]
|
||||
[EndpointDescription("Returns a collection of all blog posts on the specified page.")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BlogPost[]))]
|
||||
public IActionResult All(int page = 0)
|
||||
{
|
||||
IReadOnlyList<IBlogPost> allPosts = _blogPostService.GetBlogPosts(page, ItemsPerPage);
|
||||
return Ok(allPosts.Select(post => BlogPost.FromBlogPost(post, _blogPostService)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of publicly published blog posts.
|
||||
/// </summary>
|
||||
/// <returns>The number of publicly published blog posts.</returns>
|
||||
[HttpGet("count")]
|
||||
[EndpointDescription("Returns the number of publicly published blog posts.")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public IActionResult Count()
|
||||
{
|
||||
return Ok(new { count = _blogPostService.GetBlogPostCount() });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an object representing the blog post with the specified ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the blog post.</param>
|
||||
/// <returns>An object representing the blog post.</returns>
|
||||
[HttpGet("{id:guid}")]
|
||||
[EndpointDescription("Returns an object representing the blog post with the specified ID.")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BlogPost))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public IActionResult GetPost(Guid id)
|
||||
{
|
||||
if (!_blogPostService.TryGetPost(id, out IBlogPost? post))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return Ok(BlogPost.FromBlogPost(post, _blogPostService, true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of all blog posts which contain the specified tag on the specified page.
|
||||
/// </summary>
|
||||
/// <param name="tag">The tag for which to search.</param>
|
||||
/// <param name="page">The page number.</param>
|
||||
/// <returns>An array of <see cref="IBlogPost" /> objects.</returns>
|
||||
[HttpGet("tagged/{tag}/{page:int?}")]
|
||||
[EndpointDescription("Returns a collection of all blog posts which contain the specified tag on the specified page.")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BlogPost[]))]
|
||||
public IActionResult Tagged(string tag, int page = 0)
|
||||
{
|
||||
tag = tag.Replace('-', ' ').ToLowerInvariant();
|
||||
|
||||
IReadOnlyList<IBlogPost> allPosts = _blogPostService.GetBlogPosts(page, ItemsPerPage);
|
||||
allPosts = allPosts.Where(post => post.Tags.Contains(tag)).ToList();
|
||||
return Ok(allPosts.Select(post => BlogPost.FromBlogPost(post, _blogPostService)));
|
||||
}
|
||||
}
|
26
OliverBooth.Api/Data/Author.cs
Normal file
26
OliverBooth.Api/Data/Author.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using OliverBooth.Common.Data.Web.Users;
|
||||
|
||||
namespace OliverBooth.Api.Data;
|
||||
|
||||
internal sealed class Author
|
||||
{
|
||||
[JsonPropertyName("avatarUrl"), JsonInclude, JsonPropertyOrder(2)]
|
||||
public Uri AvatarUrl { get; private set; } = null!;
|
||||
|
||||
[JsonPropertyName("id"), JsonInclude, JsonPropertyOrder(0)]
|
||||
public Guid Id { get; private set; }
|
||||
|
||||
[JsonPropertyName("name"), JsonInclude, JsonPropertyOrder(1)]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
public static Author FromUser(IUser author)
|
||||
{
|
||||
return new Author
|
||||
{
|
||||
Id = author.Id,
|
||||
Name = author.DisplayName,
|
||||
AvatarUrl = author.AvatarUrl
|
||||
};
|
||||
}
|
||||
}
|
83
OliverBooth.Api/Data/BlogPost.cs
Normal file
83
OliverBooth.Api/Data/BlogPost.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Humanizer;
|
||||
using OliverBooth.Common.Data.Blog;
|
||||
using OliverBooth.Common.Services;
|
||||
|
||||
namespace OliverBooth.Api.Data;
|
||||
|
||||
internal sealed class BlogPost
|
||||
{
|
||||
[JsonPropertyName("author"), JsonInclude, JsonPropertyOrder(3)]
|
||||
public Guid Author { get; private set; }
|
||||
|
||||
[JsonPropertyName("commentsEnabled"), JsonInclude, JsonPropertyOrder(1)]
|
||||
public bool CommentsEnabled { get; private set; }
|
||||
|
||||
[JsonPropertyName("content"), JsonInclude, JsonPropertyOrder(11)]
|
||||
public string? Content { get; private set; }
|
||||
|
||||
[JsonPropertyName("excerpt"), JsonInclude, JsonPropertyOrder(10)]
|
||||
public string Excerpt { get; private set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("formattedPublishDate"), JsonInclude, JsonPropertyOrder(7)]
|
||||
public string FormattedPublishDate { get; private set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("formattedUpdateDate"), JsonInclude, JsonPropertyOrder(8)]
|
||||
public string? FormattedUpdateDate { get; private set; }
|
||||
|
||||
[JsonPropertyName("humanizedTimestamp"), JsonInclude, JsonPropertyOrder(9)]
|
||||
public string HumanizedTimestamp { get; private set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("id"), JsonInclude, JsonPropertyOrder(0)]
|
||||
public Guid Id { get; private set; }
|
||||
|
||||
[JsonPropertyName("identifier"), JsonInclude, JsonPropertyOrder(2)]
|
||||
public string Identifier { get; private set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("trimmed"), JsonInclude, JsonPropertyOrder(12)]
|
||||
public bool IsTrimmed { get; private set; }
|
||||
|
||||
[JsonPropertyName("published"), JsonInclude, JsonPropertyOrder(5)]
|
||||
public long Published { get; private set; }
|
||||
|
||||
[JsonPropertyName("tags"), JsonInclude, JsonPropertyOrder(13)]
|
||||
public IEnumerable<string> Tags { get; private set; } = ArraySegment<string>.Empty;
|
||||
|
||||
[JsonPropertyName("title"), JsonInclude, JsonPropertyOrder(4)]
|
||||
public string Title { get; private set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("updated"), JsonInclude, JsonPropertyOrder(6)]
|
||||
public long? Updated { get; private set; }
|
||||
|
||||
[JsonPropertyName("url"), JsonInclude, JsonPropertyOrder(14)]
|
||||
public object Url { get; private set; } = null!;
|
||||
|
||||
public static BlogPost FromBlogPost(IBlogPost post, IBlogPostService blogPostService,
|
||||
bool includeContent = false)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Id = post.Id,
|
||||
CommentsEnabled = post.EnableComments,
|
||||
Identifier = post.GetDisqusIdentifier(),
|
||||
Author = post.Author.Id,
|
||||
Title = post.Title,
|
||||
Published = post.Published.ToUnixTimeSeconds(),
|
||||
Updated = post.Updated?.ToUnixTimeSeconds(),
|
||||
FormattedPublishDate = post.Published.ToString("dddd, d MMMM yyyy HH:mm"),
|
||||
FormattedUpdateDate = post.Updated?.ToString("dddd, d MMMM yyyy HH:mm"),
|
||||
HumanizedTimestamp = post.Updated?.Humanize() ?? post.Published.Humanize(),
|
||||
Excerpt = blogPostService.RenderExcerpt(post, out bool trimmed),
|
||||
Content = includeContent ? blogPostService.RenderPost(post) : null,
|
||||
IsTrimmed = trimmed,
|
||||
Tags = post.Tags.Select(t => t.Replace(' ', '-')),
|
||||
Url = new
|
||||
{
|
||||
year = post.Published.ToString("yyyy"),
|
||||
month = post.Published.ToString("MM"),
|
||||
day = post.Published.ToString("dd"),
|
||||
slug = post.Slug
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
22
OliverBooth.Api/Dockerfile
Normal file
22
OliverBooth.Api/Dockerfile
Normal file
@ -0,0 +1,22 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
USER $APP_UID
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["OliverBooth.Api/OliverBooth.Api.csproj", "OliverBooth.Api/"]
|
||||
COPY . .
|
||||
|
||||
WORKDIR "/src/OliverBooth.Api"
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "OliverBooth.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "OliverBooth.Api.dll"]
|
38
OliverBooth.Api/OliverBooth.Api.csproj
Normal file
38
OliverBooth.Api/OliverBooth.Api.csproj
Normal file
@ -0,0 +1,38 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<VersionPrefix>2.0.0</VersionPrefix>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(VersionSuffix)' != '' And '$(BuildNumber)' == ''">
|
||||
<Version>$(VersionPrefix)-$(VersionSuffix)</Version>
|
||||
<AssemblyVersion>$(VersionPrefix).0</AssemblyVersion>
|
||||
<FileVersion>$(VersionPrefix).0</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(VersionSuffix)' != '' And '$(BuildNumber)' != ''">
|
||||
<Version>$(VersionPrefix)-$(VersionSuffix).$(BuildNumber)</Version>
|
||||
<AssemblyVersion>$(VersionPrefix).$(BuildNumber)</AssemblyVersion>
|
||||
<FileVersion>$(VersionPrefix).$(BuildNumber)</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(VersionSuffix)' == ''">
|
||||
<Version>$(VersionPrefix)</Version>
|
||||
<AssemblyVersion>$(VersionPrefix).0</AssemblyVersion>
|
||||
<FileVersion>$(VersionPrefix).0</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.0.0"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2"/>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OliverBooth.Common\OliverBooth.Common.csproj"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
7
OliverBooth.Api/OliverBooth.Api.http
Normal file
7
OliverBooth.Api/OliverBooth.Api.http
Normal file
@ -0,0 +1,7 @@
|
||||
@OliverBooth.Api_HostAddress = https://localhost:2844
|
||||
@TestPostId = bdcd9789-f0a6-4721-a66d-b6f7e2acd0f7
|
||||
|
||||
GET {{OliverBooth.Api_HostAddress}}/v1/blog/post/{{TestPostId}}
|
||||
Accept: application/json
|
||||
|
||||
###
|
84
OliverBooth.Api/Program.cs
Normal file
84
OliverBooth.Api/Program.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using Asp.Versioning;
|
||||
using Asp.Versioning.ApiExplorer;
|
||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using OliverBooth.Api;
|
||||
using OliverBooth.Common.Extensions;
|
||||
using Serilog;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.Console()
|
||||
.WriteTo.File("logs/latest.log", rollingInterval: RollingInterval.Day)
|
||||
#if DEBUG
|
||||
.MinimumLevel.Debug()
|
||||
#endif
|
||||
.CreateLogger();
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
builder.Configuration.AddTomlFile("data/config.toml", true, true);
|
||||
builder.Logging.ClearProviders();
|
||||
builder.Logging.AddSerilog();
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("localhost", policy => policy.WithOrigins("https://localhost:2843", "https://localhost:2845"));
|
||||
options.AddPolicy("site", policy => policy.WithOrigins("https://admin.oliverbooth.dev", "https://oliverbooth.dev"));
|
||||
});
|
||||
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddCommonServices();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(options => options.ResolveConflictingActions(resolver =>
|
||||
{
|
||||
foreach (ApiDescription description in resolver)
|
||||
{
|
||||
if (description.GetApiVersion()?.MajorVersion == 2)
|
||||
{
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}));
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddRouting(options => options.LowercaseUrls = true);
|
||||
builder.Services.AddApiVersioning(options =>
|
||||
{
|
||||
options.AssumeDefaultVersionWhenUnspecified = true;
|
||||
options.DefaultApiVersion = new ApiVersion(2);
|
||||
options.ReportApiVersions = true;
|
||||
options.ApiVersionReader = new UrlSegmentApiVersionReader();
|
||||
}).AddApiExplorer(options =>
|
||||
{
|
||||
options.GroupNameFormat = "'v'VVV";
|
||||
options.SubstituteApiVersionInUrl = true;
|
||||
});
|
||||
|
||||
builder.Services.ConfigureOptions<ConfigureSwaggerOptions>();
|
||||
|
||||
if (builder.Environment.IsProduction())
|
||||
{
|
||||
builder.WebHost.AddCertificateFromEnvironment(2844, 5048);
|
||||
}
|
||||
|
||||
WebApplication app = builder.Build();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(options =>
|
||||
{
|
||||
var provider = app.Services.GetRequiredService<IApiVersionDescriptionProvider>();
|
||||
foreach (ApiVersionDescription description in provider.ApiVersionDescriptions)
|
||||
{
|
||||
var url = $"/swagger/{description.GroupName}/swagger.json";
|
||||
options.SwaggerEndpoint(url, description.GroupName.ToUpperInvariant());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.MapControllers();
|
||||
app.UseCors(app.Environment.IsDevelopment() ? "localhost" : "site");
|
||||
|
||||
app.Run();
|
@ -1,7 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using OliverBooth.Data.Blog.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using OliverBooth.Common.Data.Blog.Configuration;
|
||||
|
||||
namespace OliverBooth.Data.Blog;
|
||||
namespace OliverBooth.Common.Data.Blog;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a session with the blog database.
|
||||
@ -26,16 +27,10 @@ internal sealed class BlogContext : DbContext
|
||||
public DbSet<BlogPost> BlogPosts { get; private set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of legacy comments in the database.
|
||||
/// Gets the collection of blog posts drafts in the database.
|
||||
/// </summary>
|
||||
/// <value>The collection of legacy comments.</value>
|
||||
public DbSet<LegacyComment> LegacyComments { get; private set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of users in the database.
|
||||
/// </summary>
|
||||
/// <value>The collection of users.</value>
|
||||
public DbSet<User> Users { get; private set; } = null!;
|
||||
/// <value>The collection of blog post drafts.</value>
|
||||
public DbSet<BlogPostDraft> BlogPostDrafts { get; private set; } = null!;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
@ -49,7 +44,6 @@ internal sealed class BlogContext : DbContext
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.ApplyConfiguration(new BlogPostConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new LegacyCommentConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new UserConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new BlogPostDraftConfiguration());
|
||||
}
|
||||
}
|
@ -1,26 +1,21 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using OliverBooth.Common.Data;
|
||||
using OliverBooth.Common.Data.Blog;
|
||||
using SmartFormat;
|
||||
|
||||
namespace OliverBooth.Data.Blog;
|
||||
namespace OliverBooth.Common.Data.Blog;
|
||||
|
||||
/// <inheritdoc />
|
||||
internal sealed class BlogPost : IBlogPost
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[NotMapped]
|
||||
public IBlogAuthor Author { get; internal set; } = null!;
|
||||
public IAuthor Author { get; internal set; } = null!;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Body { get; internal set; } = string.Empty;
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool EnableComments { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string? Excerpt { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Guid Id { get; private set; } = Guid.NewGuid();
|
||||
|
||||
@ -43,13 +38,13 @@ internal sealed class BlogPost : IBlogPost
|
||||
public IReadOnlyList<string> Tags { get; internal set; } = ArraySegment<string>.Empty;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Title { get; internal set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset? Updated { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Visibility Visibility { get; internal set; }
|
||||
public BlogPostVisibility Visibility { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public int? WordPressId { get; set; }
|
126
OliverBooth.Common/Data/Blog/BlogPostDraft.cs
Normal file
126
OliverBooth.Common/Data/Blog/BlogPostDraft.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using SmartFormat;
|
||||
|
||||
namespace OliverBooth.Common.Data.Blog;
|
||||
|
||||
/// <inheritdoc />
|
||||
internal sealed class BlogPostDraft : IBlogPostDraft
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[NotMapped]
|
||||
public IAuthor Author { get; internal set; } = null!;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool EnableComments { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Guid Id { get; private set; } = Guid.NewGuid();
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsRedirect { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string? Password { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Uri? RedirectUrl { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Slug { get; internal set; } = string.Empty;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<string> Tags { get; internal set; } = ArraySegment<string>.Empty;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset Updated { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public BlogPostVisibility Visibility { get; internal set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public int? WordPressId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ID of the author of this blog post.
|
||||
/// </summary>
|
||||
/// <value>The ID of the author of this blog post.</value>
|
||||
internal Guid AuthorId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the base URL of the Disqus comments for the blog post.
|
||||
/// </summary>
|
||||
/// <value>The Disqus base URL.</value>
|
||||
internal string? DisqusDomain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the identifier of the Disqus comments for the blog post.
|
||||
/// </summary>
|
||||
/// <value>The Disqus identifier.</value>
|
||||
internal string? DisqusIdentifier { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the URL path of the Disqus comments for the blog post.
|
||||
/// </summary>
|
||||
/// <value>The Disqus URL path.</value>
|
||||
internal string? DisqusPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a <see cref="BlogPostDraft" /> by copying values from an existing <see cref="BlogPost" />.
|
||||
/// </summary>
|
||||
/// <param name="post">The existing <see cref="BlogPost" />.</param>
|
||||
/// <returns>The newly-constructed <see cref="BlogPostDraft" />.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="post" /> is <see langword="null" />.</exception>
|
||||
public static BlogPostDraft CreateFromBlogPost(BlogPost post)
|
||||
{
|
||||
if (post is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(post));
|
||||
}
|
||||
|
||||
return new BlogPostDraft
|
||||
{
|
||||
AuthorId = post.AuthorId,
|
||||
Body = post.Body,
|
||||
DisqusDomain = post.DisqusDomain,
|
||||
DisqusIdentifier = post.DisqusIdentifier,
|
||||
DisqusPath = post.DisqusPath,
|
||||
EnableComments = post.EnableComments,
|
||||
IsRedirect = post.IsRedirect,
|
||||
Password = post.Password,
|
||||
RedirectUrl = post.RedirectUrl,
|
||||
Tags = post.Tags,
|
||||
Title = post.Title,
|
||||
Visibility = post.Visibility,
|
||||
WordPressId = post.WordPressId
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Disqus domain for the blog post.
|
||||
/// </summary>
|
||||
/// <returns>The Disqus domain.</returns>
|
||||
public string GetDisqusDomain()
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(DisqusDomain)
|
||||
? "https://oliverbooth.dev/blog"
|
||||
: Smart.Format(DisqusDomain, this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string GetDisqusIdentifier()
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(DisqusIdentifier) ? $"post-{Id}" : Smart.Format(DisqusIdentifier, this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string GetDisqusPostId()
|
||||
{
|
||||
return WordPressId?.ToString() ?? Id.ToString();
|
||||
}
|
||||
}
|
@ -1,15 +1,10 @@
|
||||
namespace OliverBooth.Common.Data;
|
||||
namespace OliverBooth.Common.Data.Blog;
|
||||
|
||||
/// <summary>
|
||||
/// An enumeration of the possible visibilities of a blog post.
|
||||
/// </summary>
|
||||
public enum Visibility
|
||||
public enum BlogPostVisibility
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for filtering results. Represents all visibilities.
|
||||
/// </summary>
|
||||
None = -1,
|
||||
|
||||
/// <summary>
|
||||
/// The post is private and only visible to the author, or those with the password.
|
||||
/// </summary>
|
@ -1,9 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using OliverBooth.Common.Data;
|
||||
|
||||
namespace OliverBooth.Data.Blog.Configuration;
|
||||
namespace OliverBooth.Common.Data.Blog.Configuration;
|
||||
|
||||
internal sealed class BlogPostConfiguration : IEntityTypeConfiguration<BlogPost>
|
||||
{
|
||||
@ -21,14 +20,13 @@ internal sealed class BlogPostConfiguration : IEntityTypeConfiguration<BlogPost>
|
||||
builder.Property(e => e.Updated).IsRequired(false);
|
||||
builder.Property(e => e.Title).HasMaxLength(255).IsRequired();
|
||||
builder.Property(e => e.Body).IsRequired();
|
||||
builder.Property(e => e.Excerpt).HasMaxLength(512).IsRequired(false);
|
||||
builder.Property(e => e.IsRedirect).IsRequired();
|
||||
builder.Property(e => e.RedirectUrl).HasConversion<UriToStringConverter>().HasMaxLength(255).IsRequired(false);
|
||||
builder.Property(e => e.EnableComments).IsRequired();
|
||||
builder.Property(e => e.DisqusDomain).IsRequired(false);
|
||||
builder.Property(e => e.DisqusIdentifier).IsRequired(false);
|
||||
builder.Property(e => e.DisqusPath).IsRequired(false);
|
||||
builder.Property(e => e.Visibility).HasConversion(new EnumToStringConverter<Visibility>()).IsRequired();
|
||||
builder.Property(e => e.Visibility).HasConversion(new EnumToStringConverter<BlogPostVisibility>()).IsRequired();
|
||||
builder.Property(e => e.Password).HasMaxLength(255).IsRequired(false);
|
||||
builder.Property(e => e.Tags).IsRequired()
|
||||
.HasConversion(
|
@ -0,0 +1,36 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace OliverBooth.Common.Data.Blog.Configuration;
|
||||
|
||||
internal sealed class BlogPostDraftConfiguration : IEntityTypeConfiguration<BlogPostDraft>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void Configure(EntityTypeBuilder<BlogPostDraft> builder)
|
||||
{
|
||||
builder.ToTable("BlogPostDraft");
|
||||
builder.HasKey(e => new { e.Id, e.Updated });
|
||||
|
||||
builder.Property(e => e.Id);
|
||||
builder.Property(e => e.Updated).IsRequired();
|
||||
builder.Property(e => e.WordPressId).IsRequired(false);
|
||||
builder.Property(e => e.Slug).HasMaxLength(100).IsRequired();
|
||||
builder.Property(e => e.AuthorId).IsRequired();
|
||||
builder.Property(e => e.Title).HasMaxLength(255).IsRequired();
|
||||
builder.Property(e => e.Body).IsRequired();
|
||||
builder.Property(e => e.IsRedirect).IsRequired();
|
||||
builder.Property(e => e.RedirectUrl).HasConversion<UriToStringConverter>().HasMaxLength(255).IsRequired(false);
|
||||
builder.Property(e => e.EnableComments).IsRequired();
|
||||
builder.Property(e => e.DisqusDomain).IsRequired(false);
|
||||
builder.Property(e => e.DisqusIdentifier).IsRequired(false);
|
||||
builder.Property(e => e.DisqusPath).IsRequired(false);
|
||||
builder.Property(e => e.Visibility).HasConversion(new EnumToStringConverter<BlogPostVisibility>()).IsRequired();
|
||||
builder.Property(e => e.Password).HasMaxLength(255).IsRequired(false);
|
||||
builder.Property(e => e.Tags).IsRequired()
|
||||
.HasConversion(
|
||||
tags => string.Join(' ', tags.Select(t => t.Replace(' ', '-'))),
|
||||
tags => tags.Split(' ', StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(t => t.Replace('-', ' ')).ToArray());
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ namespace OliverBooth.Common.Data.Blog;
|
||||
/// <summary>
|
||||
/// Represents the author of a blog post.
|
||||
/// </summary>
|
||||
public interface IBlogAuthor
|
||||
public interface IAuthor
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the URL of the author's avatar.
|
@ -9,13 +9,13 @@ public interface IBlogPost
|
||||
/// Gets the author of the post.
|
||||
/// </summary>
|
||||
/// <value>The author of the post.</value>
|
||||
IBlogAuthor Author { get; }
|
||||
IAuthor Author { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the body of the post.
|
||||
/// Gets or sets the body of the post.
|
||||
/// </summary>
|
||||
/// <value>The body of the post.</value>
|
||||
string Body { get; }
|
||||
string Body { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether comments are enabled for the post.
|
||||
@ -25,12 +25,6 @@ public interface IBlogPost
|
||||
/// </value>
|
||||
bool EnableComments { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the excerpt of this post, if it has one.
|
||||
/// </summary>
|
||||
/// <value>The excerpt, or <see langword="null" /> if this post has no excerpt.</value>
|
||||
string? Excerpt { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the post.
|
||||
/// </summary>
|
||||
@ -76,10 +70,10 @@ public interface IBlogPost
|
||||
IReadOnlyList<string> Tags { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of the post.
|
||||
/// Gets or sets the title of the post.
|
||||
/// </summary>
|
||||
/// <value>The title of the post.</value>
|
||||
string Title { get; }
|
||||
string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time the post was last updated.
|
||||
@ -91,7 +85,7 @@ public interface IBlogPost
|
||||
/// Gets the visibility of the post.
|
||||
/// </summary>
|
||||
/// <value>The visibility of the post.</value>
|
||||
Visibility Visibility { get; }
|
||||
BlogPostVisibility Visibility { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the WordPress ID of the post.
|
||||
|
103
OliverBooth.Common/Data/Blog/IBlogPostDraft.cs
Normal file
103
OliverBooth.Common/Data/Blog/IBlogPostDraft.cs
Normal file
@ -0,0 +1,103 @@
|
||||
namespace OliverBooth.Common.Data.Blog;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a draft of a blog post.
|
||||
/// </summary>
|
||||
public interface IBlogPostDraft
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the author of the post.
|
||||
/// </summary>
|
||||
/// <value>The author of the post.</value>
|
||||
IAuthor Author { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body of the post.
|
||||
/// </summary>
|
||||
/// <value>The body of the post.</value>
|
||||
string Body { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether comments are enabled for the post.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <see langword="true" /> if comments are enabled for the post; otherwise, <see langword="false" />.
|
||||
/// </value>
|
||||
bool EnableComments { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the post.
|
||||
/// </summary>
|
||||
/// <value>The ID of the post.</value>
|
||||
Guid Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the post redirects to another URL.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <see langword="true" /> if the post redirects to another URL; otherwise, <see langword="false" />.
|
||||
/// </value>
|
||||
bool IsRedirect { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the password of the post.
|
||||
/// </summary>
|
||||
/// <value>The password of the post.</value>
|
||||
string? Password { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URL to which the post redirects.
|
||||
/// </summary>
|
||||
/// <value>The URL to which the post redirects, or <see langword="null" /> if the post does not redirect.</value>
|
||||
Uri? RedirectUrl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the slug of the post.
|
||||
/// </summary>
|
||||
/// <value>The slug of the post.</value>
|
||||
string Slug { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tags of the post.
|
||||
/// </summary>
|
||||
/// <value>The tags of the post.</value>
|
||||
IReadOnlyList<string> Tags { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the post.
|
||||
/// </summary>
|
||||
/// <value>The title of the post.</value>
|
||||
string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time the post was last updated.
|
||||
/// </summary>
|
||||
/// <value>The update date and time.</value>
|
||||
DateTimeOffset Updated { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the visibility of the post.
|
||||
/// </summary>
|
||||
/// <value>The visibility of the post.</value>
|
||||
BlogPostVisibility Visibility { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the WordPress ID of the post.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The WordPress ID of the post, or <see langword="null" /> if the post was not imported from WordPress.
|
||||
/// </value>
|
||||
int? WordPressId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Disqus identifier for the post.
|
||||
/// </summary>
|
||||
/// <returns>The Disqus identifier for the post.</returns>
|
||||
string GetDisqusIdentifier();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Disqus post ID for the post.
|
||||
/// </summary>
|
||||
/// <returns>The Disqus post ID for the post.</returns>
|
||||
string GetDisqusPostId();
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
namespace OliverBooth.Common.Data.Blog;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a comment that was posted on a legacy comment framework.
|
||||
/// </summary>
|
||||
public interface ILegacyComment
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the PNG-encoded avatar of the author.
|
||||
/// </summary>
|
||||
/// <value>The author's avatar.</value>
|
||||
string? Avatar { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the comment's author.
|
||||
/// </summary>
|
||||
/// <value>The author's name.</value>
|
||||
string Author { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the body of the comment.
|
||||
/// </summary>
|
||||
/// <value>The comment body.</value>
|
||||
string Body { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time at which this comment was posted.
|
||||
/// </summary>
|
||||
/// <value>The creation timestamp.</value>
|
||||
DateTimeOffset CreatedAt { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of this comment.
|
||||
/// </summary>
|
||||
Guid Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the comment this comment is replying to.
|
||||
/// </summary>
|
||||
/// <value>The parent comment ID, or <see langword="null" /> if this comment is not a reply.</value>
|
||||
Guid? ParentComment { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the post to which this comment was posted.
|
||||
/// </summary>
|
||||
/// <value>The post ID.</value>
|
||||
Guid PostId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the avatar URL of the comment's author.
|
||||
/// </summary>
|
||||
/// <returns>The avatar URL.</returns>
|
||||
string GetAvatarUrl();
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
namespace OliverBooth.Common.Data.Blog;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a user which can log in to the blog.
|
||||
/// </summary>
|
||||
public interface IUser
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the URL of the user's avatar.
|
||||
/// </summary>
|
||||
/// <value>The URL of the user's avatar.</value>
|
||||
Uri AvatarUrl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the email address of the user.
|
||||
/// </summary>
|
||||
/// <value>The email address of the user.</value>
|
||||
string EmailAddress { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the display name of the author.
|
||||
/// </summary>
|
||||
/// <value>The display name of the author.</value>
|
||||
string DisplayName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique identifier of the user.
|
||||
/// </summary>
|
||||
/// <value>The unique identifier of the user.</value>
|
||||
Guid Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time the user registered.
|
||||
/// </summary>
|
||||
/// <value>The registration date and time.</value>
|
||||
DateTimeOffset Registered { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URL of the user's avatar.
|
||||
/// </summary>
|
||||
/// <param name="size">The size of the avatar.</param>
|
||||
/// <returns>The URL of the user's avatar.</returns>
|
||||
Uri GetAvatarUrl(int size = 28);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the specified password is valid for the user.
|
||||
/// </summary>
|
||||
/// <param name="password">The password to test.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if the specified password is valid for the user; otherwise,
|
||||
/// <see langword="false" />.
|
||||
/// </returns>
|
||||
bool TestCredentials(string password);
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
namespace OliverBooth.Common.Data.Mastodon;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a status on Mastodon.
|
||||
/// </summary>
|
||||
public interface IMastodonStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the content of the status.
|
||||
/// </summary>
|
||||
/// <value>The content.</value>
|
||||
string Content { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time at which this status was posted.
|
||||
/// </summary>
|
||||
/// <value>The post timestamp.</value>
|
||||
DateTimeOffset CreatedAt { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media attachments for this status.
|
||||
/// </summary>
|
||||
/// <value>The media attachments.</value>
|
||||
IReadOnlyList<MediaAttachment> MediaAttachments { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the original URI of the status.
|
||||
/// </summary>
|
||||
/// <value>The original URI.</value>
|
||||
Uri OriginalUri { get; }
|
||||
}
|
37
OliverBooth.Common/Data/Permission.cs
Normal file
37
OliverBooth.Common/Data/Permission.cs
Normal file
@ -0,0 +1,37 @@
|
||||
namespace OliverBooth.Common.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a permission.
|
||||
/// </summary>
|
||||
public struct Permission
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a permission that grants all scopes.
|
||||
/// </summary>
|
||||
public static readonly Permission Administrator = new("*");
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Permission" /> struct.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the permission.</param>
|
||||
/// <param name="isAllowed">
|
||||
/// <see langword="true" /> if the permission is allowed; otherwise, <see langword="false" />.
|
||||
/// </param>
|
||||
public Permission(string name, bool isAllowed = true)
|
||||
{
|
||||
Name = name;
|
||||
IsAllowed = isAllowed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of this permission.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this permission is allowed.
|
||||
/// </summary>
|
||||
/// <value><see langword="true" /> if the permission is allowed; otherwise, <see langword="false" />.</value>
|
||||
public bool IsAllowed { get; }
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace OliverBooth.Common.Data.ValueConverters;
|
||||
|
||||
internal sealed class PermissionListConverter : ValueConverter<IReadOnlyList<Permission>, string>
|
||||
{
|
||||
public PermissionListConverter() : this(';')
|
||||
{
|
||||
}
|
||||
|
||||
public PermissionListConverter(char separator) :
|
||||
base(v => ToProvider(v, separator),
|
||||
s => FromProvider(s, separator))
|
||||
{
|
||||
}
|
||||
|
||||
private static IReadOnlyList<Permission> FromProvider(string source, char separator = ';')
|
||||
{
|
||||
var permissions = new List<Permission>();
|
||||
|
||||
foreach (string permission in source.Split(separator))
|
||||
{
|
||||
string name = permission;
|
||||
var allowed = true;
|
||||
|
||||
if (name.Length > 1 && name[0] == '-')
|
||||
{
|
||||
name = name[1..];
|
||||
allowed = false;
|
||||
}
|
||||
|
||||
permissions.Add(new Permission(name, allowed));
|
||||
}
|
||||
|
||||
return permissions.AsReadOnly();
|
||||
}
|
||||
|
||||
private static string ToProvider(IEnumerable<Permission> permissions, char separator = ';')
|
||||
{
|
||||
return string.Join(separator, permissions.Select(p => $"{(p.IsAllowed ? "-" : "")}{p.Name}"));
|
||||
}
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
using NetBarcode;
|
||||
using OliverBooth.Common.Data.Web;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Formats.Png;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
|
||||
namespace OliverBooth.Data.Web;
|
||||
namespace OliverBooth.Common.Data.Web.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a book.
|
@ -1,4 +1,4 @@
|
||||
namespace OliverBooth.Common.Data.Web;
|
||||
namespace OliverBooth.Common.Data.Web.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the state of a book.
|
@ -1,4 +1,4 @@
|
||||
namespace OliverBooth.Common.Data.Web;
|
||||
namespace OliverBooth.Common.Data.Web.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a book.
|
@ -1,7 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using OliverBooth.Common.Data.Web.Contact;
|
||||
|
||||
namespace OliverBooth.Data.Web.Configuration;
|
||||
namespace OliverBooth.Common.Data.Web.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the configuration for the <see cref="BlacklistEntry" /> entity.
|
@ -1,9 +1,9 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using OliverBooth.Common.Data.Web;
|
||||
using OliverBooth.Common.Data.Web.Books;
|
||||
|
||||
namespace OliverBooth.Data.Web.Configuration;
|
||||
namespace OliverBooth.Common.Data.Web.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the configuration for the <see cref="Book" /> entity.
|
@ -1,7 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using OliverBooth.Common.Data.Web.Projects;
|
||||
|
||||
namespace OliverBooth.Data.Web.Configuration;
|
||||
namespace OliverBooth.Common.Data.Web.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the configuration for the <see cref="ProgrammingLanguage" /> entity.
|
@ -1,9 +1,9 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using OliverBooth.Common.Data.Web;
|
||||
using OliverBooth.Common.Data.Web.Projects;
|
||||
|
||||
namespace OliverBooth.Data.Web.Configuration;
|
||||
namespace OliverBooth.Common.Data.Web.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the configuration for the <see cref="Project" /> entity.
|
@ -0,0 +1,26 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using OliverBooth.Common.Data.Web.Users;
|
||||
|
||||
namespace OliverBooth.Common.Data.Web.Configuration;
|
||||
|
||||
internal sealed class SessionConfiguration : IEntityTypeConfiguration<Session>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void Configure(EntityTypeBuilder<Session> builder)
|
||||
{
|
||||
builder.ToTable("Session");
|
||||
builder.HasKey(e => e.Id);
|
||||
|
||||
builder.Property(e => e.Id).IsRequired();
|
||||
builder.Property(e => e.Created).IsRequired();
|
||||
builder.Property(e => e.Updated).IsRequired();
|
||||
builder.Property(e => e.LastAccessed).IsRequired();
|
||||
builder.Property(e => e.Expires).IsRequired();
|
||||
builder.Property(e => e.UserAgent).HasMaxLength(255).IsRequired();
|
||||
builder.Property(e => e.UserId);
|
||||
builder.Property(e => e.IpAddress).HasConversion<IPAddressToBytesConverter>().IsRequired();
|
||||
builder.Property(e => e.RequiresTotp).IsRequired();
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace OliverBooth.Data.Web.Configuration;
|
||||
namespace OliverBooth.Common.Data.Web.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the configuration for the <see cref="SiteConfiguration" /> entity.
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace OliverBooth.Data.Web.Configuration;
|
||||
namespace OliverBooth.Common.Data.Web.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the configuration for the <see cref="Template" /> entity.
|
@ -1,7 +1,9 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using OliverBooth.Common.Data.ValueConverters;
|
||||
using OliverBooth.Common.Data.Web.Users;
|
||||
|
||||
namespace OliverBooth.Data.Blog.Configuration;
|
||||
namespace OliverBooth.Common.Data.Web.Configuration;
|
||||
|
||||
internal sealed class UserConfiguration : IEntityTypeConfiguration<User>
|
||||
{
|
||||
@ -17,5 +19,7 @@ internal sealed class UserConfiguration : IEntityTypeConfiguration<User>
|
||||
builder.Property(e => e.Password).HasMaxLength(255).IsRequired();
|
||||
builder.Property(e => e.Salt).HasMaxLength(255).IsRequired();
|
||||
builder.Property(e => e.Registered).IsRequired();
|
||||
builder.Property(e => e.Totp);
|
||||
builder.Property(e => e.Permissions).HasConversion<PermissionListConverter>();
|
||||
}
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
using OliverBooth.Common.Data.Web;
|
||||
|
||||
namespace OliverBooth.Data.Web;
|
||||
namespace OliverBooth.Common.Data.Web.Contact;
|
||||
|
||||
/// <inheritdoc cref="IBlacklistEntry"/>
|
||||
internal sealed class BlacklistEntry : IEquatable<BlacklistEntry>, IBlacklistEntry
|
||||
@ -47,8 +45,16 @@ internal sealed class BlacklistEntry : IEquatable<BlacklistEntry>, IBlacklistEnt
|
||||
/// </returns>
|
||||
public bool Equals(BlacklistEntry? other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(this, other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return EmailAddress.Equals(other.EmailAddress);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace OliverBooth.Common.Data.Web;
|
||||
namespace OliverBooth.Common.Data.Web.Contact;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an entry in the blacklist.
|
@ -1,25 +0,0 @@
|
||||
namespace OliverBooth.Common.Data.Web;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a code snippet.
|
||||
/// </summary>
|
||||
public interface ICodeSnippet
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the content for this snippet.
|
||||
/// </summary>
|
||||
/// <value>The content for this snippet</value>
|
||||
string Content { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID for this snippet.
|
||||
/// </summary>
|
||||
/// <value>The ID for this snippet</value>
|
||||
int Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the language for this snippet.
|
||||
/// </summary>
|
||||
/// <value>The language for this snippet</value>
|
||||
string Language { get; }
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
namespace OliverBooth.Common.Data.Web;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a tutorial article.
|
||||
/// </summary>
|
||||
public interface ITutorialArticle
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the body of this article.
|
||||
/// </summary>
|
||||
/// <value>The body.</value>
|
||||
string Body { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether comments are enabled for the article.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <see langword="true" /> if comments are enabled for the article; otherwise, <see langword="false" />.
|
||||
/// </value>
|
||||
bool EnableComments { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the excerpt of this article, if it has one.
|
||||
/// </summary>
|
||||
/// <value>The excerpt, or <see langword="null" /> if this article has no excerpt.</value>
|
||||
string? Excerpt { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the folder this article is contained within.
|
||||
/// </summary>
|
||||
/// <value>The ID of the folder.</value>
|
||||
int Folder { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this article is part of a multi-part series.
|
||||
/// </summary>
|
||||
/// <value><see langword="true" /> if this article has additional parts; otherwise, <see langword="false" />.</value>
|
||||
bool HasOtherParts { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of this article.
|
||||
/// </summary>
|
||||
/// <value>The ID.</value>
|
||||
int Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the next article to this one.
|
||||
/// </summary>
|
||||
/// <value>The next part ID.</value>
|
||||
int? NextPart { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URL of the article's preview image.
|
||||
/// </summary>
|
||||
/// <value>The preview image URL.</value>
|
||||
Uri? PreviewImageUrl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the previous article to this one.
|
||||
/// </summary>
|
||||
/// <value>The previous part ID.</value>
|
||||
int? PreviousPart { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time at which this article was published.
|
||||
/// </summary>
|
||||
/// <value>The publish timestamp.</value>
|
||||
DateTimeOffset Published { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the post that was redirected to this article.
|
||||
/// </summary>
|
||||
/// <value>The source redirect post ID.</value>
|
||||
Guid? RedirectFrom { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the slug of this article.
|
||||
/// </summary>
|
||||
/// <value>The slug.</value>
|
||||
string Slug { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of this article.
|
||||
/// </summary>
|
||||
/// <value>The title.</value>
|
||||
string Title { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time at which this article was updated.
|
||||
/// </summary>
|
||||
/// <value>The update timestamp, or <see langword="null" /> if this article has not been updated.</value>
|
||||
DateTimeOffset? Updated { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the visibility of this article.
|
||||
/// </summary>
|
||||
/// <value>The visibility of the article.</value>
|
||||
Visibility Visibility { get; }
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
namespace OliverBooth.Common.Data.Web;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a folder for tutorial articles.
|
||||
/// </summary>
|
||||
public interface ITutorialFolder
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the ID of this folder.
|
||||
/// </summary>
|
||||
/// <value>The ID of the folder.</value>
|
||||
int Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of this folder's parent.
|
||||
/// </summary>
|
||||
/// <value>The ID of the parent, or <see langword="null" /> if this folder is at the root.</value>
|
||||
int? Parent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URL of the folder's preview image.
|
||||
/// </summary>
|
||||
/// <value>The preview image URL.</value>
|
||||
Uri? PreviewImageUrl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the slug of this folder.
|
||||
/// </summary>
|
||||
/// <value>The slug.</value>
|
||||
string Slug { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of this folder.
|
||||
/// </summary>
|
||||
/// <value>The title.</value>
|
||||
string Title { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the visibility of this article.
|
||||
/// </summary>
|
||||
/// <value>The visibility of the article.</value>
|
||||
Visibility Visibility { get; }
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace OliverBooth.Common.Data.Web;
|
||||
namespace OliverBooth.Common.Data.Web.Projects;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a programming language.
|
@ -1,4 +1,4 @@
|
||||
namespace OliverBooth.Common.Data.Web;
|
||||
namespace OliverBooth.Common.Data.Web.Projects;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a project.
|
@ -1,6 +1,4 @@
|
||||
using OliverBooth.Common.Data.Web;
|
||||
|
||||
namespace OliverBooth.Data.Web;
|
||||
namespace OliverBooth.Common.Data.Web.Projects;
|
||||
|
||||
/// <inheritdoc cref="IProgrammingLanguage" />
|
||||
internal sealed class ProgrammingLanguage : IEquatable<ProgrammingLanguage>, IProgrammingLanguage
|
||||
@ -44,8 +42,16 @@ internal sealed class ProgrammingLanguage : IEquatable<ProgrammingLanguage>, IPr
|
||||
/// </returns>
|
||||
public bool Equals(ProgrammingLanguage? other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(this, other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return Key.Equals(other.Key);
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
using OliverBooth.Common.Data.Web;
|
||||
|
||||
namespace OliverBooth.Data.Web;
|
||||
namespace OliverBooth.Common.Data.Web.Projects;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a project.
|
||||
@ -76,8 +74,16 @@ internal sealed class Project : IEquatable<Project>, IProject
|
||||
/// </returns>
|
||||
public bool Equals(Project? other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(this, other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return Id.Equals(other.Id);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace OliverBooth.Common.Data.Web;
|
||||
namespace OliverBooth.Common.Data.Web.Projects;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the status of a project.
|
@ -1,4 +1,4 @@
|
||||
namespace OliverBooth.Data.Web;
|
||||
namespace OliverBooth.Common.Data.Web;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a site configuration item.
|
||||
@ -50,8 +50,16 @@ public sealed class SiteConfiguration : IEquatable<SiteConfiguration>
|
||||
/// </returns>
|
||||
public bool Equals(SiteConfiguration? other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(this, other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return Key == other.Key;
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
using OliverBooth.Common.Data.Web;
|
||||
|
||||
namespace OliverBooth.Data.Web;
|
||||
namespace OliverBooth.Common.Data.Web;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a MediaWiki-style template.
|
||||
@ -49,8 +47,16 @@ public sealed class Template : ITemplate, IEquatable<Template>
|
||||
/// </returns>
|
||||
public bool Equals(Template? other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(this, other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return Name == other.Name && Variant == other.Variant;
|
||||
}
|
||||
|
37
OliverBooth.Common/Data/Web/Users/IMfaToken.cs
Normal file
37
OliverBooth.Common/Data/Web/Users/IMfaToken.cs
Normal file
@ -0,0 +1,37 @@
|
||||
namespace OliverBooth.Common.Data.Web.Users;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a temporary token used to correlate MFA attempts with the user.
|
||||
/// </summary>
|
||||
public interface IMfaToken
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a value indicating the number of attempts made with this token.
|
||||
/// </summary>
|
||||
/// <value>The number of attempts.</value>
|
||||
int Attempts { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time at which this token was created.
|
||||
/// </summary>
|
||||
/// <value>The creation timestamp.</value>
|
||||
DateTimeOffset Created { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time at which this token expires.
|
||||
/// </summary>
|
||||
/// <value>The expiration timestamp.</value>
|
||||
DateTimeOffset Expires { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the 512-bit token for MFA.
|
||||
/// </summary>
|
||||
/// <value>The temporary MFA token.</value>
|
||||
string Token { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user to whom this token is associated.
|
||||
/// </summary>
|
||||
/// <value>The user.</value>
|
||||
IUser User { get; }
|
||||
}
|
63
OliverBooth.Common/Data/Web/Users/ISession.cs
Normal file
63
OliverBooth.Common/Data/Web/Users/ISession.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using System.Net;
|
||||
|
||||
namespace OliverBooth.Common.Data.Web.Users;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a login session.
|
||||
/// </summary>
|
||||
public interface ISession
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the date and time at which this session was created.
|
||||
/// </summary>
|
||||
/// <value>The creation timestamp.</value>
|
||||
DateTimeOffset Created { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time at which this session expires.
|
||||
/// </summary>
|
||||
/// <value>The expiration timestamp.</value>
|
||||
DateTimeOffset Expires { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the session.
|
||||
/// </summary>
|
||||
/// <value>The ID of the session.</value>
|
||||
Guid Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the IP address of the session.
|
||||
/// </summary>
|
||||
/// <value>The IP address.</value>
|
||||
IPAddress IpAddress { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time at which this session was last accessed.
|
||||
/// </summary>
|
||||
/// <value>The last access timestamp.</value>
|
||||
DateTimeOffset LastAccessed { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this session is valid.
|
||||
/// </summary>
|
||||
/// <value><see langword="true" /> if the session is valid; otherwise, <see langword="false" />.</value>
|
||||
bool RequiresTotp { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time at which this session was updated.
|
||||
/// </summary>
|
||||
/// <value>The update timestamp.</value>
|
||||
DateTimeOffset Updated { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user agent string associated with this session.
|
||||
/// </summary>
|
||||
/// <value>The user agent string.</value>
|
||||
string UserAgent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user ID associated with the session.
|
||||
/// </summary>
|
||||
/// <value>The user ID.</value>
|
||||
Guid UserId { get; }
|
||||
}
|
95
OliverBooth.Common/Data/Web/Users/IUser.cs
Normal file
95
OliverBooth.Common/Data/Web/Users/IUser.cs
Normal file
@ -0,0 +1,95 @@
|
||||
namespace OliverBooth.Common.Data.Web.Users;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a user which can log in to the blog.
|
||||
/// </summary>
|
||||
public interface IUser
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the URL of the user's avatar.
|
||||
/// </summary>
|
||||
/// <value>The URL of the user's avatar.</value>
|
||||
Uri AvatarUrl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the email address of the user.
|
||||
/// </summary>
|
||||
/// <value>The email address of the user.</value>
|
||||
string EmailAddress { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the display name of the author.
|
||||
/// </summary>
|
||||
/// <value>The display name of the author.</value>
|
||||
string DisplayName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique identifier of the user.
|
||||
/// </summary>
|
||||
/// <value>The unique identifier of the user.</value>
|
||||
Guid Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time the user registered.
|
||||
/// </summary>
|
||||
/// <value>The registration date and time.</value>
|
||||
DateTimeOffset Registered { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the permissions this user is granted.
|
||||
/// </summary>
|
||||
/// <value>A read-only view of the permissions this user is granted.</value>
|
||||
IReadOnlyList<Permission> Permissions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user's TOTP token.
|
||||
/// </summary>
|
||||
/// <value>The TOTP token.</value>
|
||||
string? Totp { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URL of the user's avatar.
|
||||
/// </summary>
|
||||
/// <param name="size">The size of the avatar.</param>
|
||||
/// <returns>The URL of the user's avatar.</returns>
|
||||
Uri GetAvatarUrl(int size = 28);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the user has the specified permission.
|
||||
/// </summary>
|
||||
/// <param name="permission">The permission to test.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if the user has the specified permission; otherwise, <see langword="false" />.
|
||||
/// </returns>
|
||||
bool HasPermission(Permission permission);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the user has the specified permission.
|
||||
/// </summary>
|
||||
/// <param name="permission">The permission to test.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if the user has the specified permission; otherwise, <see langword="false" />.
|
||||
/// </returns>
|
||||
bool HasPermission(string permission);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the specified password is valid for the user.
|
||||
/// </summary>
|
||||
/// <param name="password">The password to test.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if the specified password is valid for the user; otherwise,
|
||||
/// <see langword="false" />.
|
||||
/// </returns>
|
||||
bool TestCredentials(string password);
|
||||
|
||||
/// <summary>
|
||||
/// Tests the specified TOTP with the user's current TOTP.
|
||||
/// </summary>
|
||||
/// <param name="value">The TOTP to test.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if the specified time-based one-time password matches that of the user; otherwise,
|
||||
/// <see langword="false" />.
|
||||
/// </returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
|
||||
bool TestTotp(string value);
|
||||
}
|
29
OliverBooth.Common/Data/Web/Users/MfaRequestResult.cs
Normal file
29
OliverBooth.Common/Data/Web/Users/MfaRequestResult.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using OliverBooth.Common.Services;
|
||||
|
||||
namespace OliverBooth.Common.Data.Web.Users;
|
||||
|
||||
/// <summary>
|
||||
/// An enumeration of possible results for <see cref="IUserService.VerifyMfaRequest" />.
|
||||
/// </summary>
|
||||
public enum MfaRequestResult
|
||||
{
|
||||
/// <summary>
|
||||
/// The request was successful.
|
||||
/// </summary>
|
||||
Success,
|
||||
|
||||
/// <summary>
|
||||
/// The wrong code was entered.
|
||||
/// </summary>
|
||||
InvalidTotp,
|
||||
|
||||
/// <summary>
|
||||
/// The MFA token has expired.
|
||||
/// </summary>
|
||||
TokenExpired,
|
||||
|
||||
/// <summary>
|
||||
/// Too many attempts were made by the user.
|
||||
/// </summary>
|
||||
TooManyAttempts,
|
||||
}
|
19
OliverBooth.Common/Data/Web/Users/MfaToken.cs
Normal file
19
OliverBooth.Common/Data/Web/Users/MfaToken.cs
Normal file
@ -0,0 +1,19 @@
|
||||
namespace OliverBooth.Common.Data.Web.Users;
|
||||
|
||||
internal sealed class MfaToken : IMfaToken
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public int Attempts { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset Created { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset Expires { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Token { get; set; } = string.Empty;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IUser User { get; set; } = null!;
|
||||
}
|
33
OliverBooth.Common/Data/Web/Users/Session.cs
Normal file
33
OliverBooth.Common/Data/Web/Users/Session.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System.Net;
|
||||
|
||||
namespace OliverBooth.Common.Data.Web.Users;
|
||||
|
||||
internal sealed class Session : ISession
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset Created { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset Expires { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Guid Id { get; private set; } = Guid.NewGuid();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IPAddress IpAddress { get; set; } = IPAddress.None;
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset LastAccessed { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool RequiresTotp { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset Updated { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string UserAgent { get; set; } = string.Empty;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Guid UserId { get; set; }
|
||||
}
|
@ -3,13 +3,14 @@ using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Cysharp.Text;
|
||||
using OliverBooth.Common.Data.Blog;
|
||||
using OtpNet;
|
||||
|
||||
namespace OliverBooth.Data.Blog;
|
||||
namespace OliverBooth.Common.Data.Web.Users;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a user.
|
||||
/// </summary>
|
||||
internal sealed class User : IUser, IBlogAuthor
|
||||
internal sealed class User : IUser, IAuthor
|
||||
{
|
||||
/// <inheritdoc cref="IUser.AvatarUrl" />
|
||||
[NotMapped]
|
||||
@ -24,9 +25,15 @@ internal sealed class User : IUser, IBlogAuthor
|
||||
/// <inheritdoc cref="IUser.Id" />
|
||||
public Guid Id { get; private set; } = Guid.NewGuid();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<Permission> Permissions { get; private set; } = ArraySegment<Permission>.Empty;
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset Registered { get; private set; } = DateTimeOffset.UtcNow;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string? Totp { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the password hash.
|
||||
/// </summary>
|
||||
@ -59,16 +66,44 @@ internal sealed class User : IUser, IBlogAuthor
|
||||
Span<char> hex = stackalloc char[2];
|
||||
for (var index = 0; index < hash.Length; index++)
|
||||
{
|
||||
if (hash[index].TryFormat(hex, out _, "x2")) builder.Append(hex);
|
||||
else builder.Append("00");
|
||||
if (hash[index].TryFormat(hex, out _, "x2"))
|
||||
{
|
||||
builder.Append(hex);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Append("00");
|
||||
}
|
||||
}
|
||||
|
||||
return new Uri($"https://www.gravatar.com/avatar/{builder}?size={size}");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasPermission(Permission permission)
|
||||
{
|
||||
return HasPermission(permission.Name);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasPermission(string permission)
|
||||
{
|
||||
return (Permissions.Any(p => p.IsAllowed && p.Name == permission) ||
|
||||
Permissions.Any(p => p is { IsAllowed: true, Name: "*" })) &&
|
||||
!Permissions.Any(p => !p.IsAllowed && p.Name == permission);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TestCredentials(string password)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TestTotp(string value)
|
||||
{
|
||||
byte[]? key = Base32Encoding.ToBytes(Totp);
|
||||
var totp = new Totp(key);
|
||||
return totp.VerifyTotp(value, out _, VerificationWindow.RfcSpecifiedNetworkDelay);
|
||||
}
|
||||
}
|
@ -1,7 +1,12 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using OliverBooth.Data.Web.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using OliverBooth.Common.Data.Web.Books;
|
||||
using OliverBooth.Common.Data.Web.Configuration;
|
||||
using OliverBooth.Common.Data.Web.Contact;
|
||||
using OliverBooth.Common.Data.Web.Projects;
|
||||
using OliverBooth.Common.Data.Web.Users;
|
||||
|
||||
namespace OliverBooth.Data.Web;
|
||||
namespace OliverBooth.Common.Data.Web;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a session with the web database.
|
||||
@ -25,12 +30,6 @@ internal sealed class WebContext : DbContext
|
||||
/// <value>The collection of books.</value>
|
||||
public DbSet<Book> Books { get; private set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of code snippets in the database.
|
||||
/// </summary>
|
||||
/// <value>The collection of code snippets.</value>
|
||||
public DbSet<CodeSnippet> CodeSnippets { get; private set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of blacklist entries in the database.
|
||||
/// </summary>
|
||||
@ -49,6 +48,12 @@ internal sealed class WebContext : DbContext
|
||||
/// <value>The collection of projects.</value>
|
||||
public DbSet<Project> Projects { get; private set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of sessions in the database.
|
||||
/// </summary>
|
||||
/// <value>The collection of sessions.</value>
|
||||
public DbSet<Session> Sessions { get; private set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set of site configuration items.
|
||||
/// </summary>
|
||||
@ -62,16 +67,10 @@ internal sealed class WebContext : DbContext
|
||||
public DbSet<Template> Templates { get; private set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of tutorial articles in the database.
|
||||
/// Gets the collection of users in the database.
|
||||
/// </summary>
|
||||
/// <value>The collection of tutorial articles.</value>
|
||||
public DbSet<TutorialArticle> TutorialArticles { get; private set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of tutorial folders in the database.
|
||||
/// </summary>
|
||||
/// <value>The collection of tutorial folders.</value>
|
||||
public DbSet<TutorialFolder> TutorialFolders { get; private set; } = null!;
|
||||
/// <value>The collection of users.</value>
|
||||
public DbSet<User> Users { get; private set; } = null!;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
@ -86,12 +85,11 @@ internal sealed class WebContext : DbContext
|
||||
{
|
||||
modelBuilder.ApplyConfiguration(new BlacklistEntryConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new BookConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new CodeSnippetConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new ProgrammingLanguageConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new ProjectConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new TemplateConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new TutorialArticleConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new TutorialFolderConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new SessionConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new SiteConfigurationConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new UserConfiguration());
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
using Markdig;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using OliverBooth.Common.Data.Blog;
|
||||
using OliverBooth.Common.Data.Web;
|
||||
using OliverBooth.Common.Markdown.Template;
|
||||
using OliverBooth.Common.Services;
|
||||
using X10D.Hosting.DependencyInjection;
|
||||
|
||||
namespace OliverBooth.Common.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for dependency injection.
|
||||
/// </summary>
|
||||
public static class DependencyInjectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds all required services provided by the assembly to the current <see cref="IServiceCollection" />.
|
||||
/// </summary>
|
||||
/// <param name="collection">The <see cref="IServiceCollection" /> to add the service to.</param>
|
||||
public static void AddCommonServices(this IServiceCollection collection)
|
||||
{
|
||||
collection.AddSingleton(provider => new MarkdownPipelineBuilder()
|
||||
// .Use<TimestampExtension>()
|
||||
.Use(new TemplateExtension(provider.GetRequiredService<ITemplateService>()))
|
||||
.UseAdvancedExtensions()
|
||||
.UseBootstrap()
|
||||
.UseEmojiAndSmiley()
|
||||
.UseSmartyPants()
|
||||
.Build());
|
||||
|
||||
collection.AddDbContextFactory<BlogContext>();
|
||||
collection.AddDbContextFactory<WebContext>();
|
||||
|
||||
collection.AddSingleton<IBlogPostService, BlogPostService>();
|
||||
collection.AddSingleton<IContactService, ContactService>();
|
||||
collection.AddSingleton<IProjectService, ProjectService>();
|
||||
collection.AddSingleton<IReadingListService, ReadingListService>();
|
||||
collection.AddSingleton<ITemplateService, TemplateService>();
|
||||
|
||||
collection.AddHostedSingleton<ISessionService, SessionService>();
|
||||
collection.AddHostedSingleton<IUserService, UserService>();
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
||||
namespace OliverBooth.Extensions;
|
||||
namespace OliverBooth.Common.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="IWebHostBuilder" />.
|
@ -1,7 +1,7 @@
|
||||
using System.Globalization;
|
||||
using SmartFormat.Core.Extensions;
|
||||
|
||||
namespace OliverBooth.Extensions.SmartFormat;
|
||||
namespace OliverBooth.Common.Formatting;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a SmartFormat formatter that formats a date.
|
||||
@ -18,13 +18,17 @@ public sealed class DateFormatter : IFormatter
|
||||
public bool TryEvaluateFormat(IFormattingInfo formattingInfo)
|
||||
{
|
||||
if (formattingInfo.CurrentValue is not string value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!DateTime.TryParseExact(value, "yyyy-MM-dd",
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.None,
|
||||
out DateTime date))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
formattingInfo.Write(date.ToString(formattingInfo.Format?.ToString(), CultureInfo.InvariantCulture));
|
@ -2,7 +2,7 @@ using Markdig;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SmartFormat.Core.Extensions;
|
||||
|
||||
namespace OliverBooth.Extensions.SmartFormat;
|
||||
namespace OliverBooth.Common.Formatting;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a SmartFormat formatter that formats markdown.
|
||||
@ -30,7 +30,9 @@ public sealed class MarkdownFormatter : IFormatter
|
||||
public bool TryEvaluateFormat(IFormattingInfo formattingInfo)
|
||||
{
|
||||
if (formattingInfo.CurrentValue is not string value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var pipeline = _serviceProvider.GetService<MarkdownPipeline>();
|
||||
formattingInfo.Write(Markdig.Markdown.ToHtml(value, pipeline));
|
@ -1,8 +1,8 @@
|
||||
using Markdig;
|
||||
using Markdig.Renderers;
|
||||
using OliverBooth.Extensions.Markdig.Services;
|
||||
using OliverBooth.Common.Services;
|
||||
|
||||
namespace OliverBooth.Extensions.Markdig.Markdown.Template;
|
||||
namespace OliverBooth.Common.Markdown.Template;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Markdown extension that adds support for MediaWiki-style templates.
|
@ -1,6 +1,6 @@
|
||||
using Markdig.Syntax.Inlines;
|
||||
|
||||
namespace OliverBooth.Extensions.Markdig.Markdown.Template;
|
||||
namespace OliverBooth.Common.Markdown.Template;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Markdown inline element that represents a MediaWiki-style template.
|
@ -2,7 +2,7 @@ using Cysharp.Text;
|
||||
using Markdig.Helpers;
|
||||
using Markdig.Parsers;
|
||||
|
||||
namespace OliverBooth.Extensions.Markdig.Markdown.Template;
|
||||
namespace OliverBooth.Common.Markdown.Template;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Markdown inline parser that handles MediaWiki-style templates.
|
||||
@ -17,7 +17,7 @@ public sealed class TemplateInlineParser : InlineParser
|
||||
/// </summary>
|
||||
public TemplateInlineParser()
|
||||
{
|
||||
OpeningCharacters = new[] { '{' };
|
||||
OpeningCharacters = ['{'];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
@ -1,8 +1,8 @@
|
||||
using Markdig.Renderers;
|
||||
using Markdig.Renderers.Html;
|
||||
using OliverBooth.Extensions.Markdig.Services;
|
||||
using OliverBooth.Common.Services;
|
||||
|
||||
namespace OliverBooth.Extensions.Markdig.Markdown.Template;
|
||||
namespace OliverBooth.Common.Markdown.Template;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Markdown object renderer that handles <see cref="TemplateInline" /> elements.
|
@ -7,9 +7,28 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.59"/>
|
||||
<PackageReference Include="Alexinea.Extensions.Configuration.Toml" Version="7.0.0"/>
|
||||
<PackageReference Include="Asp.Versioning.Mvc" Version="8.0.0"/>
|
||||
<PackageReference Include="BCrypt.Net-Core" Version="1.6.0"/>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1"/>
|
||||
<PackageReference Include="Markdig" Version="0.36.2"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0"/>
|
||||
<PackageReference Include="NetBarcode" Version="1.7.0"/>
|
||||
<PackageReference Include="Otp.NET" Version="1.3.0"/>
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2"/>
|
||||
<PackageReference Include="Serilog" Version="3.1.1"/>
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1"/>
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0"/>
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1"/>
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0"/>
|
||||
<PackageReference Include="SmartFormat.NET" Version="3.3.2"/>
|
||||
<PackageReference Include="X10D" Version="3.3.1"/>
|
||||
<PackageReference Include="X10D.Hosting" Version="3.3.1"/>
|
||||
<PackageReference Include="ZString" Version="2.5.1"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Markdown\"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -2,20 +2,30 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using Humanizer;
|
||||
using Markdig;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using OliverBooth.Common.Data;
|
||||
using OliverBooth.Common.Data.Blog;
|
||||
using OliverBooth.Common.Services;
|
||||
using OliverBooth.Data.Blog;
|
||||
using OliverBooth.Common.Data.Web.Users;
|
||||
|
||||
namespace OliverBooth.Services;
|
||||
namespace OliverBooth.Common.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an implementation of <see cref="IBlogPostService" />.
|
||||
/// </summary>
|
||||
internal sealed class BlogPostService : IBlogPostService
|
||||
{
|
||||
/*private static readonly JsonSerializerOptions EditorJsOptions = new()
|
||||
{
|
||||
ReferenceHandler = ReferenceHandler.Preserve,
|
||||
Converters =
|
||||
{
|
||||
new ParagraphBlockConverter(),
|
||||
new HeadingBlockConverter(),
|
||||
new MarkdownDocumentConverter()
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
private readonly IDbContextFactory<BlogContext> _dbContextFactory;
|
||||
private readonly IBlogUserService _blogUserService;
|
||||
private readonly IUserService _userService;
|
||||
private readonly MarkdownPipeline _markdownPipeline;
|
||||
|
||||
/// <summary>
|
||||
@ -24,40 +34,61 @@ internal sealed class BlogPostService : IBlogPostService
|
||||
/// <param name="dbContextFactory">
|
||||
/// The <see cref="IDbContextFactory{TContext}" /> used to create a <see cref="BlogContext" />.
|
||||
/// </param>
|
||||
/// <param name="blogUserService">The <see cref="IBlogUserService" />.</param>
|
||||
/// <param name="userService">The <see cref="IUserService" />.</param>
|
||||
/// <param name="markdownPipeline">The <see cref="MarkdownPipeline" />.</param>
|
||||
public BlogPostService(IDbContextFactory<BlogContext> dbContextFactory,
|
||||
IBlogUserService blogUserService,
|
||||
IUserService userService,
|
||||
MarkdownPipeline markdownPipeline)
|
||||
{
|
||||
_dbContextFactory = dbContextFactory;
|
||||
_blogUserService = blogUserService;
|
||||
_userService = userService;
|
||||
_markdownPipeline = markdownPipeline;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int GetBlogPostCount(Visibility visibility = Visibility.None, string[]? tags = null)
|
||||
public string GetBlogPostEditorObject(IBlogPost post)
|
||||
{
|
||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||
if (tags is { Length: > 0 })
|
||||
if (post is null)
|
||||
{
|
||||
return visibility == Visibility.None
|
||||
? context.BlogPosts.AsEnumerable().Count(p => !p.IsRedirect && p.Tags.Intersect(tags).Any())
|
||||
: context.BlogPosts.AsEnumerable().Count(p => !p.IsRedirect && p.Visibility == visibility && p.Tags.Intersect(tags).Any());
|
||||
throw new ArgumentNullException(nameof(post));
|
||||
}
|
||||
|
||||
return visibility == Visibility.None
|
||||
? context.BlogPosts.Count(p => !p.IsRedirect)
|
||||
: context.BlogPosts.Count(p => !p.IsRedirect && p.Visibility == visibility);
|
||||
/*var document = (JsonDocument)Markdig.Markdown.Convert(post.Body, new JsonRenderer(), _markdownPipeline);
|
||||
return JsonSerializer.Serialize(document, EditorJsOptions);*/
|
||||
return """{"blocks":{}}""";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<IBlogPost> GetAllBlogPosts(int limit = -1)
|
||||
public int GetBlogPostCount()
|
||||
{
|
||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||
IQueryable<BlogPost> ordered = context.BlogPosts
|
||||
.Where(p => p.Visibility == Visibility.Published && !p.IsRedirect)
|
||||
.OrderByDescending(post => post.Published);
|
||||
return context.BlogPosts.Count();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<IBlogPostDraft> GetDrafts(IBlogPost post)
|
||||
{
|
||||
if (post is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(post));
|
||||
}
|
||||
|
||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||
return context.BlogPostDrafts.Where(d => d.Id == post.Id).OrderBy(d => d.Updated).ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<IBlogPost> GetAllBlogPosts(int limit = -1,
|
||||
BlogPostVisibility visibility = BlogPostVisibility.Published)
|
||||
{
|
||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||
IQueryable<BlogPost> ordered = context.BlogPosts;
|
||||
if (visibility != (BlogPostVisibility)(-1))
|
||||
{
|
||||
ordered = ordered.Where(p => p.Visibility == visibility);
|
||||
}
|
||||
|
||||
ordered = ordered.OrderByDescending(post => post.Published);
|
||||
if (limit > -1)
|
||||
{
|
||||
ordered = ordered.Take(limit);
|
||||
@ -67,68 +98,33 @@ internal sealed class BlogPostService : IBlogPostService
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<IBlogPost> GetBlogPosts(int page, int pageSize = 10, string[]? tags = null)
|
||||
public IReadOnlyList<IBlogPost> GetBlogPosts(int page, int pageSize = 10)
|
||||
{
|
||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||
IEnumerable<BlogPost> posts = context.BlogPosts
|
||||
.Where(p => p.Visibility == Visibility.Published && !p.IsRedirect)
|
||||
return context.BlogPosts
|
||||
.Where(p => p.Visibility == BlogPostVisibility.Published)
|
||||
.OrderByDescending(post => post.Published)
|
||||
.AsEnumerable();
|
||||
|
||||
if (tags is { Length: > 0 })
|
||||
{
|
||||
posts = posts.Where(p => p.Tags.Intersect(tags).Any());
|
||||
}
|
||||
|
||||
return posts.Skip(page * pageSize)
|
||||
.Skip(page * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToArray().Select(CacheAuthor).ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int GetLegacyCommentCount(IBlogPost post)
|
||||
{
|
||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||
return context.LegacyComments.Count(c => c.PostId == post.Id);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<ILegacyComment> GetLegacyComments(IBlogPost post)
|
||||
{
|
||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||
return context.LegacyComments.Where(c => c.PostId == post.Id && c.ParentComment == null).ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<ILegacyComment> GetLegacyReplies(ILegacyComment comment)
|
||||
{
|
||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||
return context.LegacyComments.Where(c => c.ParentComment == comment.Id).ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IBlogPost? GetNextPost(IBlogPost blogPost)
|
||||
{
|
||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||
return context.BlogPosts
|
||||
.Where(p => p.Visibility == Visibility.Published && !p.IsRedirect)
|
||||
.Where(p => p.Visibility == BlogPostVisibility.Published)
|
||||
.OrderBy(post => post.Published)
|
||||
.FirstOrDefault(post => post.Published > blogPost.Published);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int GetPageCount(int pageSize = 10, Visibility visibility = Visibility.None, string[]? tags = null)
|
||||
{
|
||||
float postCount = GetBlogPostCount(visibility, tags);
|
||||
return (int)MathF.Ceiling(postCount / pageSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IBlogPost? GetPreviousPost(IBlogPost blogPost)
|
||||
{
|
||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||
return context.BlogPosts
|
||||
.Where(p => p.Visibility == Visibility.Published && !p.IsRedirect)
|
||||
.Where(p => p.Visibility == BlogPostVisibility.Published)
|
||||
.OrderByDescending(post => post.Published)
|
||||
.FirstOrDefault(post => post.Published < blogPost.Published);
|
||||
}
|
||||
@ -136,12 +132,6 @@ internal sealed class BlogPostService : IBlogPostService
|
||||
/// <inheritdoc />
|
||||
public string RenderExcerpt(IBlogPost post, out bool wasTrimmed)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(post.Excerpt))
|
||||
{
|
||||
wasTrimmed = false;
|
||||
return Markdig.Markdown.ToHtml(post.Excerpt, _markdownPipeline);
|
||||
}
|
||||
|
||||
string body = post.Body;
|
||||
int moreIndex = body.IndexOf("<!--more-->", StringComparison.Ordinal);
|
||||
|
||||
@ -208,6 +198,21 @@ internal sealed class BlogPostService : IBlogPostService
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void UpdatePost(IBlogPost post)
|
||||
{
|
||||
if (post is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(post));
|
||||
}
|
||||
|
||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||
BlogPost cached = context.BlogPosts.First(p => p.Id == post.Id);
|
||||
context.BlogPostDrafts.Add(BlogPostDraft.CreateFromBlogPost(cached));
|
||||
context.Update(post);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
private BlogPost CacheAuthor(BlogPost post)
|
||||
{
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
|
||||
@ -216,7 +221,7 @@ internal sealed class BlogPostService : IBlogPostService
|
||||
return post;
|
||||
}
|
||||
|
||||
if (_blogUserService.TryGetUser(post.AuthorId, out IUser? user) && user is IBlogAuthor author)
|
||||
if (_userService.TryGetUser(post.AuthorId, out IUser? user) && user is IAuthor author)
|
||||
{
|
||||
post.Author = author;
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using OliverBooth.Common.Data.Web;
|
||||
using OliverBooth.Common.Services;
|
||||
using OliverBooth.Data.Web;
|
||||
using OliverBooth.Common.Data.Web.Contact;
|
||||
|
||||
namespace OliverBooth.Services;
|
||||
namespace OliverBooth.Common.Services;
|
||||
|
||||
/// <inheritdoc cref="IContactService" />
|
||||
internal sealed class ContactService : IContactService
|
@ -1,5 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using OliverBooth.Common.Data;
|
||||
using OliverBooth.Common.Data.Blog;
|
||||
|
||||
namespace OliverBooth.Common.Services;
|
||||
@ -13,20 +12,28 @@ public interface IBlogPostService
|
||||
/// Returns a collection of all blog posts.
|
||||
/// </summary>
|
||||
/// <param name="limit">The maximum number of posts to return. A value of -1 returns all posts.</param>
|
||||
/// <param name="visibility">The visibility of the posts to retrieve.</param>
|
||||
/// <returns>A collection of all blog posts.</returns>
|
||||
/// <remarks>
|
||||
/// This method may slow down execution if there are a large number of blog posts being requested. It is
|
||||
/// recommended to use <see cref="GetBlogPosts" /> instead.
|
||||
/// </remarks>
|
||||
IReadOnlyList<IBlogPost> GetAllBlogPosts(int limit = -1);
|
||||
IReadOnlyList<IBlogPost> GetAllBlogPosts(int limit = -1,
|
||||
BlogPostVisibility visibility = BlogPostVisibility.Published);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the total number of blog posts.
|
||||
/// </summary>
|
||||
/// <param name="visibility">The post visibility filter.</param>
|
||||
/// <param name="tags">The tags of the posts to return.</param>
|
||||
/// <returns>The total number of blog posts.</returns>
|
||||
int GetBlogPostCount(Visibility visibility = Visibility.None, string[]? tags = null);
|
||||
int GetBlogPostCount();
|
||||
|
||||
/// <summary>
|
||||
/// Returns a JSON object representing the blog post block data.
|
||||
/// </summary>
|
||||
/// <param name="post">The blog post whose block data object should be returned.</param>
|
||||
/// <returns>The JSON data of the blog post block data.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="post" /> is <see langword="null" />.</exception>
|
||||
string GetBlogPostEditorObject(IBlogPost post);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of blog posts from the specified page, optionally limiting the number of posts
|
||||
@ -34,30 +41,16 @@ public interface IBlogPostService
|
||||
/// </summary>
|
||||
/// <param name="page">The zero-based index of the page to return.</param>
|
||||
/// <param name="pageSize">The maximum number of posts to return per page.</param>
|
||||
/// <param name="tags">The tags of the posts to return.</param>
|
||||
/// <returns>A collection of blog posts.</returns>
|
||||
IReadOnlyList<IBlogPost> GetBlogPosts(int page, int pageSize = 10, string[]? tags = null);
|
||||
IReadOnlyList<IBlogPost> GetBlogPosts(int page, int pageSize);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of legacy comments for the specified post.
|
||||
/// Returns the drafts of this post, sorted by their update timestamp.
|
||||
/// </summary>
|
||||
/// <param name="post">The post whose legacy comments to count.</param>
|
||||
/// <returns>The total number of legacy comments.</returns>
|
||||
int GetLegacyCommentCount(IBlogPost post);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the collection of legacy comments for the specified post.
|
||||
/// </summary>
|
||||
/// <param name="post">The post whose legacy comments to retrieve.</param>
|
||||
/// <returns>A read-only view of the legacy comments.</returns>
|
||||
IReadOnlyList<ILegacyComment> GetLegacyComments(IBlogPost post);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the collection of replies to the specified legacy comment.
|
||||
/// </summary>
|
||||
/// <param name="comment">The comment whose replies to retrieve.</param>
|
||||
/// <returns>A read-only view of the replies.</returns>
|
||||
IReadOnlyList<ILegacyComment> GetLegacyReplies(ILegacyComment comment);
|
||||
/// <param name="post">The post whose drafts to return.</param>
|
||||
/// <returns>The drafts of the <paramref name="post" />.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="post" /> is <see langword="null" />.</exception>
|
||||
IReadOnlyList<IBlogPostDraft> GetDrafts(IBlogPost post);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the next blog post from the specified blog post.
|
||||
@ -66,16 +59,6 @@ public interface IBlogPostService
|
||||
/// <returns>The next blog post from the specified blog post.</returns>
|
||||
IBlogPost? GetNextPost(IBlogPost blogPost);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of pages needed to render all blog posts, using the specified <paramref name="pageSize" /> as an
|
||||
/// indicator of how many posts are allowed per page.
|
||||
/// </summary>
|
||||
/// <param name="pageSize">The page size. Defaults to 10.</param>
|
||||
/// <param name="visibility">The post visibility filter.</param>
|
||||
/// <param name="tags">The tags of the posts to return.</param>
|
||||
/// <returns>The page count.</returns>
|
||||
int GetPageCount(int pageSize = 10, Visibility visibility = Visibility.None, string[]? tags = null);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the previous blog post from the specified blog post.
|
||||
/// </summary>
|
||||
@ -143,4 +126,11 @@ public interface IBlogPostService
|
||||
/// </returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="slug" /> is <see langword="null" />.</exception>
|
||||
bool TryGetPost(DateOnly publishDate, string slug, [NotNullWhen(true)] out IBlogPost? post);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the specified post.
|
||||
/// </summary>
|
||||
/// <param name="post">The post to edit.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="post" /> is <see langword="null" />.</exception>
|
||||
void UpdatePost(IBlogPost post);
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using OliverBooth.Common.Data.Blog;
|
||||
|
||||
namespace OliverBooth.Common.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a service for managing users.
|
||||
/// </summary>
|
||||
public interface IBlogUserService
|
||||
{
|
||||
/// <summary>
|
||||
/// Attempts to find a user with the specified ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the user to find.</param>
|
||||
/// <param name="user">
|
||||
/// When this method returns, contains the user with the specified ID, if the user is found; otherwise,
|
||||
/// <see langword="null" />.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if a user with the specified ID is found; otherwise, <see langword="false" />.
|
||||
/// </returns>
|
||||
bool TryGetUser(Guid id, [NotNullWhen(true)] out IUser? user);
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using OliverBooth.Common.Data.Web;
|
||||
|
||||
namespace OliverBooth.Common.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a service which can fetch multi-language code snippets.
|
||||
/// </summary>
|
||||
public interface ICodeSnippetService
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns all the languages which apply to the specified snippet.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the snippet whose languages should be returned.</param>
|
||||
/// <returns>
|
||||
/// A read-only view of the languages that apply to the snippet. This list may be empty if the snippet ID is invalid.
|
||||
/// </returns>
|
||||
IReadOnlyList<string> GetLanguagesForSnippet(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to find a code snippet by the specified ID, in the specified language.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the snippet to search for.</param>
|
||||
/// <param name="language">The language to search for.</param>
|
||||
/// <param name="snippet">
|
||||
/// When this method returns, contains the code snippet matching the specified criteria, if such a snippet was found;
|
||||
/// otherwise, <see langword="null" />.
|
||||
/// </param>
|
||||
/// <returns><see langword="true" /> if the snippet was found; otherwise, <see langword="false" />.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="language" /> is <see langword="null" />.</exception>
|
||||
bool TryGetCodeSnippetForLanguage(int id, string language, [NotNullWhen(true)] out ICodeSnippet? snippet);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using OliverBooth.Common.Data.Web;
|
||||
using OliverBooth.Common.Data.Web.Contact;
|
||||
|
||||
namespace OliverBooth.Common.Services;
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user