Update CacheController and SignatureCacheRequest

- Added `using EnvelopeGenerator.API.Extensions;` for utilities.
- Changed `SignatureCacheKeyPrefix` to a new prefix value.
- Added `[Authorize(Policy = AuthPolicy.Receiver)]` to methods.
- Used `[FromRoute]` for `envelopeKey` in route-bound methods.
- Updated cache key logic to use `User.ReceiverSignature`.
- Made `DataUrl`, `FullName`, and `Place` required in `SignatureCacheRequest`.
- Set default value (`null`) for `Position` in `SignatureCacheRequest`.
This commit is contained in:
2026-06-09 10:59:13 +02:00
parent 5b220932d3
commit b8926f25c4

View File

@@ -5,6 +5,7 @@ using Microsoft.Extensions.Options;
using System.Text.Json; using System.Text.Json;
using EnvelopeGenerator.API.Options; using EnvelopeGenerator.API.Options;
using EnvelopeGenerator.Domain.Constants; using EnvelopeGenerator.Domain.Constants;
using EnvelopeGenerator.API.Extensions;
namespace EnvelopeGenerator.API.Controllers; namespace EnvelopeGenerator.API.Controllers;
@@ -18,18 +19,19 @@ public class CacheController(
IDistributedCache cache, IDistributedCache cache,
IOptions<CacheOptions> cacheOptions) : ControllerBase IOptions<CacheOptions> cacheOptions) : ControllerBase
{ {
private const string SignatureCacheKeyPrefix = "signature:91751687-8ae6-4777-bf5f-b8846085e62e:"; private const string SignatureCacheKeyPrefix = "envelope-generator.receiver-ui.signature:";
/// <summary> /// <summary>
/// Stores a receiver's signature in cache for the specified envelope. /// Stores a receiver's signature in cache for the specified envelope.
/// </summary> /// </summary>
[Authorize(Policy = AuthPolicy.Receiver)]
[HttpPost("SignatureCapture/{envelopeKey}")] [HttpPost("SignatureCapture/{envelopeKey}")]
public async Task<IActionResult> SaveSignature( public async Task<IActionResult> SaveSignature(
string envelopeKey, [FromRoute] string envelopeKey,
[FromBody] SignatureCacheRequest request, [FromBody] SignatureCacheRequest request,
CancellationToken cancel) CancellationToken cancel)
{ {
var cacheKey = $"{SignatureCacheKeyPrefix}{envelopeKey}"; var cacheKey = $"{SignatureCacheKeyPrefix}{User.ReceiverSignature}";
var json = JsonSerializer.Serialize(request); var json = JsonSerializer.Serialize(request);
var options = cacheOptions.Value.SignatureCacheExpiration.HasValue var options = cacheOptions.Value.SignatureCacheExpiration.HasValue
@@ -44,10 +46,11 @@ public class CacheController(
/// <summary> /// <summary>
/// Retrieves a cached signature for the specified envelope. /// Retrieves a cached signature for the specified envelope.
/// </summary> /// </summary>
[Authorize(Policy = AuthPolicy.Receiver)]
[HttpGet("SignatureCapture/{envelopeKey}")] [HttpGet("SignatureCapture/{envelopeKey}")]
public async Task<IActionResult> GetSignature(string envelopeKey, CancellationToken cancel) public async Task<IActionResult> GetSignature([FromRoute] string envelopeKey, CancellationToken cancel)
{ {
var cacheKey = $"{SignatureCacheKeyPrefix}{envelopeKey}"; var cacheKey = $"{SignatureCacheKeyPrefix}{User.ReceiverSignature}";
var json = await cache.GetStringAsync(cacheKey, cancel); var json = await cache.GetStringAsync(cacheKey, cancel);
if (json is null) if (json is null)
@@ -60,10 +63,11 @@ public class CacheController(
/// <summary> /// <summary>
/// Deletes a cached signature for the specified envelope. /// Deletes a cached signature for the specified envelope.
/// </summary> /// </summary>
[Authorize(Policy = AuthPolicy.Receiver)]
[HttpDelete("SignatureCapture/{envelopeKey}")] [HttpDelete("SignatureCapture/{envelopeKey}")]
public async Task<IActionResult> DeleteSignature(string envelopeKey, CancellationToken cancel) public async Task<IActionResult> DeleteSignature([FromRoute] string envelopeKey, CancellationToken cancel)
{ {
var cacheKey = $"{SignatureCacheKeyPrefix}{envelopeKey}"; var cacheKey = $"{SignatureCacheKeyPrefix}{User.ReceiverSignature}";
await cache.RemoveAsync(cacheKey, cancel); await cache.RemoveAsync(cacheKey, cancel);
return Ok(); return Ok();
@@ -74,9 +78,7 @@ public class CacheController(
/// Request model for caching signature data. /// Request model for caching signature data.
/// </summary> /// </summary>
public sealed record SignatureCacheRequest( public sealed record SignatureCacheRequest(
string? DataUrl, string DataUrl,
string? FullName, string FullName,
string? Position, string Place,
string? Place); string? Position = null);