Add new controllers for envelope management
Introduced multiple controllers to enhance application functionality: - `AnnotationController`: Manages annotations and signature lifecycle. - `AuthController`: Handles user authentication and session management. - `CacheController`: Manages cached data for receivers. - `ConfigController`: Exposes client configuration data. - `DocumentController`: Provides access to envelope documents. - `EmailTemplateController`: Manages email templates. - `EnvelopeController`: Manages envelope operations. - `EnvelopeReceiverController`: Handles envelope receiver data. - `EnvelopeTypeController`: Retrieves envelope types. - `HistoryController`: Accesses envelope history. - `IAuthController`: Defines authentication interface. - `LocalizationController`: Manages localization settings. - `ReadOnlyController`: Manages read-only envelope sharing. - `ReceiverController`: Retrieves receiver data. - `SignatureController`: Retrieves document signatures. - `TfaRegistrationController`: Manages two-factor authentication. These changes improve maintainability and scalability by organizing operations into dedicated controllers.
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Text.Json;
|
||||
using EnvelopeGenerator.API.Options;
|
||||
using EnvelopeGenerator.Domain.Constants;
|
||||
using EnvelopeGenerator.API.Extensions;
|
||||
|
||||
namespace EnvelopeGenerator.API.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Manages cached data for receivers using distributed cache.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
[Authorize(Policy = AuthPolicy.Receiver)]
|
||||
public class CacheController(
|
||||
IDistributedCache cache,
|
||||
IOptions<CacheOptions> cacheOptions) : ControllerBase
|
||||
{
|
||||
private const string SignatureCacheKeyPrefix = "envelope-generator.receiver-ui.signature:";
|
||||
|
||||
/// <summary>
|
||||
/// Stores a receiver's signature in cache for the specified envelope.
|
||||
/// </summary>
|
||||
[Authorize(Policy = AuthPolicy.Receiver)]
|
||||
[HttpPost("SignatureCapture/{envelopeKey}")]
|
||||
public async Task<IActionResult> SaveSignature(
|
||||
[FromRoute] string envelopeKey,
|
||||
[FromBody] SignatureCacheRequest request,
|
||||
CancellationToken cancel)
|
||||
{
|
||||
var cacheKey = $"{SignatureCacheKeyPrefix}{User.ReceiverSignature()}";
|
||||
var json = JsonSerializer.Serialize(request);
|
||||
|
||||
var options = cacheOptions.Value.SignatureCacheExpiration.HasValue
|
||||
? new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = cacheOptions.Value.SignatureCacheExpiration.Value }
|
||||
: null;
|
||||
|
||||
await cache.SetStringAsync(cacheKey, json, options ?? new DistributedCacheEntryOptions(), cancel);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a cached signature for the specified envelope.
|
||||
/// </summary>
|
||||
[Authorize(Policy = AuthPolicy.Receiver)]
|
||||
[HttpGet("SignatureCapture/{envelopeKey}")]
|
||||
public async Task<IActionResult> GetSignature([FromRoute] string envelopeKey, CancellationToken cancel)
|
||||
{
|
||||
var cacheKey = $"{SignatureCacheKeyPrefix}{User.ReceiverSignature()}";
|
||||
var json = await cache.GetStringAsync(cacheKey, cancel);
|
||||
|
||||
if (json is null)
|
||||
return NotFound();
|
||||
|
||||
var signature = JsonSerializer.Deserialize<SignatureCacheRequest>(json);
|
||||
return Ok(signature);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a cached signature for the specified envelope.
|
||||
/// </summary>
|
||||
[Authorize(Policy = AuthPolicy.Receiver)]
|
||||
[HttpDelete("SignatureCapture/{envelopeKey}")]
|
||||
public async Task<IActionResult> DeleteSignature([FromRoute] string envelopeKey, CancellationToken cancel)
|
||||
{
|
||||
var cacheKey = $"{SignatureCacheKeyPrefix}{User.ReceiverSignature()}";
|
||||
await cache.RemoveAsync(cacheKey, cancel);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request model for caching signature data.
|
||||
/// </summary>
|
||||
public sealed record SignatureCacheRequest(
|
||||
string DataUrl,
|
||||
string FullName,
|
||||
string Place,
|
||||
string? Position = null);
|
||||
Reference in New Issue
Block a user