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

View File

@ -1,9 +1,10 @@
using EnvelopeGenerator.Application.Contracts.Services; using EnvelopeGenerator.Application.Contracts.Services;
using EnvelopeGenerator.CommonServices; using EnvelopeGenerator.CommonServices;
using EnvelopeGenerator.Domain.Entities;
using System.Text; using System.Text;
namespace EnvelopeGenerator.Web.Services namespace EnvelopeGenerator.Web.Services;
{
public class EnvelopeOldService public class EnvelopeOldService
{ {
private readonly ReceiverModel receiverModel; private readonly ReceiverModel receiverModel;
@ -12,9 +13,11 @@ namespace EnvelopeGenerator.Web.Services
private readonly DocumentStatusModel documentStatusModel; private readonly DocumentStatusModel documentStatusModel;
[Obsolete("Use MediatR")]
private readonly IConfigService _configService; private readonly IConfigService _configService;
private readonly ILogger<EnvelopeOldService> _logger; private readonly ILogger<EnvelopeOldService> _logger;
[Obsolete("Use MediatR")]
public EnvelopeOldService(DatabaseService database, IConfigService configService, ILogger<EnvelopeOldService> logger) public EnvelopeOldService(DatabaseService database, IConfigService configService, ILogger<EnvelopeOldService> logger)
{ {
_logger = logger; _logger = logger;
@ -48,6 +51,7 @@ namespace EnvelopeGenerator.Web.Services
throw new ArgumentNullException("ReceiverSignature"); throw new ArgumentNullException("ReceiverSignature");
} }
[Obsolete("Use MediatR")]
public async Task<EnvelopeReceiver> LoadEnvelope(string pEnvelopeKey) public async Task<EnvelopeReceiver> LoadEnvelope(string pEnvelopeKey)
{ {
_logger.LogInformation("Loading Envelope by Key [{0}]", 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) public async Task<EnvelopeDocument> GetDocument(int documentId, string envelopeKey)
{ {
EnvelopeReceiver response = await LoadEnvelope(envelopeKey); EnvelopeReceiver response = await LoadEnvelope(envelopeKey);
@ -168,7 +173,7 @@ namespace EnvelopeGenerator.Web.Services
return document; return document;
} }
public bool InsertDocumentStatus(Common.DocumentStatus documentStatus) public bool InsertDocumentStatus(DocumentStatus documentStatus)
{ {
_logger.LogInformation("Saving annotation data.."); _logger.LogInformation("Saving annotation data..");
return documentStatusModel.InsertOrUpdate(documentStatus); return documentStatusModel.InsertOrUpdate(documentStatus);
@ -183,4 +188,3 @@ namespace EnvelopeGenerator.Web.Services
return bytes; return bytes;
} }
} }
}