Add user preferences management via distributed cache
Introduced `UserPreferencesDto` to represent UI preferences, including theme, dark mode, and grid layouts. Added the `IUserPreferencesService` interface and implemented it in `UserPreferencesService` to manage preferences stored in the distributed cache (`dbo.TBDD_CACHE`). Registered `UserPreferencesService` in dependency injection and added a NuGet reference for `Microsoft.Extensions.Caching.Abstractions`. Created `UserPreferencesController` with `GET` and `PUT` endpoints to retrieve and save user preferences. Validated theme names in the `PUT` endpoint. Updated `Program.cs` to ensure proper service registration.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using EnvelopeGenerator.Application.Common.Dto;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Common.Interfaces.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Manages per-user UI preferences (theme, dark mode, grid layouts).
|
||||
/// Preferences are stored in the distributed cache (dbo.TBDD_CACHE) as JSON.
|
||||
/// Cache key schema: "signflow.user-preferences:{username}"
|
||||
/// </summary>
|
||||
public interface IUserPreferencesService
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves preferences for the given user.
|
||||
/// Always returns a valid object — never throws, never returns null.
|
||||
/// Returns defaults if no entry exists in cache.
|
||||
/// </summary>
|
||||
/// <param name="username">The sender's username (ClaimTypes.Name from JWT).</param>
|
||||
/// <param name="ct">Cancellation token.</param>
|
||||
Task<UserPreferencesDto> GetAsync(string username, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Persists the given preferences for the user in the distributed cache.
|
||||
/// Failures are non-fatal and silently ignored.
|
||||
/// </summary>
|
||||
/// <param name="username">The sender's username (ClaimTypes.Name from JWT).</param>
|
||||
/// <param name="preferences">The preferences to persist.</param>
|
||||
/// <param name="ct">Cancellation token.</param>
|
||||
Task SaveAsync(string username, UserPreferencesDto preferences, CancellationToken ct = default);
|
||||
}
|
||||
Reference in New Issue
Block a user