Refactor EnvelopeController and EnvelopeOldService

Significantly refactored `EnvelopeController.cs` to improve structure, add logging, and enhance error handling in methods. Introduced new private fields and updated constructor parameters, with some marked as obsolete.

Updated `EnvelopeOldService.cs` to add private fields, improve logging, and enhance error handling in key methods. Introduced `ReceiverAlreadySigned` method and marked `GetDocument` as obsolete. Improved overall functionality and maintainability.
This commit is contained in:
tekh 2025-06-27 10:59:52 +02:00
parent 08601adc49
commit dedfb924d8
2 changed files with 296 additions and 284 deletions

View File

@ -1,27 +1,33 @@
using DigitalData.Core.DTO;
using EnvelopeGenerator.CommonServices;
using EnvelopeGenerator.CommonServices;
using EnvelopeGenerator.Web.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Text.Encodings.Web;
using static EnvelopeGenerator.CommonServices.Constants;
using EnvelopeGenerator.Extensions;
using EnvelopeGenerator.Application.Contracts.Services;
using static EnvelopeGenerator.Domain.Constants;
using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Domain;
using DigitalData.Core.Abstraction.Application.DTO;
namespace EnvelopeGenerator.Web.Controllers
namespace EnvelopeGenerator.Web.Controllers;
[Authorize(Roles = ReceiverRole.FullyAuth)]
[ApiController]
[Route("api/[controller]")]
public class EnvelopeController : BaseController
{
[Authorize(Roles = ReceiverRole.FullyAuth)]
[ApiController]
[Route("api/[controller]")]
public class EnvelopeController : BaseController
{
private readonly EnvelopeOldService envelopeService;
private readonly ActionService? actionService;
private readonly UrlEncoder _urlEncoder;
[Obsolete("Use MediatR")]
private readonly IEnvelopeHistoryService _histService;
[Obsolete("Use MediatR")]
private readonly IReceiverService _receiverService;
[Obsolete("Use MediatR")]
private readonly IEnvelopeReceiverService _envRcvService;
[Obsolete("Use MediatR")]
public EnvelopeController(DatabaseService database,
EnvelopeOldService envelope,
ILogger<EnvelopeController> logger, UrlEncoder urlEncoder,
@ -38,6 +44,7 @@ namespace EnvelopeGenerator.Web.Controllers
}
[NonAction]
[Obsolete("Use MediatR")]
public async Task<IActionResult> Get([FromRoute] string envelopeKey)
{
try
@ -66,6 +73,7 @@ namespace EnvelopeGenerator.Web.Controllers
[Authorize(Roles = ReceiverRole.FullyAuth)]
[HttpPost("{envelopeKey}")]
[Obsolete("Use MediatR")]
public async Task<IActionResult> Update(string envelopeKey, int index)
{
try
@ -91,12 +99,12 @@ namespace EnvelopeGenerator.Web.Controllers
string? annotationData = await envelopeService.EnsureValidAnnotationData(Request);
envelopeService.InsertDocumentStatus(new Common.DocumentStatus()
envelopeService.InsertDocumentStatus(new Domain.Entities.DocumentStatus()
{
EnvelopeId = response.Envelope.Id,
ReceiverId = response.Receiver.Id,
Value = annotationData,
Status = Common.Constants.DocumentStatus.Signed
Status = Constants.DocumentStatus.Signed
});
var signResult = actionService?.SignEnvelope(response.Envelope, response.Receiver);
@ -112,6 +120,7 @@ namespace EnvelopeGenerator.Web.Controllers
[Authorize(Roles = ReceiverRole.FullyAuth)]
[HttpPost("reject")]
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public async Task<IActionResult> Reject([FromBody] string? reason = null)
{
try
@ -149,5 +158,4 @@ namespace EnvelopeGenerator.Web.Controllers
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
}
}

View File

@ -1,20 +1,23 @@
using EnvelopeGenerator.Application.Contracts.Services;
using EnvelopeGenerator.CommonServices;
using EnvelopeGenerator.Domain.Entities;
using System.Text;
namespace EnvelopeGenerator.Web.Services
namespace EnvelopeGenerator.Web.Services;
public class EnvelopeOldService
{
public class EnvelopeOldService
{
private readonly ReceiverModel receiverModel;
private readonly EnvelopeModel envelopeModel;
private readonly HistoryModel historyModel;
private readonly DocumentStatusModel documentStatusModel;
[Obsolete("Use MediatR")]
private readonly IConfigService _configService;
private readonly ILogger<EnvelopeOldService> _logger;
[Obsolete("Use MediatR")]
public EnvelopeOldService(DatabaseService database, IConfigService configService, ILogger<EnvelopeOldService> logger)
{
_logger = logger;
@ -48,6 +51,7 @@ namespace EnvelopeGenerator.Web.Services
throw new ArgumentNullException("ReceiverSignature");
}
[Obsolete("Use MediatR")]
public async Task<EnvelopeReceiver> LoadEnvelope(string pEnvelopeKey)
{
_logger.LogInformation("Loading Envelope by Key [{0}]", pEnvelopeKey);
@ -150,6 +154,7 @@ namespace EnvelopeGenerator.Web.Services
}
}
[Obsolete("Use MediatR")]
public async Task<EnvelopeDocument> GetDocument(int documentId, string envelopeKey)
{
EnvelopeReceiver response = await LoadEnvelope(envelopeKey);
@ -168,7 +173,7 @@ namespace EnvelopeGenerator.Web.Services
return document;
}
public bool InsertDocumentStatus(Common.DocumentStatus documentStatus)
public bool InsertDocumentStatus(DocumentStatus documentStatus)
{
_logger.LogInformation("Saving annotation data..");
return documentStatusModel.InsertOrUpdate(documentStatus);
@ -182,5 +187,4 @@ namespace EnvelopeGenerator.Web.Services
return bytes;
}
}
}