diff --git a/OliverBooth/Data/Blog/BlogContext.cs b/OliverBooth.Common/Data/Blog/BlogContext.cs similarity index 92% rename from OliverBooth/Data/Blog/BlogContext.cs rename to OliverBooth.Common/Data/Blog/BlogContext.cs index 1dead2e..b1f56fe 100644 --- a/OliverBooth/Data/Blog/BlogContext.cs +++ b/OliverBooth.Common/Data/Blog/BlogContext.cs @@ -1,7 +1,8 @@ using Microsoft.EntityFrameworkCore; -using OliverBooth.Data.Blog.Configuration; +using Microsoft.Extensions.Configuration; +using OliverBooth.Common.Data.Blog.Configuration; -namespace OliverBooth.Data.Blog; +namespace OliverBooth.Common.Data.Blog; /// /// Represents a session with the blog database. diff --git a/OliverBooth/Data/Blog/BlogPost.cs b/OliverBooth.Common/Data/Blog/BlogPost.cs similarity index 96% rename from OliverBooth/Data/Blog/BlogPost.cs rename to OliverBooth.Common/Data/Blog/BlogPost.cs index 7be2a16..c662a5a 100644 --- a/OliverBooth/Data/Blog/BlogPost.cs +++ b/OliverBooth.Common/Data/Blog/BlogPost.cs @@ -1,14 +1,14 @@ using System.ComponentModel.DataAnnotations.Schema; using SmartFormat; -namespace OliverBooth.Data.Blog; +namespace OliverBooth.Common.Data.Blog; /// internal sealed class BlogPost : IBlogPost { /// [NotMapped] - public IBlogAuthor Author { get; internal set; } = null!; + public IAuthor Author { get; internal set; } = null!; /// public string Body { get; set; } = string.Empty; diff --git a/OliverBooth/Data/Blog/BlogPostDraft.cs b/OliverBooth.Common/Data/Blog/BlogPostDraft.cs similarity index 97% rename from OliverBooth/Data/Blog/BlogPostDraft.cs rename to OliverBooth.Common/Data/Blog/BlogPostDraft.cs index 3c5a027..a9673b5 100644 --- a/OliverBooth/Data/Blog/BlogPostDraft.cs +++ b/OliverBooth.Common/Data/Blog/BlogPostDraft.cs @@ -1,14 +1,14 @@ using System.ComponentModel.DataAnnotations.Schema; using SmartFormat; -namespace OliverBooth.Data.Blog; +namespace OliverBooth.Common.Data.Blog; /// internal sealed class BlogPostDraft : IBlogPostDraft { /// [NotMapped] - public IBlogAuthor Author { get; internal set; } = null!; + public IAuthor Author { get; internal set; } = null!; /// public string Body { get; set; } = string.Empty; diff --git a/OliverBooth/Data/Blog/BlogPostVisibility.cs b/OliverBooth.Common/Data/Blog/BlogPostVisibility.cs similarity index 92% rename from OliverBooth/Data/Blog/BlogPostVisibility.cs rename to OliverBooth.Common/Data/Blog/BlogPostVisibility.cs index d8e982a..72bd17e 100644 --- a/OliverBooth/Data/Blog/BlogPostVisibility.cs +++ b/OliverBooth.Common/Data/Blog/BlogPostVisibility.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Blog; +namespace OliverBooth.Common.Data.Blog; /// /// An enumeration of the possible visibilities of a blog post. diff --git a/OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs b/OliverBooth.Common/Data/Blog/Configuration/BlogPostConfiguration.cs similarity index 97% rename from OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs rename to OliverBooth.Common/Data/Blog/Configuration/BlogPostConfiguration.cs index 7c89b2b..82657c6 100644 --- a/OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs +++ b/OliverBooth.Common/Data/Blog/Configuration/BlogPostConfiguration.cs @@ -2,7 +2,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -namespace OliverBooth.Data.Blog.Configuration; +namespace OliverBooth.Common.Data.Blog.Configuration; internal sealed class BlogPostConfiguration : IEntityTypeConfiguration { diff --git a/OliverBooth/Data/Blog/Configuration/BlogPostDraftConfiguration.cs b/OliverBooth.Common/Data/Blog/Configuration/BlogPostDraftConfiguration.cs similarity index 97% rename from OliverBooth/Data/Blog/Configuration/BlogPostDraftConfiguration.cs rename to OliverBooth.Common/Data/Blog/Configuration/BlogPostDraftConfiguration.cs index 9c2f760..2a305c8 100644 --- a/OliverBooth/Data/Blog/Configuration/BlogPostDraftConfiguration.cs +++ b/OliverBooth.Common/Data/Blog/Configuration/BlogPostDraftConfiguration.cs @@ -2,7 +2,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -namespace OliverBooth.Data.Blog.Configuration; +namespace OliverBooth.Common.Data.Blog.Configuration; internal sealed class BlogPostDraftConfiguration : IEntityTypeConfiguration { diff --git a/OliverBooth/Data/Blog/IBlogAuthor.cs b/OliverBooth.Common/Data/Blog/IAuthor.cs similarity index 92% rename from OliverBooth/Data/Blog/IBlogAuthor.cs rename to OliverBooth.Common/Data/Blog/IAuthor.cs index 3f1c3e1..1ebc851 100644 --- a/OliverBooth/Data/Blog/IBlogAuthor.cs +++ b/OliverBooth.Common/Data/Blog/IAuthor.cs @@ -1,9 +1,9 @@ -namespace OliverBooth.Data.Blog; +namespace OliverBooth.Common.Data.Blog; /// /// Represents the author of a blog post. /// -public interface IBlogAuthor +public interface IAuthor { /// /// Gets the URL of the author's avatar. diff --git a/OliverBooth/Data/Blog/IBlogPost.cs b/OliverBooth.Common/Data/Blog/IBlogPost.cs similarity index 98% rename from OliverBooth/Data/Blog/IBlogPost.cs rename to OliverBooth.Common/Data/Blog/IBlogPost.cs index 8daaaad..e92b574 100644 --- a/OliverBooth/Data/Blog/IBlogPost.cs +++ b/OliverBooth.Common/Data/Blog/IBlogPost.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Blog; +namespace OliverBooth.Common.Data.Blog; /// /// Represents a blog post. @@ -9,7 +9,7 @@ public interface IBlogPost /// Gets the author of the post. /// /// The author of the post. - IBlogAuthor Author { get; } + IAuthor Author { get; } /// /// Gets or sets the body of the post. diff --git a/OliverBooth/Data/Blog/IBlogPostDraft.cs b/OliverBooth.Common/Data/Blog/IBlogPostDraft.cs similarity index 97% rename from OliverBooth/Data/Blog/IBlogPostDraft.cs rename to OliverBooth.Common/Data/Blog/IBlogPostDraft.cs index 1d66c2b..032fc01 100644 --- a/OliverBooth/Data/Blog/IBlogPostDraft.cs +++ b/OliverBooth.Common/Data/Blog/IBlogPostDraft.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Blog; +namespace OliverBooth.Common.Data.Blog; /// /// Represents a draft of a blog post. @@ -9,7 +9,7 @@ public interface IBlogPostDraft /// Gets the author of the post. /// /// The author of the post. - IBlogAuthor Author { get; } + IAuthor Author { get; } /// /// Gets or sets the body of the post. diff --git a/OliverBooth/Data/Permission.cs b/OliverBooth.Common/Data/Permission.cs similarity index 96% rename from OliverBooth/Data/Permission.cs rename to OliverBooth.Common/Data/Permission.cs index 6ad2376..fb3e35c 100644 --- a/OliverBooth/Data/Permission.cs +++ b/OliverBooth.Common/Data/Permission.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data; +namespace OliverBooth.Common.Data; /// /// Represents a permission. diff --git a/OliverBooth/Data/PermissionListConverter.cs b/OliverBooth.Common/Data/ValueConverters/PermissionListConverter.cs similarity index 95% rename from OliverBooth/Data/PermissionListConverter.cs rename to OliverBooth.Common/Data/ValueConverters/PermissionListConverter.cs index 3dd86a2..8bb7c96 100644 --- a/OliverBooth/Data/PermissionListConverter.cs +++ b/OliverBooth.Common/Data/ValueConverters/PermissionListConverter.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -namespace OliverBooth.Data; +namespace OliverBooth.Common.Data.ValueConverters; internal sealed class PermissionListConverter : ValueConverter, string> { diff --git a/OliverBooth/Data/Web/Book.cs b/OliverBooth.Common/Data/Web/Books/Book.cs similarity index 94% rename from OliverBooth/Data/Web/Book.cs rename to OliverBooth.Common/Data/Web/Books/Book.cs index 278aa4e..750ee74 100644 --- a/OliverBooth/Data/Web/Book.cs +++ b/OliverBooth.Common/Data/Web/Books/Book.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp; using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.Processing; -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Books; /// /// Represents a book. diff --git a/OliverBooth/Data/Web/BookState.cs b/OliverBooth.Common/Data/Web/Books/BookState.cs similarity index 89% rename from OliverBooth/Data/Web/BookState.cs rename to OliverBooth.Common/Data/Web/Books/BookState.cs index 637415a..83dcefd 100644 --- a/OliverBooth/Data/Web/BookState.cs +++ b/OliverBooth.Common/Data/Web/Books/BookState.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Books; /// /// Represents the state of a book. diff --git a/OliverBooth/Data/Web/IBook.cs b/OliverBooth.Common/Data/Web/Books/IBook.cs similarity index 95% rename from OliverBooth/Data/Web/IBook.cs rename to OliverBooth.Common/Data/Web/Books/IBook.cs index 5c71d85..7e443a2 100644 --- a/OliverBooth/Data/Web/IBook.cs +++ b/OliverBooth.Common/Data/Web/Books/IBook.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Books; /// /// Represents a book. diff --git a/OliverBooth/Data/Web/Configuration/BlacklistEntryConfiguration.cs b/OliverBooth.Common/Data/Web/Configuration/BlacklistEntryConfiguration.cs similarity index 87% rename from OliverBooth/Data/Web/Configuration/BlacklistEntryConfiguration.cs rename to OliverBooth.Common/Data/Web/Configuration/BlacklistEntryConfiguration.cs index 6d6f570..a53f3e5 100644 --- a/OliverBooth/Data/Web/Configuration/BlacklistEntryConfiguration.cs +++ b/OliverBooth.Common/Data/Web/Configuration/BlacklistEntryConfiguration.cs @@ -1,7 +1,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; +using OliverBooth.Common.Data.Web.Contact; -namespace OliverBooth.Data.Web.Configuration; +namespace OliverBooth.Common.Data.Web.Configuration; /// /// Represents the configuration for the entity. diff --git a/OliverBooth/Data/Web/Configuration/BookConfiguration.cs b/OliverBooth.Common/Data/Web/Configuration/BookConfiguration.cs similarity index 89% rename from OliverBooth/Data/Web/Configuration/BookConfiguration.cs rename to OliverBooth.Common/Data/Web/Configuration/BookConfiguration.cs index f27a1d2..c6c3c08 100644 --- a/OliverBooth/Data/Web/Configuration/BookConfiguration.cs +++ b/OliverBooth.Common/Data/Web/Configuration/BookConfiguration.cs @@ -1,8 +1,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OliverBooth.Common.Data.Web.Books; -namespace OliverBooth.Data.Web.Configuration; +namespace OliverBooth.Common.Data.Web.Configuration; /// /// Represents the configuration for the entity. diff --git a/OliverBooth/Data/Web/Configuration/ProgrammingLanguageConfiguration.cs b/OliverBooth.Common/Data/Web/Configuration/ProgrammingLanguageConfiguration.cs similarity index 86% rename from OliverBooth/Data/Web/Configuration/ProgrammingLanguageConfiguration.cs rename to OliverBooth.Common/Data/Web/Configuration/ProgrammingLanguageConfiguration.cs index 521ab7e..11a2973 100644 --- a/OliverBooth/Data/Web/Configuration/ProgrammingLanguageConfiguration.cs +++ b/OliverBooth.Common/Data/Web/Configuration/ProgrammingLanguageConfiguration.cs @@ -1,7 +1,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; +using OliverBooth.Common.Data.Web.Projects; -namespace OliverBooth.Data.Web.Configuration; +namespace OliverBooth.Common.Data.Web.Configuration; /// /// Represents the configuration for the entity. diff --git a/OliverBooth/Data/Web/Configuration/ProjectConfiguration.cs b/OliverBooth.Common/Data/Web/Configuration/ProjectConfiguration.cs similarity index 92% rename from OliverBooth/Data/Web/Configuration/ProjectConfiguration.cs rename to OliverBooth.Common/Data/Web/Configuration/ProjectConfiguration.cs index 08ef5d9..5b01f79 100644 --- a/OliverBooth/Data/Web/Configuration/ProjectConfiguration.cs +++ b/OliverBooth.Common/Data/Web/Configuration/ProjectConfiguration.cs @@ -1,8 +1,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OliverBooth.Common.Data.Web.Projects; -namespace OliverBooth.Data.Web.Configuration; +namespace OliverBooth.Common.Data.Web.Configuration; /// /// Represents the configuration for the entity. diff --git a/OliverBooth/Data/Web/Configuration/SessionConfiguration.cs b/OliverBooth.Common/Data/Web/Configuration/SessionConfiguration.cs similarity index 91% rename from OliverBooth/Data/Web/Configuration/SessionConfiguration.cs rename to OliverBooth.Common/Data/Web/Configuration/SessionConfiguration.cs index b41c566..cd92b7d 100644 --- a/OliverBooth/Data/Web/Configuration/SessionConfiguration.cs +++ b/OliverBooth.Common/Data/Web/Configuration/SessionConfiguration.cs @@ -1,8 +1,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OliverBooth.Common.Data.Web.Users; -namespace OliverBooth.Data.Web.Configuration; +namespace OliverBooth.Common.Data.Web.Configuration; internal sealed class SessionConfiguration : IEntityTypeConfiguration { diff --git a/OliverBooth/Data/Web/Configuration/SiteConfigurationConfiguration.cs b/OliverBooth.Common/Data/Web/Configuration/SiteConfigurationConfiguration.cs similarity index 92% rename from OliverBooth/Data/Web/Configuration/SiteConfigurationConfiguration.cs rename to OliverBooth.Common/Data/Web/Configuration/SiteConfigurationConfiguration.cs index 9fbcb2a..21128a2 100644 --- a/OliverBooth/Data/Web/Configuration/SiteConfigurationConfiguration.cs +++ b/OliverBooth.Common/Data/Web/Configuration/SiteConfigurationConfiguration.cs @@ -1,7 +1,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace OliverBooth.Data.Web.Configuration; +namespace OliverBooth.Common.Data.Web.Configuration; /// /// Represents the configuration for the entity. diff --git a/OliverBooth/Data/Web/Configuration/TemplateConfiguration.cs b/OliverBooth.Common/Data/Web/Configuration/TemplateConfiguration.cs similarity index 92% rename from OliverBooth/Data/Web/Configuration/TemplateConfiguration.cs rename to OliverBooth.Common/Data/Web/Configuration/TemplateConfiguration.cs index 512b5ab..c4b3b01 100644 --- a/OliverBooth/Data/Web/Configuration/TemplateConfiguration.cs +++ b/OliverBooth.Common/Data/Web/Configuration/TemplateConfiguration.cs @@ -1,7 +1,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace OliverBooth.Data.Web.Configuration; +namespace OliverBooth.Common.Data.Web.Configuration; /// /// Represents the configuration for the entity. diff --git a/OliverBooth/Data/Web/Configuration/UserConfiguration.cs b/OliverBooth.Common/Data/Web/Configuration/UserConfiguration.cs similarity index 85% rename from OliverBooth/Data/Web/Configuration/UserConfiguration.cs rename to OliverBooth.Common/Data/Web/Configuration/UserConfiguration.cs index c6be0cc..c08dafb 100644 --- a/OliverBooth/Data/Web/Configuration/UserConfiguration.cs +++ b/OliverBooth.Common/Data/Web/Configuration/UserConfiguration.cs @@ -1,7 +1,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; +using OliverBooth.Common.Data.ValueConverters; +using OliverBooth.Common.Data.Web.Users; -namespace OliverBooth.Data.Web.Configuration; +namespace OliverBooth.Common.Data.Web.Configuration; internal sealed class UserConfiguration : IEntityTypeConfiguration { diff --git a/OliverBooth/Data/Web/BlacklistEntry.cs b/OliverBooth.Common/Data/Web/Contact/BlacklistEntry.cs similarity index 98% rename from OliverBooth/Data/Web/BlacklistEntry.cs rename to OliverBooth.Common/Data/Web/Contact/BlacklistEntry.cs index 2141557..57972cf 100644 --- a/OliverBooth/Data/Web/BlacklistEntry.cs +++ b/OliverBooth.Common/Data/Web/Contact/BlacklistEntry.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Contact; /// internal sealed class BlacklistEntry : IEquatable, IBlacklistEntry diff --git a/OliverBooth/Data/Web/IBlacklistEntry.cs b/OliverBooth.Common/Data/Web/Contact/IBlacklistEntry.cs similarity index 92% rename from OliverBooth/Data/Web/IBlacklistEntry.cs rename to OliverBooth.Common/Data/Web/Contact/IBlacklistEntry.cs index 00516fb..535ece1 100644 --- a/OliverBooth/Data/Web/IBlacklistEntry.cs +++ b/OliverBooth.Common/Data/Web/Contact/IBlacklistEntry.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Contact; /// /// Represents an entry in the blacklist. diff --git a/OliverBooth/Data/Web/ITemplate.cs b/OliverBooth.Common/Data/Web/ITemplate.cs similarity index 92% rename from OliverBooth/Data/Web/ITemplate.cs rename to OliverBooth.Common/Data/Web/ITemplate.cs index 50ad893..b3bd1e5 100644 --- a/OliverBooth/Data/Web/ITemplate.cs +++ b/OliverBooth.Common/Data/Web/ITemplate.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web; /// /// Represents a template. diff --git a/OliverBooth/Data/Web/IProgrammingLanguage.cs b/OliverBooth.Common/Data/Web/Projects/IProgrammingLanguage.cs similarity index 91% rename from OliverBooth/Data/Web/IProgrammingLanguage.cs rename to OliverBooth.Common/Data/Web/Projects/IProgrammingLanguage.cs index 039f31a..4a24d4b 100644 --- a/OliverBooth/Data/Web/IProgrammingLanguage.cs +++ b/OliverBooth.Common/Data/Web/Projects/IProgrammingLanguage.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Projects; /// /// Represents a programming language. diff --git a/OliverBooth/Data/Web/IProject.cs b/OliverBooth.Common/Data/Web/Projects/IProject.cs similarity index 97% rename from OliverBooth/Data/Web/IProject.cs rename to OliverBooth.Common/Data/Web/Projects/IProject.cs index f2cc0d8..bd83946 100644 --- a/OliverBooth/Data/Web/IProject.cs +++ b/OliverBooth.Common/Data/Web/Projects/IProject.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Projects; /// /// Represents a project. diff --git a/OliverBooth/Data/Web/ProgrammingLanguage.cs b/OliverBooth.Common/Data/Web/Projects/ProgrammingLanguage.cs similarity index 98% rename from OliverBooth/Data/Web/ProgrammingLanguage.cs rename to OliverBooth.Common/Data/Web/Projects/ProgrammingLanguage.cs index 1c4de45..8e8e066 100644 --- a/OliverBooth/Data/Web/ProgrammingLanguage.cs +++ b/OliverBooth.Common/Data/Web/Projects/ProgrammingLanguage.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Projects; /// internal sealed class ProgrammingLanguage : IEquatable, IProgrammingLanguage diff --git a/OliverBooth/Data/Web/Project.cs b/OliverBooth.Common/Data/Web/Projects/Project.cs similarity index 98% rename from OliverBooth/Data/Web/Project.cs rename to OliverBooth.Common/Data/Web/Projects/Project.cs index 32868de..cfbe719 100644 --- a/OliverBooth/Data/Web/Project.cs +++ b/OliverBooth.Common/Data/Web/Projects/Project.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Projects; /// /// Represents a project. diff --git a/OliverBooth/Data/Web/ProjectStatus.cs b/OliverBooth.Common/Data/Web/Projects/ProjectStatus.cs similarity index 90% rename from OliverBooth/Data/Web/ProjectStatus.cs rename to OliverBooth.Common/Data/Web/Projects/ProjectStatus.cs index a3cbf49..301bb1a 100644 --- a/OliverBooth/Data/Web/ProjectStatus.cs +++ b/OliverBooth.Common/Data/Web/Projects/ProjectStatus.cs @@ -1,6 +1,6 @@ using System.ComponentModel; -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Projects; /// /// Represents the status of a project. diff --git a/OliverBooth/Data/Web/SiteConfiguration.cs b/OliverBooth.Common/Data/Web/SiteConfiguration.cs similarity index 98% rename from OliverBooth/Data/Web/SiteConfiguration.cs rename to OliverBooth.Common/Data/Web/SiteConfiguration.cs index 1bba964..08da76a 100644 --- a/OliverBooth/Data/Web/SiteConfiguration.cs +++ b/OliverBooth.Common/Data/Web/SiteConfiguration.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web; /// /// Represents a site configuration item. diff --git a/OliverBooth/Data/Web/Template.cs b/OliverBooth.Common/Data/Web/Template.cs similarity index 98% rename from OliverBooth/Data/Web/Template.cs rename to OliverBooth.Common/Data/Web/Template.cs index 0ef5d90..06765b4 100644 --- a/OliverBooth/Data/Web/Template.cs +++ b/OliverBooth.Common/Data/Web/Template.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web; /// /// Represents a MediaWiki-style template. diff --git a/OliverBooth/Data/Web/IMfaToken.cs b/OliverBooth.Common/Data/Web/Users/IMfaToken.cs similarity index 95% rename from OliverBooth/Data/Web/IMfaToken.cs rename to OliverBooth.Common/Data/Web/Users/IMfaToken.cs index 9c61e5d..0574744 100644 --- a/OliverBooth/Data/Web/IMfaToken.cs +++ b/OliverBooth.Common/Data/Web/Users/IMfaToken.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Users; /// /// Represents a temporary token used to correlate MFA attempts with the user. @@ -34,4 +34,4 @@ public interface IMfaToken /// /// The user. IUser User { get; } -} \ No newline at end of file +} diff --git a/OliverBooth/Data/Web/ISession.cs b/OliverBooth.Common/Data/Web/Users/ISession.cs similarity index 97% rename from OliverBooth/Data/Web/ISession.cs rename to OliverBooth.Common/Data/Web/Users/ISession.cs index d711057..7292ee4 100644 --- a/OliverBooth/Data/Web/ISession.cs +++ b/OliverBooth.Common/Data/Web/Users/ISession.cs @@ -1,6 +1,6 @@ using System.Net; -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Users; /// /// Represents a login session. diff --git a/OliverBooth/Data/Web/IUser.cs b/OliverBooth.Common/Data/Web/Users/IUser.cs similarity index 98% rename from OliverBooth/Data/Web/IUser.cs rename to OliverBooth.Common/Data/Web/Users/IUser.cs index fced72a..b71724f 100644 --- a/OliverBooth/Data/Web/IUser.cs +++ b/OliverBooth.Common/Data/Web/Users/IUser.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Users; /// /// Represents a user which can log in to the blog. diff --git a/OliverBooth/Data/Web/MfaRequestResult.cs b/OliverBooth.Common/Data/Web/Users/MfaRequestResult.cs similarity index 87% rename from OliverBooth/Data/Web/MfaRequestResult.cs rename to OliverBooth.Common/Data/Web/Users/MfaRequestResult.cs index d92a793..5c8e873 100644 --- a/OliverBooth/Data/Web/MfaRequestResult.cs +++ b/OliverBooth.Common/Data/Web/Users/MfaRequestResult.cs @@ -1,6 +1,6 @@ -using OliverBooth.Services; +using OliverBooth.Common.Services; -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Users; /// /// An enumeration of possible results for . diff --git a/OliverBooth/Data/Web/MfaToken.cs b/OliverBooth.Common/Data/Web/Users/MfaToken.cs similarity index 89% rename from OliverBooth/Data/Web/MfaToken.cs rename to OliverBooth.Common/Data/Web/Users/MfaToken.cs index b2a9951..9c7b482 100644 --- a/OliverBooth/Data/Web/MfaToken.cs +++ b/OliverBooth.Common/Data/Web/Users/MfaToken.cs @@ -1,4 +1,4 @@ -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Users; internal sealed class MfaToken : IMfaToken { diff --git a/OliverBooth/Data/Web/Session.cs b/OliverBooth.Common/Data/Web/Users/Session.cs similarity index 94% rename from OliverBooth/Data/Web/Session.cs rename to OliverBooth.Common/Data/Web/Users/Session.cs index b46624f..1b9e90e 100644 --- a/OliverBooth/Data/Web/Session.cs +++ b/OliverBooth.Common/Data/Web/Users/Session.cs @@ -1,6 +1,6 @@ using System.Net; -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Users; internal sealed class Session : ISession { diff --git a/OliverBooth/Data/Web/User.cs b/OliverBooth.Common/Data/Web/Users/User.cs similarity index 96% rename from OliverBooth/Data/Web/User.cs rename to OliverBooth.Common/Data/Web/Users/User.cs index 67d6efe..ad954da 100644 --- a/OliverBooth/Data/Web/User.cs +++ b/OliverBooth.Common/Data/Web/Users/User.cs @@ -2,15 +2,15 @@ using System.ComponentModel.DataAnnotations.Schema; using System.Security.Cryptography; using System.Text; using Cysharp.Text; -using OliverBooth.Data.Blog; +using OliverBooth.Common.Data.Blog; using OtpNet; -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web.Users; /// /// Represents a user. /// -internal sealed class User : IUser, IBlogAuthor +internal sealed class User : IUser, IAuthor { /// [NotMapped] diff --git a/OliverBooth/Data/Web/WebContext.cs b/OliverBooth.Common/Data/Web/WebContext.cs similarity index 91% rename from OliverBooth/Data/Web/WebContext.cs rename to OliverBooth.Common/Data/Web/WebContext.cs index 9f884c6..92fd285 100644 --- a/OliverBooth/Data/Web/WebContext.cs +++ b/OliverBooth.Common/Data/Web/WebContext.cs @@ -1,7 +1,12 @@ using Microsoft.EntityFrameworkCore; -using OliverBooth.Data.Web.Configuration; +using Microsoft.Extensions.Configuration; +using OliverBooth.Common.Data.Web.Books; +using OliverBooth.Common.Data.Web.Configuration; +using OliverBooth.Common.Data.Web.Contact; +using OliverBooth.Common.Data.Web.Projects; +using OliverBooth.Common.Data.Web.Users; -namespace OliverBooth.Data.Web; +namespace OliverBooth.Common.Data.Web; /// /// Represents a session with the web database. diff --git a/OliverBooth.Common/Extensions/DependencyInjectionExtensions.cs b/OliverBooth.Common/Extensions/DependencyInjectionExtensions.cs new file mode 100644 index 0000000..a383e71 --- /dev/null +++ b/OliverBooth.Common/Extensions/DependencyInjectionExtensions.cs @@ -0,0 +1,32 @@ +using Microsoft.Extensions.DependencyInjection; +using OliverBooth.Common.Data.Blog; +using OliverBooth.Common.Data.Web; +using OliverBooth.Common.Services; +using X10D.Hosting.DependencyInjection; + +namespace OliverBooth.Common.Extensions; + +/// +/// Extension methods for dependency injection. +/// +public static class DependencyInjectionExtensions +{ + /// + /// Adds all required services provided by the assembly to the current . + /// + /// The to add the service to. + public static void AddCommonServices(this IServiceCollection collection) + { + collection.AddDbContextFactory(); + collection.AddDbContextFactory(); + + collection.AddSingleton(); + collection.AddSingleton(); + collection.AddSingleton(); + collection.AddSingleton(); + collection.AddSingleton(); + + collection.AddHostedSingleton(); + collection.AddHostedSingleton(); + } +} diff --git a/OliverBooth/Formatting/DateFormatter.cs b/OliverBooth.Common/Formatting/DateFormatter.cs similarity index 95% rename from OliverBooth/Formatting/DateFormatter.cs rename to OliverBooth.Common/Formatting/DateFormatter.cs index 93479a8..9666d65 100644 --- a/OliverBooth/Formatting/DateFormatter.cs +++ b/OliverBooth.Common/Formatting/DateFormatter.cs @@ -1,7 +1,7 @@ using System.Globalization; using SmartFormat.Core.Extensions; -namespace OliverBooth.Formatting; +namespace OliverBooth.Common.Formatting; /// /// Represents a SmartFormat formatter that formats a date. diff --git a/OliverBooth/Formatting/MarkdownFormatter.cs b/OliverBooth.Common/Formatting/MarkdownFormatter.cs similarity index 92% rename from OliverBooth/Formatting/MarkdownFormatter.cs rename to OliverBooth.Common/Formatting/MarkdownFormatter.cs index ed515c5..d20e5a5 100644 --- a/OliverBooth/Formatting/MarkdownFormatter.cs +++ b/OliverBooth.Common/Formatting/MarkdownFormatter.cs @@ -1,7 +1,8 @@ using Markdig; +using Microsoft.Extensions.DependencyInjection; using SmartFormat.Core.Extensions; -namespace OliverBooth.Formatting; +namespace OliverBooth.Common.Formatting; /// /// Represents a SmartFormat formatter that formats markdown. diff --git a/OliverBooth/Markdown/Template/TemplateExtension.cs b/OliverBooth.Common/Markdown/Template/TemplateExtension.cs similarity index 92% rename from OliverBooth/Markdown/Template/TemplateExtension.cs rename to OliverBooth.Common/Markdown/Template/TemplateExtension.cs index ec1ea0d..76371cf 100644 --- a/OliverBooth/Markdown/Template/TemplateExtension.cs +++ b/OliverBooth.Common/Markdown/Template/TemplateExtension.cs @@ -1,8 +1,8 @@ using Markdig; using Markdig.Renderers; -using OliverBooth.Services; +using OliverBooth.Common.Services; -namespace OliverBooth.Markdown.Template; +namespace OliverBooth.Common.Markdown.Template; /// /// Represents a Markdown extension that adds support for MediaWiki-style templates. diff --git a/OliverBooth/Markdown/Template/TemplateInline.cs b/OliverBooth.Common/Markdown/Template/TemplateInline.cs similarity index 96% rename from OliverBooth/Markdown/Template/TemplateInline.cs rename to OliverBooth.Common/Markdown/Template/TemplateInline.cs index a50f3b8..dd6d26f 100644 --- a/OliverBooth/Markdown/Template/TemplateInline.cs +++ b/OliverBooth.Common/Markdown/Template/TemplateInline.cs @@ -1,6 +1,6 @@ using Markdig.Syntax.Inlines; -namespace OliverBooth.Markdown.Template; +namespace OliverBooth.Common.Markdown.Template; /// /// Represents a Markdown inline element that represents a MediaWiki-style template. diff --git a/OliverBooth/Markdown/Template/TemplateInlineParser.cs b/OliverBooth.Common/Markdown/Template/TemplateInlineParser.cs similarity index 98% rename from OliverBooth/Markdown/Template/TemplateInlineParser.cs rename to OliverBooth.Common/Markdown/Template/TemplateInlineParser.cs index 57385b3..27cd603 100644 --- a/OliverBooth/Markdown/Template/TemplateInlineParser.cs +++ b/OliverBooth.Common/Markdown/Template/TemplateInlineParser.cs @@ -2,7 +2,7 @@ using Cysharp.Text; using Markdig.Helpers; using Markdig.Parsers; -namespace OliverBooth.Markdown.Template; +namespace OliverBooth.Common.Markdown.Template; /// /// Represents a Markdown inline parser that handles MediaWiki-style templates. @@ -17,7 +17,7 @@ public sealed class TemplateInlineParser : InlineParser /// public TemplateInlineParser() { - OpeningCharacters = new[] { '{' }; + OpeningCharacters = ['{']; } /// diff --git a/OliverBooth/Markdown/Template/TemplateRenderer.cs b/OliverBooth.Common/Markdown/Template/TemplateRenderer.cs similarity index 90% rename from OliverBooth/Markdown/Template/TemplateRenderer.cs rename to OliverBooth.Common/Markdown/Template/TemplateRenderer.cs index 9e70fb2..c9f5f69 100644 --- a/OliverBooth/Markdown/Template/TemplateRenderer.cs +++ b/OliverBooth.Common/Markdown/Template/TemplateRenderer.cs @@ -1,8 +1,8 @@ using Markdig.Renderers; using Markdig.Renderers.Html; -using OliverBooth.Services; +using OliverBooth.Common.Services; -namespace OliverBooth.Markdown.Template; +namespace OliverBooth.Common.Markdown.Template; /// /// Represents a Markdown object renderer that handles elements. diff --git a/OliverBooth.Common/OliverBooth.Common.csproj b/OliverBooth.Common/OliverBooth.Common.csproj new file mode 100644 index 0000000..d7e38d1 --- /dev/null +++ b/OliverBooth.Common/OliverBooth.Common.csproj @@ -0,0 +1,34 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OliverBooth/Services/BlogPostService.cs b/OliverBooth.Common/Services/BlogPostService.cs similarity index 88% rename from OliverBooth/Services/BlogPostService.cs rename to OliverBooth.Common/Services/BlogPostService.cs index afde740..2f89ac4 100644 --- a/OliverBooth/Services/BlogPostService.cs +++ b/OliverBooth.Common/Services/BlogPostService.cs @@ -2,16 +2,28 @@ using System.Diagnostics.CodeAnalysis; using Humanizer; using Markdig; using Microsoft.EntityFrameworkCore; -using OliverBooth.Data.Blog; -using OliverBooth.Data.Web; +using OliverBooth.Common.Data.Blog; +using OliverBooth.Common.Data.Web.Users; -namespace OliverBooth.Services; +namespace OliverBooth.Common.Services; /// /// Represents an implementation of . /// internal sealed class BlogPostService : IBlogPostService { + /*private static readonly JsonSerializerOptions EditorJsOptions = new() + { + ReferenceHandler = ReferenceHandler.Preserve, + Converters = + { + new ParagraphBlockConverter(), + new HeadingBlockConverter(), + new MarkdownDocumentConverter() + } + }; + */ + private readonly IDbContextFactory _dbContextFactory; private readonly IUserService _userService; private readonly MarkdownPipeline _markdownPipeline; @@ -33,6 +45,19 @@ internal sealed class BlogPostService : IBlogPostService _markdownPipeline = markdownPipeline; } + /// + public string GetBlogPostEditorObject(IBlogPost post) + { + if (post is null) + { + throw new ArgumentNullException(nameof(post)); + } + + /*var document = (JsonDocument)Markdig.Markdown.Convert(post.Body, new JsonRenderer(), _markdownPipeline); + return JsonSerializer.Serialize(document, EditorJsOptions);*/ + return """{"blocks":{}}"""; + } + /// public int GetBlogPostCount() { @@ -196,7 +221,7 @@ internal sealed class BlogPostService : IBlogPostService return post; } - if (_userService.TryGetUser(post.AuthorId, out IUser? user) && user is IBlogAuthor author) + if (_userService.TryGetUser(post.AuthorId, out IUser? user) && user is IAuthor author) { post.Author = author; } diff --git a/OliverBooth/Services/ContactService.cs b/OliverBooth.Common/Services/ContactService.cs similarity index 87% rename from OliverBooth/Services/ContactService.cs rename to OliverBooth.Common/Services/ContactService.cs index de2b591..1c79d96 100644 --- a/OliverBooth/Services/ContactService.cs +++ b/OliverBooth.Common/Services/ContactService.cs @@ -1,7 +1,8 @@ using Microsoft.EntityFrameworkCore; -using OliverBooth.Data.Web; +using OliverBooth.Common.Data.Web; +using OliverBooth.Common.Data.Web.Contact; -namespace OliverBooth.Services; +namespace OliverBooth.Common.Services; /// internal sealed class ContactService : IContactService diff --git a/OliverBooth/Services/IBlogPostService.cs b/OliverBooth.Common/Services/IBlogPostService.cs similarity index 91% rename from OliverBooth/Services/IBlogPostService.cs rename to OliverBooth.Common/Services/IBlogPostService.cs index 34a9840..df5ed58 100644 --- a/OliverBooth/Services/IBlogPostService.cs +++ b/OliverBooth.Common/Services/IBlogPostService.cs @@ -1,7 +1,7 @@ using System.Diagnostics.CodeAnalysis; -using OliverBooth.Data.Blog; +using OliverBooth.Common.Data.Blog; -namespace OliverBooth.Services; +namespace OliverBooth.Common.Services; /// /// Represents a service for managing blog posts. @@ -27,6 +27,14 @@ public interface IBlogPostService /// The total number of blog posts. int GetBlogPostCount(); + /// + /// Returns a JSON object representing the blog post block data. + /// + /// The blog post whose block data object should be returned. + /// The JSON data of the blog post block data. + /// is . + string GetBlogPostEditorObject(IBlogPost post); + /// /// Returns a collection of blog posts from the specified page, optionally limiting the number of posts /// returned per page. diff --git a/OliverBooth/Services/IContactService.cs b/OliverBooth.Common/Services/IContactService.cs similarity index 75% rename from OliverBooth/Services/IContactService.cs rename to OliverBooth.Common/Services/IContactService.cs index 800a3e7..9574ee3 100644 --- a/OliverBooth/Services/IContactService.cs +++ b/OliverBooth.Common/Services/IContactService.cs @@ -1,6 +1,6 @@ -using OliverBooth.Data.Web; +using OliverBooth.Common.Data.Web.Contact; -namespace OliverBooth.Services; +namespace OliverBooth.Common.Services; /// /// Represents a service for managing contact information. diff --git a/OliverBooth/Services/IProjectService.cs b/OliverBooth.Common/Services/IProjectService.cs similarity index 96% rename from OliverBooth/Services/IProjectService.cs rename to OliverBooth.Common/Services/IProjectService.cs index 16ae771..545b52d 100644 --- a/OliverBooth/Services/IProjectService.cs +++ b/OliverBooth.Common/Services/IProjectService.cs @@ -1,7 +1,7 @@ using System.Diagnostics.CodeAnalysis; -using OliverBooth.Data.Web; +using OliverBooth.Common.Data.Web.Projects; -namespace OliverBooth.Services; +namespace OliverBooth.Common.Services; /// /// Represents a service for interacting with projects. diff --git a/OliverBooth/Services/IReadingListService.cs b/OliverBooth.Common/Services/IReadingListService.cs similarity index 84% rename from OliverBooth/Services/IReadingListService.cs rename to OliverBooth.Common/Services/IReadingListService.cs index 78cc4f2..f487a09 100644 --- a/OliverBooth/Services/IReadingListService.cs +++ b/OliverBooth.Common/Services/IReadingListService.cs @@ -1,6 +1,6 @@ -using OliverBooth.Data.Web; +using OliverBooth.Common.Data.Web.Books; -namespace OliverBooth.Services; +namespace OliverBooth.Common.Services; /// /// Represents a service which fetches books from the reading list. diff --git a/OliverBooth/Services/ISessionService.cs b/OliverBooth.Common/Services/ISessionService.cs similarity index 96% rename from OliverBooth/Services/ISessionService.cs rename to OliverBooth.Common/Services/ISessionService.cs index 4d55c8c..9833857 100644 --- a/OliverBooth/Services/ISessionService.cs +++ b/OliverBooth.Common/Services/ISessionService.cs @@ -1,9 +1,10 @@ using System.Diagnostics.CodeAnalysis; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using OliverBooth.Data.Web; -using ISession = OliverBooth.Data.Web.ISession; +using OliverBooth.Common.Data.Web.Users; +using ISession = OliverBooth.Common.Data.Web.Users.ISession; -namespace OliverBooth.Services; +namespace OliverBooth.Common.Services; public interface ISessionService { diff --git a/OliverBooth/Services/ITemplateService.cs b/OliverBooth.Common/Services/ITemplateService.cs similarity index 95% rename from OliverBooth/Services/ITemplateService.cs rename to OliverBooth.Common/Services/ITemplateService.cs index 5fa9239..194a68c 100644 --- a/OliverBooth/Services/ITemplateService.cs +++ b/OliverBooth.Common/Services/ITemplateService.cs @@ -1,8 +1,8 @@ using System.Diagnostics.CodeAnalysis; -using OliverBooth.Data.Web; -using OliverBooth.Markdown.Template; +using OliverBooth.Common.Data.Web; +using OliverBooth.Common.Markdown.Template; -namespace OliverBooth.Services; +namespace OliverBooth.Common.Services; /// /// Represents a service that renders MediaWiki-style templates. diff --git a/OliverBooth/Services/IUserService.cs b/OliverBooth.Common/Services/IUserService.cs similarity index 82% rename from OliverBooth/Services/IUserService.cs rename to OliverBooth.Common/Services/IUserService.cs index 336b220..8f15e74 100644 --- a/OliverBooth/Services/IUserService.cs +++ b/OliverBooth.Common/Services/IUserService.cs @@ -1,10 +1,10 @@ using System.Diagnostics.CodeAnalysis; -using OliverBooth.Data.Web; +using OliverBooth.Common.Data.Web.Users; -namespace OliverBooth.Services; +namespace OliverBooth.Common.Services; /// -/// Represents a service for managing users. +/// Represents a service which manages users. /// public interface IUserService { @@ -34,15 +34,16 @@ public interface IUserService void DeleteToken(string token); /// - /// Attempts to find a user with the specified ID. + /// Attempts to find a user by their unique ID. /// - /// The ID of the user to find. + /// The ID of the user to return. /// - /// When this method returns, contains the user with the specified ID, if the user is found; otherwise, - /// . + /// When this method returns, contains the user whose ID is equal to the specified , if + /// such a user exists; otherwise, . /// /// - /// if a user with the specified ID is found; otherwise, . + /// if a user was found with the specified ; otherwise, + /// . /// bool TryGetUser(Guid id, [NotNullWhen(true)] out IUser? user); diff --git a/OliverBooth/Services/ProjectService.cs b/OliverBooth.Common/Services/ProjectService.cs similarity index 95% rename from OliverBooth/Services/ProjectService.cs rename to OliverBooth.Common/Services/ProjectService.cs index 6f75ca5..72eb42f 100644 --- a/OliverBooth/Services/ProjectService.cs +++ b/OliverBooth.Common/Services/ProjectService.cs @@ -2,9 +2,10 @@ using System.Diagnostics.CodeAnalysis; using Humanizer; using Markdig; using Microsoft.EntityFrameworkCore; -using OliverBooth.Data.Web; +using OliverBooth.Common.Data.Web; +using OliverBooth.Common.Data.Web.Projects; -namespace OliverBooth.Services; +namespace OliverBooth.Common.Services; /// /// Represents a service for interacting with projects. diff --git a/OliverBooth/Services/ReadingListService.cs b/OliverBooth.Common/Services/ReadingListService.cs similarity index 90% rename from OliverBooth/Services/ReadingListService.cs rename to OliverBooth.Common/Services/ReadingListService.cs index 54da5fb..3855884 100644 --- a/OliverBooth/Services/ReadingListService.cs +++ b/OliverBooth.Common/Services/ReadingListService.cs @@ -1,7 +1,8 @@ using Microsoft.EntityFrameworkCore; -using OliverBooth.Data.Web; +using OliverBooth.Common.Data.Web; +using OliverBooth.Common.Data.Web.Books; -namespace OliverBooth.Services; +namespace OliverBooth.Common.Services; internal sealed class ReadingListService : IReadingListService { diff --git a/OliverBooth/Services/SessionService.cs b/OliverBooth.Common/Services/SessionService.cs similarity index 96% rename from OliverBooth/Services/SessionService.cs rename to OliverBooth.Common/Services/SessionService.cs index 14908ed..3796d31 100644 --- a/OliverBooth/Services/SessionService.cs +++ b/OliverBooth.Common/Services/SessionService.cs @@ -1,13 +1,16 @@ using System.Diagnostics.CodeAnalysis; using System.Net; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; -using OliverBooth.Data.Blog; -using OliverBooth.Data.Web; -using ISession = OliverBooth.Data.Web.ISession; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using OliverBooth.Common.Data.Web; +using OliverBooth.Common.Data.Web.Users; +using ISession = OliverBooth.Common.Data.Web.Users.ISession; -namespace OliverBooth.Services; +namespace OliverBooth.Common.Services; internal sealed class SessionService : BackgroundService, ISessionService { @@ -20,11 +23,9 @@ internal sealed class SessionService : BackgroundService, ISessionService /// /// The logger. /// The user service. - /// The factory. /// The factory. public SessionService(ILogger logger, IUserService userService, - IDbContextFactory blogContextFactory, IDbContextFactory webContextFactory) { _logger = logger; diff --git a/OliverBooth/Services/TemplateService.cs b/OliverBooth.Common/Services/TemplateService.cs similarity index 92% rename from OliverBooth/Services/TemplateService.cs rename to OliverBooth.Common/Services/TemplateService.cs index 8eabc70..8c8ea68 100644 --- a/OliverBooth/Services/TemplateService.cs +++ b/OliverBooth.Common/Services/TemplateService.cs @@ -1,13 +1,13 @@ using System.Buffers.Binary; using System.Diagnostics.CodeAnalysis; using Microsoft.EntityFrameworkCore; -using OliverBooth.Data.Web; -using OliverBooth.Formatting; -using OliverBooth.Markdown.Template; +using OliverBooth.Common.Data.Web; +using OliverBooth.Common.Formatting; +using OliverBooth.Common.Markdown.Template; using SmartFormat; using SmartFormat.Extensions; -namespace OliverBooth.Services; +namespace OliverBooth.Common.Services; /// /// Represents a service that renders MediaWiki-style templates. @@ -22,7 +22,7 @@ internal sealed class TemplateService : ITemplateService /// Initializes a new instance of the class. /// /// The . - /// The factory. + /// The factory. public TemplateService(IServiceProvider serviceProvider, IDbContextFactory webContextFactory) { diff --git a/OliverBooth/Services/UserService.cs b/OliverBooth.Common/Services/UserService.cs similarity index 92% rename from OliverBooth/Services/UserService.cs rename to OliverBooth.Common/Services/UserService.cs index dc7a5ef..d4b103d 100644 --- a/OliverBooth/Services/UserService.cs +++ b/OliverBooth.Common/Services/UserService.cs @@ -2,15 +2,14 @@ using System.Collections.Concurrent; using System.Diagnostics.CodeAnalysis; using System.Security.Cryptography; using Microsoft.EntityFrameworkCore; -using OliverBooth.Data.Web; +using Microsoft.Extensions.Hosting; +using OliverBooth.Common.Data.Web; +using OliverBooth.Common.Data.Web.Users; using BC = BCrypt.Net.BCrypt; using Timer = System.Timers.Timer; -namespace OliverBooth.Services; +namespace OliverBooth.Common.Services; -/// -/// Represents an implementation of . -/// internal sealed class UserService : BackgroundService, IUserService { private static readonly RandomNumberGenerator RandomNumberGenerator = RandomNumberGenerator.Create(); @@ -117,19 +116,8 @@ internal sealed class UserService : BackgroundService, IUserService /// public bool TryGetUser(Guid id, [NotNullWhen(true)] out IUser? user) { - if (_userCache.TryGetValue(id, out user)) - { - return true; - } - using WebContext context = _dbContextFactory.CreateDbContext(); - user = context.Users.Find(id); - - if (user is not null) - { - _userCache.TryAdd(id, user); - } - + user = context.Users.FirstOrDefault(u => u.Id == id); return user is not null; } @@ -138,7 +126,12 @@ internal sealed class UserService : BackgroundService, IUserService { using WebContext context = _dbContextFactory.CreateDbContext(); user = context.Users.FirstOrDefault(u => u.EmailAddress == email); - return user is not null && BC.Verify(password, ((User)user).Password); + if (user is not null && !BC.Verify(password, ((User)user).Password)) + { + user = null; + } + + return user is not null; } /// diff --git a/OliverBooth.sln b/OliverBooth.sln index b852780..fa82af3 100644 --- a/OliverBooth.sln +++ b/OliverBooth.sln @@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Gulpfile.mjs = Gulpfile.mjs EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OliverBooth.Common", "OliverBooth.Common\OliverBooth.Common.csproj", "{77DC9941-E648-442F-935A-C66FC401ECBC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -23,6 +25,10 @@ Global {A58A6FA3-480C-400B-822A-3786741BF39C}.Debug|Any CPU.Build.0 = Debug|Any CPU {A58A6FA3-480C-400B-822A-3786741BF39C}.Release|Any CPU.ActiveCfg = Release|Any CPU {A58A6FA3-480C-400B-822A-3786741BF39C}.Release|Any CPU.Build.0 = Release|Any CPU + {77DC9941-E648-442F-935A-C66FC401ECBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {77DC9941-E648-442F-935A-C66FC401ECBC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {77DC9941-E648-442F-935A-C66FC401ECBC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {77DC9941-E648-442F-935A-C66FC401ECBC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution EndGlobalSection diff --git a/OliverBooth/Controllers/Api/v1/AuthenticationController.cs b/OliverBooth/Controllers/Api/v1/AuthenticationController.cs index 3b4b7da..8945ae7 100644 --- a/OliverBooth/Controllers/Api/v1/AuthenticationController.cs +++ b/OliverBooth/Controllers/Api/v1/AuthenticationController.cs @@ -1,9 +1,9 @@ using System.Diagnostics; using Asp.Versioning; using Microsoft.AspNetCore.Mvc; -using OliverBooth.Data.Web; -using OliverBooth.Services; -using ISession = OliverBooth.Data.Web.ISession; +using OliverBooth.Common.Data.Web.Users; +using OliverBooth.Common.Services; +using ISession = OliverBooth.Common.Data.Web.Users.ISession; namespace OliverBooth.Controllers.Api.v1; diff --git a/OliverBooth/Controllers/Api/v1/BlogApiController.cs b/OliverBooth/Controllers/Api/v1/BlogApiController.cs index 3b88341..5e55a66 100644 --- a/OliverBooth/Controllers/Api/v1/BlogApiController.cs +++ b/OliverBooth/Controllers/Api/v1/BlogApiController.cs @@ -1,8 +1,9 @@ using Asp.Versioning; using Humanizer; using Microsoft.AspNetCore.Mvc; -using OliverBooth.Data.Blog; -using OliverBooth.Data.Web; +using OliverBooth.Common.Data.Blog; +using OliverBooth.Common.Data.Web.Users; +using OliverBooth.Common.Services; using OliverBooth.Services; namespace OliverBooth.Controllers.Api.v1; diff --git a/OliverBooth/Controllers/Blog/RssController.cs b/OliverBooth/Controllers/Blog/RssController.cs index 83b1a08..55d520c 100644 --- a/OliverBooth/Controllers/Blog/RssController.cs +++ b/OliverBooth/Controllers/Blog/RssController.cs @@ -1,6 +1,7 @@ using System.Xml.Serialization; using Microsoft.AspNetCore.Mvc; -using OliverBooth.Data.Blog; +using OliverBooth.Common.Data.Blog; +using OliverBooth.Common.Services; using OliverBooth.Data.Blog.Rss; using OliverBooth.Services; diff --git a/OliverBooth/Controllers/FormattedBlacklist.cs b/OliverBooth/Controllers/FormattedBlacklist.cs index bce6143..cfc9506 100644 --- a/OliverBooth/Controllers/FormattedBlacklist.cs +++ b/OliverBooth/Controllers/FormattedBlacklist.cs @@ -1,7 +1,7 @@ using System.Text; using Microsoft.AspNetCore.Mvc; -using OliverBooth.Data.Web; -using OliverBooth.Services; +using OliverBooth.Common.Data.Web.Contact; +using OliverBooth.Common.Services; namespace OliverBooth.Controllers; diff --git a/OliverBooth/Markdown/Timestamp/TimestampInlineParser.cs b/OliverBooth/Markdown/Timestamp/TimestampInlineParser.cs index de402ce..a88fe8e 100644 --- a/OliverBooth/Markdown/Timestamp/TimestampInlineParser.cs +++ b/OliverBooth/Markdown/Timestamp/TimestampInlineParser.cs @@ -13,7 +13,7 @@ public sealed class TimestampInlineParser : InlineParser /// public TimestampInlineParser() { - OpeningCharacters = new[] { '<' }; + OpeningCharacters = ['<']; } /// diff --git a/OliverBooth/OliverBooth.csproj b/OliverBooth/OliverBooth.csproj index 03dea62..f0c8495 100644 --- a/OliverBooth/OliverBooth.csproj +++ b/OliverBooth/OliverBooth.csproj @@ -27,32 +27,17 @@ - - - - - - - - - - - - - - - - - - - + + + + diff --git a/OliverBooth/Pages/Admin/BlogPosts.cshtml b/OliverBooth/Pages/Admin/BlogPosts.cshtml index 0dd1a2d..0eeea07 100644 --- a/OliverBooth/Pages/Admin/BlogPosts.cshtml +++ b/OliverBooth/Pages/Admin/BlogPosts.cshtml @@ -1,8 +1,10 @@ @page "/admin/blog-posts" @using System.Diagnostics -@using OliverBooth.Data -@using OliverBooth.Data.Blog -@using OliverBooth.Data.Web +@using Microsoft.AspNetCore.Mvc.TagHelpers +@using OliverBooth.Common.Data +@using OliverBooth.Common.Data.Blog +@using OliverBooth.Common.Data.Web.Users +@using OliverBooth.Common.Services @using OliverBooth.Services @model OliverBooth.Pages.Admin.BlogPosts @inject IBlogPostService BlogPostService @@ -52,7 +54,7 @@ Options - + @foreach (IBlogPost post in BlogPostService.GetAllBlogPosts(visibility: (BlogPostVisibility)(-1))) { diff --git a/OliverBooth/Pages/Admin/BlogPosts.cshtml.cs b/OliverBooth/Pages/Admin/BlogPosts.cshtml.cs index ff2e5de..c053429 100644 --- a/OliverBooth/Pages/Admin/BlogPosts.cshtml.cs +++ b/OliverBooth/Pages/Admin/BlogPosts.cshtml.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using OliverBooth.Data.Web; -using OliverBooth.Services; +using OliverBooth.Common.Data.Web.Users; +using OliverBooth.Common.Services; namespace OliverBooth.Pages.Admin; diff --git a/OliverBooth/Pages/Admin/EditBlogPost.cshtml b/OliverBooth/Pages/Admin/EditBlogPost.cshtml index 6833c36..66a858f 100644 --- a/OliverBooth/Pages/Admin/EditBlogPost.cshtml +++ b/OliverBooth/Pages/Admin/EditBlogPost.cshtml @@ -1,6 +1,6 @@ @page "/admin/blog-posts/edit/{id}" @using Markdig -@using OliverBooth.Data.Blog +@using OliverBooth.Common.Data.Blog @model OliverBooth.Pages.Admin.EditBlogPost @inject MarkdownPipeline MarkdownPipeline diff --git a/OliverBooth/Pages/Admin/EditBlogPost.cshtml.cs b/OliverBooth/Pages/Admin/EditBlogPost.cshtml.cs index e2e659a..6906ba8 100644 --- a/OliverBooth/Pages/Admin/EditBlogPost.cshtml.cs +++ b/OliverBooth/Pages/Admin/EditBlogPost.cshtml.cs @@ -1,7 +1,8 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using OliverBooth.Data.Blog; -using OliverBooth.Data.Web; +using OliverBooth.Common.Data.Blog; +using OliverBooth.Common.Data.Web.Users; +using OliverBooth.Common.Services; using OliverBooth.Services; namespace OliverBooth.Pages.Admin; diff --git a/OliverBooth/Pages/Admin/Index.cshtml.cs b/OliverBooth/Pages/Admin/Index.cshtml.cs index d13264d..3bd820e 100644 --- a/OliverBooth/Pages/Admin/Index.cshtml.cs +++ b/OliverBooth/Pages/Admin/Index.cshtml.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using OliverBooth.Data.Web; -using OliverBooth.Services; +using OliverBooth.Common.Data.Web.Users; +using OliverBooth.Common.Services; namespace OliverBooth.Pages.Admin; diff --git a/OliverBooth/Pages/Admin/Login.cshtml.cs b/OliverBooth/Pages/Admin/Login.cshtml.cs index 6033f27..3dba549 100644 --- a/OliverBooth/Pages/Admin/Login.cshtml.cs +++ b/OliverBooth/Pages/Admin/Login.cshtml.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using OliverBooth.Services; +using OliverBooth.Common.Services; namespace OliverBooth.Pages.Admin; diff --git a/OliverBooth/Pages/Admin/MultiFactorStep.cshtml b/OliverBooth/Pages/Admin/MultiFactorStep.cshtml index e41a58b..8fcdc2b 100644 --- a/OliverBooth/Pages/Admin/MultiFactorStep.cshtml +++ b/OliverBooth/Pages/Admin/MultiFactorStep.cshtml @@ -1,5 +1,5 @@ @page "/admin/login/mfa" -@using OliverBooth.Data.Web +@using OliverBooth.Common.Data.Web.Users @model OliverBooth.Pages.Admin.MultiFactorStep @{ diff --git a/OliverBooth/Pages/Admin/MultiFactorStep.cshtml.cs b/OliverBooth/Pages/Admin/MultiFactorStep.cshtml.cs index 8ae4725..0f9a300 100644 --- a/OliverBooth/Pages/Admin/MultiFactorStep.cshtml.cs +++ b/OliverBooth/Pages/Admin/MultiFactorStep.cshtml.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using OliverBooth.Services; +using OliverBooth.Common.Services; namespace OliverBooth.Pages.Admin; diff --git a/OliverBooth/Pages/Blog/Article.cshtml b/OliverBooth/Pages/Blog/Article.cshtml index 9bb648c..6b46be8 100644 --- a/OliverBooth/Pages/Blog/Article.cshtml +++ b/OliverBooth/Pages/Blog/Article.cshtml @@ -1,6 +1,7 @@ @page "/blog/{year:int}/{month:int}/{day:int}/{slug}" @using Humanizer -@using OliverBooth.Data.Blog +@using OliverBooth.Common.Data.Blog +@using OliverBooth.Common.Services @using OliverBooth.Services @inject IBlogPostService BlogPostService @model Article @@ -29,7 +30,7 @@ @{ ViewData["Post"] = post; ViewData["Title"] = post.Title; - IBlogAuthor author = post.Author; + IAuthor author = post.Author; DateTimeOffset published = post.Published; } diff --git a/OliverBooth/Pages/Blog/Article.cshtml.cs b/OliverBooth/Pages/Blog/Article.cshtml.cs index 17a9337..bdf873b 100644 --- a/OliverBooth/Pages/Blog/Article.cshtml.cs +++ b/OliverBooth/Pages/Blog/Article.cshtml.cs @@ -1,7 +1,8 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Primitives; -using OliverBooth.Data.Blog; +using OliverBooth.Common.Data.Blog; +using OliverBooth.Common.Services; using OliverBooth.Services; using BC = BCrypt.Net.BCrypt; diff --git a/OliverBooth/Pages/Blog/Index.cshtml.cs b/OliverBooth/Pages/Blog/Index.cshtml.cs index 97104b6..3e93788 100644 --- a/OliverBooth/Pages/Blog/Index.cshtml.cs +++ b/OliverBooth/Pages/Blog/Index.cshtml.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using OliverBooth.Data.Blog; +using OliverBooth.Common.Data.Blog; +using OliverBooth.Common.Services; using OliverBooth.Services; namespace OliverBooth.Pages.Blog; diff --git a/OliverBooth/Pages/Blog/RawArticle.cshtml.cs b/OliverBooth/Pages/Blog/RawArticle.cshtml.cs index e55b687..4715971 100644 --- a/OliverBooth/Pages/Blog/RawArticle.cshtml.cs +++ b/OliverBooth/Pages/Blog/RawArticle.cshtml.cs @@ -1,7 +1,8 @@ using Cysharp.Text; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using OliverBooth.Data.Blog; +using OliverBooth.Common.Data.Blog; +using OliverBooth.Common.Services; using OliverBooth.Services; namespace OliverBooth.Pages.Blog; diff --git a/OliverBooth/Pages/Books.cshtml b/OliverBooth/Pages/Books.cshtml index dd83d7e..4ae1f8e 100644 --- a/OliverBooth/Pages/Books.cshtml +++ b/OliverBooth/Pages/Books.cshtml @@ -1,5 +1,5 @@ @page -@using OliverBooth.Data.Web +@using OliverBooth.Common.Data.Web.Books @model OliverBooth.Pages.Books @{ ViewData["Title"] = "Reading List"; diff --git a/OliverBooth/Pages/Books.cshtml.cs b/OliverBooth/Pages/Books.cshtml.cs index 6cbc5af..0b29c33 100644 --- a/OliverBooth/Pages/Books.cshtml.cs +++ b/OliverBooth/Pages/Books.cshtml.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc.RazorPages; -using OliverBooth.Data.Web; -using OliverBooth.Services; +using OliverBooth.Common.Data.Web.Books; +using OliverBooth.Common.Services; namespace OliverBooth.Pages; diff --git a/OliverBooth/Pages/Contact/Blacklist.cshtml b/OliverBooth/Pages/Contact/Blacklist.cshtml index a0101ac..e312feb 100644 --- a/OliverBooth/Pages/Contact/Blacklist.cshtml +++ b/OliverBooth/Pages/Contact/Blacklist.cshtml @@ -1,6 +1,6 @@ @page -@using OliverBooth.Data.Web -@using OliverBooth.Services +@using OliverBooth.Common.Data.Web.Contact +@using OliverBooth.Common.Services @inject IContactService ContactService @{ ViewData["Title"] = "Blacklist"; diff --git a/OliverBooth/Pages/Projects/Index.cshtml b/OliverBooth/Pages/Projects/Index.cshtml index 90468e5..5c9442a 100644 --- a/OliverBooth/Pages/Projects/Index.cshtml +++ b/OliverBooth/Pages/Projects/Index.cshtml @@ -1,6 +1,6 @@ @page -@using OliverBooth.Data.Web -@using OliverBooth.Services +@using OliverBooth.Common.Data.Web.Projects +@using OliverBooth.Common.Services @inject IProjectService ProjectService @{ ViewData["Title"] = "Projects"; diff --git a/OliverBooth/Pages/Projects/Project.cshtml b/OliverBooth/Pages/Projects/Project.cshtml index b9c9933..b44f8cf 100644 --- a/OliverBooth/Pages/Projects/Project.cshtml +++ b/OliverBooth/Pages/Projects/Project.cshtml @@ -1,7 +1,7 @@ @page "/project/{slug}" @using Markdig -@using OliverBooth.Data.Web -@using OliverBooth.Services +@using OliverBooth.Common.Data.Web.Projects +@using OliverBooth.Common.Services @model Project @inject IProjectService ProjectService @inject MarkdownPipeline MarkdownPipeline diff --git a/OliverBooth/Pages/Projects/Project.cshtml.cs b/OliverBooth/Pages/Projects/Project.cshtml.cs index 87782ec..35bc875 100644 --- a/OliverBooth/Pages/Projects/Project.cshtml.cs +++ b/OliverBooth/Pages/Projects/Project.cshtml.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc.RazorPages; -using OliverBooth.Data.Web; -using OliverBooth.Services; +using OliverBooth.Common.Data.Web.Projects; +using OliverBooth.Common.Services; namespace OliverBooth.Pages.Projects; diff --git a/OliverBooth/Pages/Shared/_AdminLayout.cshtml b/OliverBooth/Pages/Shared/_AdminLayout.cshtml index 42bf356..39e610b 100644 --- a/OliverBooth/Pages/Shared/_AdminLayout.cshtml +++ b/OliverBooth/Pages/Shared/_AdminLayout.cshtml @@ -1,6 +1,8 @@ @using OliverBooth.Data.Blog -@using OliverBooth.Data.Web @using OliverBooth.Services +@using OliverBooth.Common.Data.Web.Users +@using OliverBooth.Common.Services +@using OliverBooth.Common.Data.Blog @inject IBlogPostService BlogPostService @inject IUserService UserService @inject ISessionService SessionService diff --git a/OliverBooth/Pages/Shared/_Layout.cshtml b/OliverBooth/Pages/Shared/_Layout.cshtml index 966dabc..abc185c 100644 --- a/OliverBooth/Pages/Shared/_Layout.cshtml +++ b/OliverBooth/Pages/Shared/_Layout.cshtml @@ -1,6 +1,8 @@ @using OliverBooth.Data.Blog -@using OliverBooth.Data.Web @using OliverBooth.Services +@using OliverBooth.Common.Data.Web.Users +@using OliverBooth.Common.Services +@using OliverBooth.Common.Data.Blog @inject IBlogPostService BlogPostService @inject IUserService UserService @inject ISessionService SessionService diff --git a/OliverBooth/Program.cs b/OliverBooth/Program.cs index 50f3e3a..7050f46 100644 --- a/OliverBooth/Program.cs +++ b/OliverBooth/Program.cs @@ -4,15 +4,15 @@ using AspNetCore.ReCaptcha; using FluentFTP; using FluentFTP.Logging; using Markdig; +using OliverBooth.Common.Extensions; +using OliverBooth.Common.Markdown.Template; +using OliverBooth.Common.Services; using OliverBooth.Data.Blog; -using OliverBooth.Data.Web; using OliverBooth.Extensions; -using OliverBooth.Markdown.Template; using OliverBooth.Markdown.Timestamp; using OliverBooth.Services; using Serilog; using Serilog.Extensions.Logging; -using X10D.Hosting.DependencyInjection; Log.Logger = new LoggerConfiguration() .WriteTo.Console() @@ -44,8 +44,7 @@ builder.Services.AddApiVersioning(options => options.ApiVersionReader = new UrlSegmentApiVersionReader(); }); -builder.Services.AddDbContextFactory(); -builder.Services.AddDbContextFactory(); +builder.Services.AddCommonServices(); builder.Services.AddHttpClient(); builder.Services.AddTransient(provider => { @@ -66,14 +65,7 @@ builder.Services.AddTransient(provider => }); builder.Services.AddSingleton(); -builder.Services.AddSingleton(); -builder.Services.AddSingleton(); -builder.Services.AddSingleton(); -builder.Services.AddSingleton(); builder.Services.AddSingleton(); -builder.Services.AddSingleton(); -builder.Services.AddHostedSingleton(); -builder.Services.AddHostedSingleton(); builder.Services.AddRazorPages().AddRazorRuntimeCompilation(); builder.Services.AddControllersWithViews(); builder.Services.AddRazorComponents().AddInteractiveServerComponents();