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:
parent
08601adc49
commit
dedfb924d8
@ -1,15 +1,17 @@
|
||||
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]")]
|
||||
@ -18,10 +20,14 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
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
|
||||
@ -150,4 +159,3 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,10 @@
|
||||
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
|
||||
{
|
||||
private readonly ReceiverModel receiverModel;
|
||||
@ -12,9 +13,11 @@ namespace EnvelopeGenerator.Web.Services
|
||||
|
||||
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);
|
||||
@ -183,4 +188,3 @@ namespace EnvelopeGenerator.Web.Services
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user