refactor: move BlogPostVisibility to Visibility

shared enum for blog posts and tutorials, and anything else that may need it
This commit is contained in:
Oliver Booth 2024-02-23 16:50:43 +00:00
parent 8629f8f963
commit 577f3b0148
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5
6 changed files with 13 additions and 11 deletions

View File

@ -44,7 +44,7 @@ internal sealed class BlogPost : IBlogPost
public DateTimeOffset? Updated { get; internal set; }
/// <inheritdoc />
public BlogPostVisibility Visibility { get; internal set; }
public Visibility Visibility { get; internal set; }
/// <inheritdoc />
public int? WordPressId { get; set; }

View File

@ -26,7 +26,7 @@ internal sealed class BlogPostConfiguration : IEntityTypeConfiguration<BlogPost>
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.Visibility).HasConversion(new EnumToStringConverter<Visibility>()).IsRequired();
builder.Property(e => e.Password).HasMaxLength(255).IsRequired(false);
builder.Property(e => e.Tags).IsRequired()
.HasConversion(

View File

@ -85,7 +85,7 @@ public interface IBlogPost
/// Gets the visibility of the post.
/// </summary>
/// <value>The visibility of the post.</value>
BlogPostVisibility Visibility { get; }
Visibility Visibility { get; }
/// <summary>
/// Gets the WordPress ID of the post.

View File

@ -1,9 +1,9 @@
namespace OliverBooth.Data.Blog;
namespace OliverBooth.Data;
/// <summary>
/// An enumeration of the possible visibilities of a blog post.
/// </summary>
public enum BlogPostVisibility
public enum Visibility
{
/// <summary>
/// The post is private and only visible to the author, or those with the password.

View File

@ -1,5 +1,6 @@
@page "/blog/{year:int}/{month:int}/{day:int}/{slug}"
@using Humanizer
@using OliverBooth.Data
@using OliverBooth.Data.Blog
@using OliverBooth.Services
@inject IBlogPostService BlogPostService
@ -44,13 +45,13 @@
@switch (post.Visibility)
{
case BlogPostVisibility.Private:
case Visibility.Private:
<div class="alert alert-danger" role="alert">
This post is private and can only be viewed by those with the password.
</div>
break;
case BlogPostVisibility.Unlisted:
case Visibility.Unlisted:
<div class="alert alert-warning" role="alert">
This post is unlisted and can only be viewed by those with the link.
</div>

View File

@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis;
using Humanizer;
using Markdig;
using Microsoft.EntityFrameworkCore;
using OliverBooth.Data;
using OliverBooth.Data.Blog;
namespace OliverBooth.Services;
@ -44,7 +45,7 @@ internal sealed class BlogPostService : IBlogPostService
{
using BlogContext context = _dbContextFactory.CreateDbContext();
IQueryable<BlogPost> ordered = context.BlogPosts
.Where(p => p.Visibility == BlogPostVisibility.Published)
.Where(p => p.Visibility == Visibility.Published)
.OrderByDescending(post => post.Published);
if (limit > -1)
{
@ -59,7 +60,7 @@ internal sealed class BlogPostService : IBlogPostService
{
using BlogContext context = _dbContextFactory.CreateDbContext();
return context.BlogPosts
.Where(p => p.Visibility == BlogPostVisibility.Published)
.Where(p => p.Visibility == Visibility.Published)
.OrderByDescending(post => post.Published)
.Skip(page * pageSize)
.Take(pageSize)
@ -71,7 +72,7 @@ internal sealed class BlogPostService : IBlogPostService
{
using BlogContext context = _dbContextFactory.CreateDbContext();
return context.BlogPosts
.Where(p => p.Visibility == BlogPostVisibility.Published)
.Where(p => p.Visibility == Visibility.Published)
.OrderBy(post => post.Published)
.FirstOrDefault(post => post.Published > blogPost.Published);
}
@ -81,7 +82,7 @@ internal sealed class BlogPostService : IBlogPostService
{
using BlogContext context = _dbContextFactory.CreateDbContext();
return context.BlogPosts
.Where(p => p.Visibility == BlogPostVisibility.Published)
.Where(p => p.Visibility == Visibility.Published)
.OrderByDescending(post => post.Published)
.FirstOrDefault(post => post.Published < blogPost.Published);
}