mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 17: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
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Settings.Queries.GetUserSettings;
|
||||
using Lumina.Contracts.Responses.UsersManagement.Settings;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.UsersManagement;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Settings.GetUserSettings;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/settings</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class GetUserSettingsEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetUserSettingsQuery, Result<UserSettingsResponse>> _getUserSettingsQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetUserSettingsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getUserSettingsQueryHandler">Injected service for handling get user settings queries.</param>
|
||||
public GetUserSettingsEndpoint(IQueryHandler<GetUserSettingsQuery, Result<UserSettingsResponse>> getUserSettingsQueryHandler)
|
||||
{
|
||||
_getUserSettingsQueryHandler = getUserSettingsQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Users.GET_USER_SETTINGS);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the settings of the current user.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<UserSettingsResponse> result = await _getUserSettingsQueryHandler.HandleAsync(new GetUserSettingsQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.UsersManagement.Settings;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Settings.GetUserSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetUserSettingsEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetUserSettingsEndpointSummary : Summary<GetUserSettingsEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetUserSettingsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetUserSettingsEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the settings of the current user.";
|
||||
Description = "Retrieves the settings of the current user. When no settings are stored for the user yet, the default settings are returned.";
|
||||
|
||||
Response(200, "The settings of the current user are returned.",
|
||||
example: new UserSettingsResponse(
|
||||
UserId: Guid.NewGuid(),
|
||||
IsPaginationEnabled: true,
|
||||
ItemsPerPage: 48,
|
||||
IgnoreThePrefixForAlphaPicker: false
|
||||
));
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/users/me/settings"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
instance = "/api/v1/users/me/settings"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/users/me/settings"
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.UsersManagement.Users;
|
||||
using Lumina.Application.Core.UsersManagement.Settings.Commands.UpdateUserSettings;
|
||||
using Lumina.Contracts.Requests.UsersManagement.Settings;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.UsersManagement;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Settings.UpdateUserSettings;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/settings</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class UpdateUserSettingsEndpoint : BaseEndpoint<UpdateUserSettingsRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<UpdateUserSettingsCommand, Result<Updated>> _updateUserSettingsCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateUserSettingsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="updateUserSettingsCommandHandler">Injected service for handling update user settings commands.</param>
|
||||
public UpdateUserSettingsEndpoint(ICommandHandler<UpdateUserSettingsCommand, Result<Updated>> updateUserSettingsCommandHandler)
|
||||
{
|
||||
_updateUserSettingsCommandHandler = updateUserSettingsCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.PUT);
|
||||
Routes(ApiRoutes.Users.UPDATE_USER_SETTINGS);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the settings of the current user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the new settings of the current user.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(UpdateUserSettingsRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<Updated> result = await _updateUserSettingsCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.UsersManagement.Settings;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Settings.UpdateUserSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="UpdateUserSettingsEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateUserSettingsEndpointSummary : Summary<UpdateUserSettingsEndpoint, UpdateUserSettingsRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateUserSettingsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public UpdateUserSettingsEndpointSummary()
|
||||
{
|
||||
Summary = "Updates the settings of the current user.";
|
||||
Description = "Updates the settings of the current user. When no settings are stored for the user yet, they are created with the provided values.";
|
||||
|
||||
ExampleRequest = new UpdateUserSettingsRequest(
|
||||
IsPaginationEnabled: true,
|
||||
ItemsPerPage: 48,
|
||||
IgnoreThePrefixForAlphaPicker: false
|
||||
);
|
||||
|
||||
Response(200, "The settings of the current user were successfully updated.");
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/users/me/settings"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
instance = "/api/v1/users/me/settings"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/users/me/settings"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/users/me/settings",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"ItemsPerPageMustBeGreaterThanZero"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user