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.
30 lines
1.3 KiB
C#
30 lines
1.3 KiB
C#
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);
|
|
}
|