feat(blog): add post visibility and password
This commit is contained in:
parent
06fd256ec8
commit
0e583de316
|
@ -22,6 +22,9 @@ internal sealed class BlogPost : IBlogPost
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool IsRedirect { get; internal set; }
|
public bool IsRedirect { get; internal set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string? Password { get; internal set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTimeOffset Published { get; internal set; }
|
public DateTimeOffset Published { get; internal set; }
|
||||||
|
|
||||||
|
@ -37,6 +40,9 @@ internal sealed class BlogPost : IBlogPost
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTimeOffset? Updated { get; internal set; }
|
public DateTimeOffset? Updated { get; internal set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public BlogPostVisibility Visibility { get; internal set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public int? WordPressId { get; set; }
|
public int? WordPressId { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
namespace OliverBooth.Data.Blog;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An enumeration of the possible visibilities of a blog post.
|
||||||
|
/// </summary>
|
||||||
|
public enum BlogPostVisibility
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The post is private and only visible to the author, or those with the password.
|
||||||
|
/// </summary>
|
||||||
|
Private,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The post is unlisted and only visible to those with the link.
|
||||||
|
/// </summary>
|
||||||
|
Unlisted,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The post is published and visible to everyone.
|
||||||
|
/// </summary>
|
||||||
|
Published
|
||||||
|
}
|
|
@ -26,5 +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.Password).HasMaxLength(255).IsRequired(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,12 @@ public interface IBlogPost
|
||||||
/// </value>
|
/// </value>
|
||||||
bool IsRedirect { get; }
|
bool IsRedirect { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the password of the post.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The password of the post.</value>
|
||||||
|
string? Password { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the date and time the post was published.
|
/// Gets the date and time the post was published.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -69,6 +75,12 @@ public interface IBlogPost
|
||||||
/// <value>The update date and time, or <see langword="null" /> if the post has not been updated.</value>
|
/// <value>The update date and time, or <see langword="null" /> if the post has not been updated.</value>
|
||||||
DateTimeOffset? Updated { get; }
|
DateTimeOffset? Updated { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the visibility of the post.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The visibility of the post.</value>
|
||||||
|
BlogPostVisibility Visibility { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the WordPress ID of the post.
|
/// Gets the WordPress ID of the post.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -43,7 +43,9 @@ internal sealed class BlogPostService : IBlogPostService
|
||||||
public IReadOnlyList<IBlogPost> GetAllBlogPosts(int limit = -1)
|
public IReadOnlyList<IBlogPost> GetAllBlogPosts(int limit = -1)
|
||||||
{
|
{
|
||||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||||
IQueryable<BlogPost> ordered = context.BlogPosts.OrderByDescending(post => post.Published);
|
IQueryable<BlogPost> ordered = context.BlogPosts
|
||||||
|
.Where(p => p.Visibility == BlogPostVisibility.Published)
|
||||||
|
.OrderByDescending(post => post.Published);
|
||||||
if (limit > -1)
|
if (limit > -1)
|
||||||
{
|
{
|
||||||
ordered = ordered.Take(limit);
|
ordered = ordered.Take(limit);
|
||||||
|
@ -57,6 +59,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)
|
||||||
.OrderByDescending(post => post.Published)
|
.OrderByDescending(post => post.Published)
|
||||||
.Skip(page * pageSize)
|
.Skip(page * pageSize)
|
||||||
.Take(pageSize)
|
.Take(pageSize)
|
||||||
|
|
Loading…
Reference in New Issue