mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Adds user settings management
Adds the UserSettings aggregate with pagination and alpha picker preferences, keyed to a user with a dedicated UserId foreign key. Adds GET and PUT /users/me/settings API endpoints, a localized Tools > Settings page with save confirmation, the EF migration for the UserSettings table, and unit, integration and security tests.
This commit is contained in:
1 parent
c3f8786fe4
commit
2354e21d42
65 files changed
+4711
-21
No files matched your search
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// User settings error types.
|
||||
/// </summary>
|
||||
public static partial class Errors
|
||||
{
|
||||
public static class UserSettings
|
||||
{
|
||||
public static Error UserSettingsAlreadyExists => Error.Conflict(description: nameof(UserSettingsAlreadyExists));
|
||||
public static Error UserSettingsNotFound => Error.NotFound(description: nameof(UserSettingsNotFound));
|
||||
public static Error ItemsPerPageMustBeGreaterThanZero => Error.Validation(description: nameof(ItemsPerPageMustBeGreaterThanZero));
|
||||
}
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Aggregate root for the settings of a user.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Id: {Id}; UserId: {UserId}")]
|
||||
public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
{
|
||||
private const bool DEFAULT_IS_PAGINATION_ENABLED = true;
|
||||
private const int DEFAULT_ITEMS_PER_PAGE = 48;
|
||||
private const bool DEFAULT_IGNORE_THE_PREFIX_FOR_ALPHA_PICKER = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the object representing the unique identifier of the user that owns these settings.
|
||||
/// </summary>
|
||||
public UserId UserId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether pagination is enabled for the user, or not.
|
||||
/// </summary>
|
||||
public bool IsPaginationEnabled { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of library items displayed per page when pagination is enabled.
|
||||
/// </summary>
|
||||
public int ItemsPerPage { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the "The" prefix of library item titles is ignored by the alpha picker, or not.
|
||||
/// </summary>
|
||||
public bool IgnoreThePrefixForAlphaPicker { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserSettings"/> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The object representing the unique identifier of these settings.</param>
|
||||
/// <param name="userId">The object representing the unique identifier of the user that owns these settings.</param>
|
||||
/// <param name="isPaginationEnabled">Whether pagination is enabled for the user, or not.</param>
|
||||
/// <param name="itemsPerPage">The number of library items displayed per page when pagination is enabled.</param>
|
||||
/// <param name="ignoreThePrefixForAlphaPicker">Whether the "The" prefix of library item titles is ignored by the alpha picker, or not.</param>
|
||||
private UserSettings(
|
||||
UserSettingsId id,
|
||||
UserId userId,
|
||||
bool isPaginationEnabled,
|
||||
int itemsPerPage,
|
||||
bool ignoreThePrefixForAlphaPicker) : base(id)
|
||||
{
|
||||
UserId = userId;
|
||||
IsPaginationEnabled = isPaginationEnabled;
|
||||
ItemsPerPage = itemsPerPage;
|
||||
IgnoreThePrefixForAlphaPicker = ignoreThePrefixForAlphaPicker;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="UserSettings"/> class, with the default settings.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="UserSettings"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<UserSettings> Create()
|
||||
{
|
||||
return Create(UserId.CreateUnique(), DEFAULT_IS_PAGINATION_ENABLED, DEFAULT_ITEMS_PER_PAGE, DEFAULT_IGNORE_THE_PREFIX_FOR_ALPHA_PICKER);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="UserSettings"/> class, with the default settings.
|
||||
/// </summary>
|
||||
/// <param name="userId">The object representing the unique identifier of the user that owns these settings.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="UserSettings"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<UserSettings> Create(UserId userId)
|
||||
{
|
||||
return Create(userId, DEFAULT_IS_PAGINATION_ENABLED, DEFAULT_ITEMS_PER_PAGE, DEFAULT_IGNORE_THE_PREFIX_FOR_ALPHA_PICKER);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="UserSettings"/> class.
|
||||
/// </summary>
|
||||
/// <param name="userId">The object representing the unique identifier of the user that owns these settings.</param>
|
||||
/// <param name="isPaginationEnabled">Whether pagination is enabled for the user, or not.</param>
|
||||
/// <param name="itemsPerPage">The number of library items displayed per page when pagination is enabled.</param>
|
||||
/// <param name="ignoreThePrefixForAlphaPicker">Whether the "The" prefix of library item titles is ignored by the alpha picker, or not.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="UserSettings"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<UserSettings> Create(
|
||||
UserId userId,
|
||||
bool isPaginationEnabled,
|
||||
int itemsPerPage,
|
||||
bool ignoreThePrefixForAlphaPicker)
|
||||
{
|
||||
if (itemsPerPage <= 0)
|
||||
return Errors.UserSettings.ItemsPerPageMustBeGreaterThanZero;
|
||||
|
||||
return new UserSettings(
|
||||
UserSettingsId.CreateUnique(),
|
||||
userId,
|
||||
isPaginationEnabled,
|
||||
itemsPerPage,
|
||||
ignoreThePrefixForAlphaPicker);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="UserSettings"/> class, with a pre-existing <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The object representing the unique identifier of these settings.</param>
|
||||
/// <param name="userId">The object representing the unique identifier of the user that owns these settings.</param>
|
||||
/// <param name="isPaginationEnabled">Whether pagination is enabled for the user, or not.</param>
|
||||
/// <param name="itemsPerPage">The number of library items displayed per page when pagination is enabled.</param>
|
||||
/// <param name="ignoreThePrefixForAlphaPicker">Whether the "The" prefix of library item titles is ignored by the alpha picker, or not.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="UserSettings"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<UserSettings> Create(
|
||||
UserSettingsId id,
|
||||
UserId userId,
|
||||
bool isPaginationEnabled,
|
||||
int itemsPerPage,
|
||||
bool ignoreThePrefixForAlphaPicker)
|
||||
{
|
||||
if (itemsPerPage <= 0)
|
||||
return Errors.UserSettings.ItemsPerPageMustBeGreaterThanZero;
|
||||
|
||||
return new UserSettings(id, userId, isPaginationEnabled, itemsPerPage, ignoreThePrefixForAlphaPicker);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the settings of the user.
|
||||
/// </summary>
|
||||
/// <param name="isPaginationEnabled">Whether pagination is enabled for the user, or not.</param>
|
||||
/// <param name="itemsPerPage">The number of library items displayed per page when pagination is enabled.</param>
|
||||
/// <param name="ignoreThePrefixForAlphaPicker">Whether the "The" prefix of library item titles is ignored by the alpha picker, or not.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful update, or an error.</returns>
|
||||
public Result<Updated> UpdateSettings(
|
||||
bool isPaginationEnabled,
|
||||
int itemsPerPage,
|
||||
bool ignoreThePrefixForAlphaPicker)
|
||||
{
|
||||
if (itemsPerPage <= 0)
|
||||
return Errors.UserSettings.ItemsPerPageMustBeGreaterThanZero;
|
||||
|
||||
IsPaginationEnabled = isPaginationEnabled;
|
||||
ItemsPerPage = itemsPerPage;
|
||||
IgnoreThePrefixForAlphaPicker = ignoreThePrefixForAlphaPicker;
|
||||
return Result.Updated;
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for the Id of a set of user settings.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Value}")]
|
||||
public sealed class UserSettingsId : EntityId<Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserSettingsId"/> class.
|
||||
/// </summary>
|
||||
/// <param name="value">The value representing this object.</param>
|
||||
private UserSettingsId(Guid value) : base(value)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="UserSettingsId"/> class.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="UserSettingsId"/> instance.</returns>
|
||||
public static UserSettingsId CreateUnique()
|
||||
{
|
||||
return new UserSettingsId(Guid.NewGuid());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="UserSettingsId"/> class, from a pre-existing <paramref name="value"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value used to create the <see cref="UserSettingsId"/> instance.</param>
|
||||
/// <returns>The created <see cref="UserSettingsId"/> instance.</returns>
|
||||
public static UserSettingsId Create(Guid value)
|
||||
{
|
||||
return new UserSettingsId(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of items that define equality of the object.
|
||||
/// </summary>
|
||||
/// <returns>A list of items defining the equality.</returns>
|
||||
public override IEnumerable<object> GetEqualityComponents()
|
||||
{
|
||||
yield return Value;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user