refactor: move BlogPostVisibility to Visibility
shared enum for blog posts and tutorials, and anything else that may need it
This commit is contained in:
parent
8629f8f963
commit
577f3b0148
@ -44,7 +44,7 @@ internal sealed class BlogPost : IBlogPost
|
|||||||
public DateTimeOffset? Updated { get; internal set; }
|
public DateTimeOffset? Updated { get; internal set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public BlogPostVisibility Visibility { get; internal set; }
|
public Visibility Visibility { get; internal set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public int? WordPressId { get; set; }
|
public int? WordPressId { get; set; }
|
||||||
|
@ -26,7 +26,7 @@ internal sealed class BlogPostConfiguration : IEntityTypeConfiguration<BlogPost>
|
|||||||
builder.Property(e => e.DisqusDomain).IsRequired(false);
|
builder.Property(e => e.DisqusDomain).IsRequired(false);
|
||||||
builder.Property(e => e.DisqusIdentifier).IsRequired(false);
|
builder.Property(e => e.DisqusIdentifier).IsRequired(false);
|
||||||
builder.Property(e => e.DisqusPath).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.Password).HasMaxLength(255).IsRequired(false);
|
||||||
builder.Property(e => e.Tags).IsRequired()
|
builder.Property(e => e.Tags).IsRequired()
|
||||||
.HasConversion(
|
.HasConversion(
|
||||||
|
@ -85,7 +85,7 @@ public interface IBlogPost
|
|||||||
/// Gets the visibility of the post.
|
/// Gets the visibility of the post.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The visibility of the post.</value>
|
/// <value>The visibility of the post.</value>
|
||||||
BlogPostVisibility Visibility { get; }
|
Visibility Visibility { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the WordPress ID of the post.
|
/// Gets the WordPress ID of the post.
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
namespace OliverBooth.Data.Blog;
|
namespace OliverBooth.Data;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An enumeration of the possible visibilities of a blog post.
|
/// An enumeration of the possible visibilities of a blog post.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum BlogPostVisibility
|
public enum Visibility
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The post is private and only visible to the author, or those with the password.
|
/// The post is private and only visible to the author, or those with the password.
|
@ -1,5 +1,6 @@
|
|||||||
@page "/blog/{year:int}/{month:int}/{day:int}/{slug}"
|
@page "/blog/{year:int}/{month:int}/{day:int}/{slug}"
|
||||||
@using Humanizer
|
@using Humanizer
|
||||||
|
@using OliverBooth.Data
|
||||||
@using OliverBooth.Data.Blog
|
@using OliverBooth.Data.Blog
|
||||||
@using OliverBooth.Services
|
@using OliverBooth.Services
|
||||||
@inject IBlogPostService BlogPostService
|
@inject IBlogPostService BlogPostService
|
||||||
@ -44,13 +45,13 @@
|
|||||||
|
|
||||||
@switch (post.Visibility)
|
@switch (post.Visibility)
|
||||||
{
|
{
|
||||||
case BlogPostVisibility.Private:
|
case Visibility.Private:
|
||||||
<div class="alert alert-danger" role="alert">
|
<div class="alert alert-danger" role="alert">
|
||||||
This post is private and can only be viewed by those with the password.
|
This post is private and can only be viewed by those with the password.
|
||||||
</div>
|
</div>
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BlogPostVisibility.Unlisted:
|
case Visibility.Unlisted:
|
||||||
<div class="alert alert-warning" role="alert">
|
<div class="alert alert-warning" role="alert">
|
||||||
This post is unlisted and can only be viewed by those with the link.
|
This post is unlisted and can only be viewed by those with the link.
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using Humanizer;
|
using Humanizer;
|
||||||
using Markdig;
|
using Markdig;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using OliverBooth.Data;
|
||||||
using OliverBooth.Data.Blog;
|
using OliverBooth.Data.Blog;
|
||||||
|
|
||||||
namespace OliverBooth.Services;
|
namespace OliverBooth.Services;
|
||||||
@ -44,7 +45,7 @@ internal sealed class BlogPostService : IBlogPostService
|
|||||||
{
|
{
|
||||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||||
IQueryable<BlogPost> ordered = context.BlogPosts
|
IQueryable<BlogPost> ordered = context.BlogPosts
|
||||||
.Where(p => p.Visibility == BlogPostVisibility.Published)
|
.Where(p => p.Visibility == Visibility.Published)
|
||||||
.OrderByDescending(post => post.Published);
|
.OrderByDescending(post => post.Published);
|
||||||
if (limit > -1)
|
if (limit > -1)
|
||||||
{
|
{
|
||||||
@ -59,7 +60,7 @@ internal sealed class BlogPostService : IBlogPostService
|
|||||||
{
|
{
|
||||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||||
return context.BlogPosts
|
return context.BlogPosts
|
||||||
.Where(p => p.Visibility == BlogPostVisibility.Published)
|
.Where(p => p.Visibility == Visibility.Published)
|
||||||
.OrderByDescending(post => post.Published)
|
.OrderByDescending(post => post.Published)
|
||||||
.Skip(page * pageSize)
|
.Skip(page * pageSize)
|
||||||
.Take(pageSize)
|
.Take(pageSize)
|
||||||
@ -71,7 +72,7 @@ internal sealed class BlogPostService : IBlogPostService
|
|||||||
{
|
{
|
||||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||||
return context.BlogPosts
|
return context.BlogPosts
|
||||||
.Where(p => p.Visibility == BlogPostVisibility.Published)
|
.Where(p => p.Visibility == Visibility.Published)
|
||||||
.OrderBy(post => post.Published)
|
.OrderBy(post => post.Published)
|
||||||
.FirstOrDefault(post => post.Published > blogPost.Published);
|
.FirstOrDefault(post => post.Published > blogPost.Published);
|
||||||
}
|
}
|
||||||
@ -81,7 +82,7 @@ internal sealed class BlogPostService : IBlogPostService
|
|||||||
{
|
{
|
||||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||||
return context.BlogPosts
|
return context.BlogPosts
|
||||||
.Where(p => p.Visibility == BlogPostVisibility.Published)
|
.Where(p => p.Visibility == Visibility.Published)
|
||||||
.OrderByDescending(post => post.Published)
|
.OrderByDescending(post => post.Published)
|
||||||
.FirstOrDefault(post => post.Published < blogPost.Published);
|
.FirstOrDefault(post => post.Published < blogPost.Published);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user