diff --git a/OliverBooth/Data/Visibility.cs b/OliverBooth/Data/Visibility.cs index 6f96339..17b3e87 100644 --- a/OliverBooth/Data/Visibility.cs +++ b/OliverBooth/Data/Visibility.cs @@ -5,6 +5,11 @@ namespace OliverBooth.Data; /// public enum Visibility { + /// + /// Used for filtering results. Represents all visibilities. + /// + None = -1, + /// /// The post is private and only visible to the author, or those with the password. /// diff --git a/OliverBooth/Data/Web/ITutorialArticle.cs b/OliverBooth/Data/Web/ITutorialArticle.cs index a52ac3d..c1be295 100644 --- a/OliverBooth/Data/Web/ITutorialArticle.cs +++ b/OliverBooth/Data/Web/ITutorialArticle.cs @@ -64,4 +64,10 @@ public interface ITutorialArticle /// /// The update timestamp, or if this article has not been updated. DateTimeOffset? Updated { get; } + + /// + /// Gets the visibility of this article. + /// + /// The visibility of the article. + Visibility Visibility { get; } } diff --git a/OliverBooth/Data/Web/ITutorialFolder.cs b/OliverBooth/Data/Web/ITutorialFolder.cs index 7195c68..65a3cd2 100644 --- a/OliverBooth/Data/Web/ITutorialFolder.cs +++ b/OliverBooth/Data/Web/ITutorialFolder.cs @@ -34,4 +34,10 @@ public interface ITutorialFolder /// /// The title. string Title { get; } -} \ No newline at end of file + + /// + /// Gets the visibility of this article. + /// + /// The visibility of the article. + Visibility Visibility { get; } +} diff --git a/OliverBooth/Data/Web/TutorialArticle.cs b/OliverBooth/Data/Web/TutorialArticle.cs index 0389473..1938e75 100644 --- a/OliverBooth/Data/Web/TutorialArticle.cs +++ b/OliverBooth/Data/Web/TutorialArticle.cs @@ -35,6 +35,9 @@ internal sealed class TutorialArticle : IEquatable, ITutorialAr /// public DateTimeOffset? Updated { get; private set; } + /// + public Visibility Visibility { get; private set; } + /// /// Returns a value indicating whether two instances of are equal. /// diff --git a/OliverBooth/Data/Web/TutorialFolder.cs b/OliverBooth/Data/Web/TutorialFolder.cs index 372b960..26c5bc1 100644 --- a/OliverBooth/Data/Web/TutorialFolder.cs +++ b/OliverBooth/Data/Web/TutorialFolder.cs @@ -20,6 +20,9 @@ internal sealed class TutorialFolder : IEquatable, ITutorialFold /// public string Title { get; private set; } = string.Empty; + /// + public Visibility Visibility { get; private set; } + /// /// Returns a value indicating whether two instances of are equal. /// @@ -80,4 +83,4 @@ internal sealed class TutorialFolder : IEquatable, ITutorialFold // ReSharper disable once NonReadonlyMemberInGetHashCode return Id; } -} \ No newline at end of file +} diff --git a/OliverBooth/Services/ITutorialService.cs b/OliverBooth/Services/ITutorialService.cs index 364ad77..ad85bbf 100644 --- a/OliverBooth/Services/ITutorialService.cs +++ b/OliverBooth/Services/ITutorialService.cs @@ -1,4 +1,5 @@ using System.Diagnostics.CodeAnalysis; +using OliverBooth.Data; using OliverBooth.Data.Web; namespace OliverBooth.Services; @@ -12,14 +13,17 @@ public interface ITutorialService /// Gets the articles within a tutorial folder. /// /// The folder whose articles to retrieve. + /// The visibility to filter by. -1 does not filter. /// A read-only view of the articles in the folder. - IReadOnlyCollection GetArticles(ITutorialFolder folder); + IReadOnlyCollection GetArticles(ITutorialFolder folder, Visibility visibility = Visibility.None); /// /// Gets the tutorial folders within a specified folder. /// + /// The parent folder. + /// The visibility to filter by. -1 does not filter. /// A read-only view of the subfolders in the folder. - IReadOnlyCollection GetFolders(ITutorialFolder? parent = null); + IReadOnlyCollection GetFolders(ITutorialFolder? parent = null, Visibility visibility = Visibility.None); /// /// Gets a folder by its ID. diff --git a/OliverBooth/Services/TutorialService.cs b/OliverBooth/Services/TutorialService.cs index 0039095..e8d6c9d 100644 --- a/OliverBooth/Services/TutorialService.cs +++ b/OliverBooth/Services/TutorialService.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using Cysharp.Text; using Markdig; using Microsoft.EntityFrameworkCore; +using OliverBooth.Data; using OliverBooth.Data.Web; namespace OliverBooth.Services; @@ -23,20 +24,28 @@ internal sealed class TutorialService : ITutorialService } /// - public IReadOnlyCollection GetArticles(ITutorialFolder folder) + public IReadOnlyCollection GetArticles(ITutorialFolder folder, + Visibility visibility = Visibility.None) { if (folder is null) throw new ArgumentNullException(nameof(folder)); using WebContext context = _dbContextFactory.CreateDbContext(); - return context.TutorialArticles.Where(a => a.Folder == folder.Id).ToArray(); + IQueryable articles = context.TutorialArticles.Where(a => a.Folder == folder.Id); + + if (visibility != Visibility.None) articles = articles.Where(a => a.Visibility == visibility); + return articles.ToArray(); } /// - public IReadOnlyCollection GetFolders(ITutorialFolder? parent = null) + public IReadOnlyCollection GetFolders(ITutorialFolder? parent = null, + Visibility visibility = Visibility.None) { using WebContext context = _dbContextFactory.CreateDbContext(); - if (parent is null) return context.TutorialFolders.Where(f => f.Parent == null).ToArray(); - return context.TutorialFolders.Where(a => a.Parent == parent.Id).ToArray(); + IQueryable folders = context.TutorialFolders; + + folders = parent is null ? folders.Where(f => f.Parent == null) : folders.Where(f => f.Parent == parent.Id); + if (visibility != Visibility.None) folders = folders.Where(a => a.Visibility == visibility); + return folders.ToArray(); } ///