Renamed namespaces and related identifiers from EnvelopeGenerator.WebUI to EnvelopeGenerator.Server across the project. This change affects data models, services, controllers, and configuration files to ensure consistency with the new architecture. Updated @using directives in Razor components and other files to reflect the new namespace structure. Adjusted project references in EnvelopeGenerator.Server.csproj to point to the new EnvelopeGenerator.Server.Client project. Modified middleware and logging configurations to use the new EnvelopeGenerator.Server namespace, including changes in Program.cs and appsettings.json. Updated resource and file references to use the new EnvelopeGenerator.Server path, ensuring correct resource loading. Adjusted configuration options in Program.cs to use the new namespace for options classes, such as ApiOptions and PdfViewerOptions. Updated authentication scheme names and related constants to align with the new namespace structure. Revised comments and documentation to reflect the new namespace, ensuring clarity and consistency in the codebase.
92 lines
3.4 KiB
C#
92 lines
3.4 KiB
C#
using DigitalData.Core.Abstraction.Application.DTO;
|
|
using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiverReadOnly;
|
|
using EnvelopeGenerator.Application.Common.Interfaces.Services;
|
|
using EnvelopeGenerator.Domain.Constants;
|
|
using EnvelopeGenerator.Server.Extensions;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace EnvelopeGenerator.Server.Controllers;
|
|
|
|
/// <summary>
|
|
/// Manages read-only envelope sharing flows.
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class ReadOnlyController : ControllerBase
|
|
{
|
|
private readonly ILogger<ReadOnlyController> _logger;
|
|
private readonly IEnvelopeReceiverReadOnlyService _readOnlyService;
|
|
private readonly IEnvelopeMailService _mailService;
|
|
private readonly IEnvelopeHistoryService _historyService;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="ReadOnlyController"/> class.
|
|
/// </summary>
|
|
public ReadOnlyController(ILogger<ReadOnlyController> logger, IEnvelopeReceiverReadOnlyService readOnlyService, IEnvelopeMailService mailService, IEnvelopeHistoryService historyService)
|
|
{
|
|
_logger = logger;
|
|
_readOnlyService = readOnlyService;
|
|
_mailService = mailService;
|
|
_historyService = historyService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new read-only receiver for the current envelope.
|
|
/// </summary>
|
|
/// <param name="createDto">Creation payload.</param>
|
|
[HttpPost]
|
|
[Authorize(Policy = AuthPolicy.Receiver)]
|
|
[Obsolete("Use MediatR")]
|
|
public async Task<IActionResult> CreateAsync([FromBody] EnvelopeReceiverReadOnlyCreateDto createDto)
|
|
{
|
|
var authReceiverMail = User.ReceiverMail();
|
|
if (authReceiverMail is null)
|
|
{
|
|
_logger.LogError("EmailAddress claim is not found in envelope-receiver-read-only creation process. Create DTO is:\n {dto}", JsonConvert.SerializeObject(createDto));
|
|
return Unauthorized();
|
|
}
|
|
|
|
var envelopeId = User.EnvelopeId();
|
|
|
|
createDto.AddedWho = authReceiverMail;
|
|
createDto.EnvelopeId = envelopeId;
|
|
|
|
var creationRes = await _readOnlyService.CreateAsync(createDto: createDto);
|
|
|
|
if (creationRes.IsFailed)
|
|
{
|
|
_logger.LogNotice(creationRes);
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
|
|
var readRes = await _readOnlyService.ReadByIdAsync(creationRes.Data.Id);
|
|
if (readRes.IsFailed)
|
|
{
|
|
_logger.LogNotice(creationRes);
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
|
|
var newReadOnly = readRes.Data;
|
|
|
|
return await _mailService.SendAsync(newReadOnly).ThenAsync<int, IActionResult>(SuccessAsync: async _ =>
|
|
{
|
|
var histRes = await _historyService.RecordAsync((int)createDto.EnvelopeId, createDto.AddedWho, EnvelopeStatus.EnvelopeShared);
|
|
if (histRes.IsFailed)
|
|
{
|
|
_logger.LogError("Although the envelope was sent as read-only, the EnvelopeShared history could not be saved. Create DTO:\n{createDto}", JsonConvert.SerializeObject(createDto));
|
|
_logger.LogNotice(histRes.Notices);
|
|
}
|
|
|
|
return Ok();
|
|
},
|
|
|
|
Fail: (msg, ntc) =>
|
|
{
|
|
_logger.LogNotice(ntc);
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
});
|
|
}
|
|
}
|