diff --git a/OliverBooth/Controllers/Blog/BlogApiController.cs b/OliverBooth/Controllers/Blog/BlogApiController.cs
index 21eb070..c5ab926 100644
--- a/OliverBooth/Controllers/Blog/BlogApiController.cs
+++ b/OliverBooth/Controllers/Blog/BlogApiController.cs
@@ -1,6 +1,7 @@
using Humanizer;
using Microsoft.AspNetCore.Mvc;
using OliverBooth.Data.Blog;
+using OliverBooth.Data.Web;
using OliverBooth.Services;
namespace OliverBooth.Controllers.Blog;
@@ -14,14 +15,14 @@ namespace OliverBooth.Controllers.Blog;
public sealed class BlogApiController : ControllerBase
{
private readonly IBlogPostService _blogPostService;
- private readonly IBlogUserService _userService;
+ private readonly IUserService _userService;
///
/// Initializes a new instance of the class.
///
/// The .
- /// The .
- public BlogApiController(IBlogPostService blogPostService, IBlogUserService userService)
+ /// The .
+ public BlogApiController(IBlogPostService blogPostService, IUserService userService)
{
_blogPostService = blogPostService;
_userService = userService;
diff --git a/OliverBooth/Data/Blog/BlogContext.cs b/OliverBooth/Data/Blog/BlogContext.cs
index 3f37b46..2d4b937 100644
--- a/OliverBooth/Data/Blog/BlogContext.cs
+++ b/OliverBooth/Data/Blog/BlogContext.cs
@@ -31,12 +31,6 @@ internal sealed class BlogContext : DbContext
/// The collection of sessions.
public DbSet Sessions { get; private set; } = null!;
- ///
- /// Gets the collection of users in the database.
- ///
- /// The collection of users.
- public DbSet Users { get; private set; } = null!;
-
///
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
@@ -50,6 +44,5 @@ internal sealed class BlogContext : DbContext
{
modelBuilder.ApplyConfiguration(new BlogPostConfiguration());
modelBuilder.ApplyConfiguration(new SessionConfiguration());
- modelBuilder.ApplyConfiguration(new UserConfiguration());
}
}
diff --git a/OliverBooth/Data/Blog/Configuration/UserConfiguration.cs b/OliverBooth/Data/Blog/Configuration/UserConfiguration.cs
index 7c16adf..47abe5c 100644
--- a/OliverBooth/Data/Blog/Configuration/UserConfiguration.cs
+++ b/OliverBooth/Data/Blog/Configuration/UserConfiguration.cs
@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
+using OliverBooth.Data.Web;
namespace OliverBooth.Data.Blog.Configuration;
diff --git a/OliverBooth/Data/Blog/IUser.cs b/OliverBooth/Data/Web/IUser.cs
similarity index 98%
rename from OliverBooth/Data/Blog/IUser.cs
rename to OliverBooth/Data/Web/IUser.cs
index 6fdedd6..e021546 100644
--- a/OliverBooth/Data/Blog/IUser.cs
+++ b/OliverBooth/Data/Web/IUser.cs
@@ -1,4 +1,4 @@
-namespace OliverBooth.Data.Blog;
+namespace OliverBooth.Data.Web;
///
/// Represents a user which can log in to the blog.
diff --git a/OliverBooth/Data/Blog/User.cs b/OliverBooth/Data/Web/User.cs
similarity index 97%
rename from OliverBooth/Data/Blog/User.cs
rename to OliverBooth/Data/Web/User.cs
index 987e2e7..867935d 100644
--- a/OliverBooth/Data/Blog/User.cs
+++ b/OliverBooth/Data/Web/User.cs
@@ -2,8 +2,9 @@ using System.ComponentModel.DataAnnotations.Schema;
using System.Security.Cryptography;
using System.Text;
using Cysharp.Text;
+using OliverBooth.Data.Blog;
-namespace OliverBooth.Data.Blog;
+namespace OliverBooth.Data.Web;
///
/// Represents a user.
diff --git a/OliverBooth/Data/Web/WebContext.cs b/OliverBooth/Data/Web/WebContext.cs
index d5b74e4..4d54ea3 100644
--- a/OliverBooth/Data/Web/WebContext.cs
+++ b/OliverBooth/Data/Web/WebContext.cs
@@ -55,6 +55,12 @@ internal sealed class WebContext : DbContext
/// The collection of templates.
public DbSet Templates { get; private set; } = null!;
+ ///
+ /// Gets the collection of users in the database.
+ ///
+ /// The collection of users.
+ public DbSet Users { get; private set; } = null!;
+
///
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
@@ -72,5 +78,6 @@ internal sealed class WebContext : DbContext
modelBuilder.ApplyConfiguration(new ProjectConfiguration());
modelBuilder.ApplyConfiguration(new TemplateConfiguration());
modelBuilder.ApplyConfiguration(new SiteConfigurationConfiguration());
+ modelBuilder.ApplyConfiguration(new UserConfiguration());
}
}
diff --git a/OliverBooth/Pages/Blog/Admin/Index.cshtml.cs b/OliverBooth/Pages/Blog/Admin/Index.cshtml.cs
index 144fd15..900d698 100644
--- a/OliverBooth/Pages/Blog/Admin/Index.cshtml.cs
+++ b/OliverBooth/Pages/Blog/Admin/Index.cshtml.cs
@@ -1,7 +1,7 @@
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
-using OliverBooth.Data.Blog;
+using OliverBooth.Data.Web;
using OliverBooth.Services;
using ISession = OliverBooth.Data.Blog.ISession;
diff --git a/OliverBooth/Program.cs b/OliverBooth/Program.cs
index 99c7701..e772130 100644
--- a/OliverBooth/Program.cs
+++ b/OliverBooth/Program.cs
@@ -36,8 +36,8 @@ builder.Services.AddHttpClient();
builder.Services.AddSingleton();
builder.Services.AddSingleton();
builder.Services.AddSingleton();
-builder.Services.AddSingleton();
builder.Services.AddSingleton();
+builder.Services.AddSingleton();
builder.Services.AddSingleton();
builder.Services.AddSingleton();
builder.Services.AddSingleton();
diff --git a/OliverBooth/Services/BlogPostService.cs b/OliverBooth/Services/BlogPostService.cs
index aa2a4a1..9d2be3e 100644
--- a/OliverBooth/Services/BlogPostService.cs
+++ b/OliverBooth/Services/BlogPostService.cs
@@ -3,6 +3,7 @@ using Humanizer;
using Markdig;
using Microsoft.EntityFrameworkCore;
using OliverBooth.Data.Blog;
+using OliverBooth.Data.Web;
namespace OliverBooth.Services;
@@ -12,7 +13,7 @@ namespace OliverBooth.Services;
internal sealed class BlogPostService : IBlogPostService
{
private readonly IDbContextFactory _dbContextFactory;
- private readonly IBlogUserService _blogUserService;
+ private readonly IUserService _userService;
private readonly MarkdownPipeline _markdownPipeline;
///
@@ -21,14 +22,14 @@ internal sealed class BlogPostService : IBlogPostService
///
/// The used to create a .
///
- /// The .
+ /// The .
/// The .
public BlogPostService(IDbContextFactory dbContextFactory,
- IBlogUserService blogUserService,
+ IUserService userService,
MarkdownPipeline markdownPipeline)
{
_dbContextFactory = dbContextFactory;
- _blogUserService = blogUserService;
+ _userService = userService;
_markdownPipeline = markdownPipeline;
}
@@ -163,7 +164,7 @@ internal sealed class BlogPostService : IBlogPostService
return post;
}
- if (_blogUserService.TryGetUser(post.AuthorId, out IUser? user) && user is IBlogAuthor author)
+ if (_userService.TryGetUser(post.AuthorId, out IUser? user) && user is IBlogAuthor author)
{
post.Author = author;
}
diff --git a/OliverBooth/Services/ISessionService.cs b/OliverBooth/Services/ISessionService.cs
index 0fb0ff6..e087bcb 100644
--- a/OliverBooth/Services/ISessionService.cs
+++ b/OliverBooth/Services/ISessionService.cs
@@ -1,5 +1,5 @@
using System.Diagnostics.CodeAnalysis;
-using OliverBooth.Data.Blog;
+using OliverBooth.Data.Web;
using ISession = OliverBooth.Data.Blog.ISession;
namespace OliverBooth.Services;
diff --git a/OliverBooth/Services/IBlogUserService.cs b/OliverBooth/Services/IUserService.cs
similarity index 95%
rename from OliverBooth/Services/IBlogUserService.cs
rename to OliverBooth/Services/IUserService.cs
index 577509c..d52b65e 100644
--- a/OliverBooth/Services/IBlogUserService.cs
+++ b/OliverBooth/Services/IUserService.cs
@@ -1,12 +1,12 @@
using System.Diagnostics.CodeAnalysis;
-using OliverBooth.Data.Blog;
+using OliverBooth.Data.Web;
namespace OliverBooth.Services;
///
/// Represents a service for managing users.
///
-public interface IBlogUserService
+public interface IUserService
{
///
/// Attempts to find a user with the specified ID.
diff --git a/OliverBooth/Services/SessionService.cs b/OliverBooth/Services/SessionService.cs
index 1fdaa8a..84340af 100644
--- a/OliverBooth/Services/SessionService.cs
+++ b/OliverBooth/Services/SessionService.cs
@@ -11,7 +11,7 @@ namespace OliverBooth.Services;
internal sealed class SessionService : ISessionService
{
private readonly ILogger _logger;
- private readonly IBlogUserService _userService;
+ private readonly IUserService _userService;
private readonly IDbContextFactory _blogContextFactory;
///
@@ -22,7 +22,7 @@ internal sealed class SessionService : ISessionService
/// The factory.
/// The factory.
public SessionService(ILogger logger,
- IBlogUserService userService,
+ IUserService userService,
IDbContextFactory blogContextFactory,
IDbContextFactory webContextFactory)
{
diff --git a/OliverBooth/Services/BlogUserService.cs b/OliverBooth/Services/UserService.cs
similarity index 65%
rename from OliverBooth/Services/BlogUserService.cs
rename to OliverBooth/Services/UserService.cs
index 6db6c71..bcb0f3e 100644
--- a/OliverBooth/Services/BlogUserService.cs
+++ b/OliverBooth/Services/UserService.cs
@@ -1,26 +1,26 @@
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore;
-using OliverBooth.Data.Blog;
+using OliverBooth.Data.Web;
using BC = BCrypt.Net.BCrypt;
namespace OliverBooth.Services;
///
-/// Represents an implementation of .
+/// Represents an implementation of .
///
-internal sealed class BlogUserService : IBlogUserService
+internal sealed class UserService : IUserService
{
- private readonly IDbContextFactory _dbContextFactory;
+ private readonly IDbContextFactory _dbContextFactory;
private readonly ConcurrentDictionary _userCache = new();
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
- /// The used to create a .
+ /// The used to create a .
///
- public BlogUserService(IDbContextFactory dbContextFactory)
+ public UserService(IDbContextFactory dbContextFactory)
{
_dbContextFactory = dbContextFactory;
}
@@ -30,7 +30,7 @@ internal sealed class BlogUserService : IBlogUserService
{
if (_userCache.TryGetValue(id, out user)) return true;
- using BlogContext context = _dbContextFactory.CreateDbContext();
+ using WebContext context = _dbContextFactory.CreateDbContext();
user = context.Users.Find(id);
if (user is not null) _userCache.TryAdd(id, user);
@@ -40,7 +40,7 @@ internal sealed class BlogUserService : IBlogUserService
///
public bool VerifyLogin(string email, string password, [NotNullWhen(true)] out IUser? user)
{
- using BlogContext context = _dbContextFactory.CreateDbContext();
+ using WebContext context = _dbContextFactory.CreateDbContext();
user = context.Users.FirstOrDefault(u => u.EmailAddress == email);
return user is not null && BC.Verify(password, ((User)user).Password);
}