feat: add visibility search to GetAllBlogPosts
This commit is contained in:
parent
9593979d7b
commit
1d1acd2a40
@ -41,12 +41,17 @@ internal sealed class BlogPostService : IBlogPostService
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<IBlogPost> GetAllBlogPosts(int limit = -1)
|
||||
public IReadOnlyList<IBlogPost> GetAllBlogPosts(int limit = -1,
|
||||
BlogPostVisibility visibility = BlogPostVisibility.Published)
|
||||
{
|
||||
using BlogContext context = _dbContextFactory.CreateDbContext();
|
||||
IQueryable<BlogPost> ordered = context.BlogPosts
|
||||
.Where(p => p.Visibility == BlogPostVisibility.Published)
|
||||
.OrderByDescending(post => post.Published);
|
||||
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);
|
||||
|
@ -12,12 +12,14 @@ 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.
|
||||
|
Loading…
Reference in New Issue
Block a user