Refactor HomeController for MediatR and domain model
- Added new using directives for domain-driven design. - Marked several fields and methods as obsolete to transition to MediatR for request handling. - Updated action methods to use middleware for exception management. - Changed response type in EnvelopeSigned method for consistency with new domain model. - Overall improvements for maintainability and adherence to best practices.
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using EnvelopeGenerator.CommonServices;
|
using EnvelopeGenerator.Web.Services;
|
||||||
using EnvelopeGenerator.Web.Services;
|
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -8,33 +7,40 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using DigitalData.Core.API;
|
using DigitalData.Core.API;
|
||||||
using EnvelopeGenerator.Extensions;
|
using EnvelopeGenerator.Extensions;
|
||||||
using Microsoft.Extensions.Localization;
|
using Microsoft.Extensions.Localization;
|
||||||
using DigitalData.Core.DTO;
|
|
||||||
using Microsoft.AspNetCore.Localization;
|
using Microsoft.AspNetCore.Localization;
|
||||||
using EnvelopeGenerator.Web.Models;
|
using EnvelopeGenerator.Web.Models;
|
||||||
using EnvelopeGenerator.Application.Resources;
|
using EnvelopeGenerator.Application.Resources;
|
||||||
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
|
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
|
||||||
using static EnvelopeGenerator.CommonServices.Constants;
|
|
||||||
using Ganss.Xss;
|
using Ganss.Xss;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using EnvelopeGenerator.Application.DTOs;
|
using EnvelopeGenerator.Application.DTOs;
|
||||||
using DigitalData.Core.Client;
|
using DigitalData.Core.Client;
|
||||||
using OtpNet;
|
using OtpNet;
|
||||||
using EnvelopeGenerator.Application.Contracts.Services;
|
using EnvelopeGenerator.Application.Contracts.Services;
|
||||||
|
using static EnvelopeGenerator.Domain.Constants;
|
||||||
|
using DigitalData.Core.Abstraction.Application.DTO;
|
||||||
|
using EnvelopeGenerator.Domain.Entities;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Web.Controllers;
|
namespace EnvelopeGenerator.Web.Controllers;
|
||||||
|
|
||||||
public class HomeController : ViewControllerBase
|
public class HomeController : ViewControllerBase
|
||||||
{
|
{
|
||||||
private readonly EnvelopeOldService envelopeOldService;
|
private readonly EnvelopeOldService envelopeOldService;
|
||||||
|
[Obsolete("Use MediatR")]
|
||||||
private readonly IEnvelopeReceiverService _envRcvService;
|
private readonly IEnvelopeReceiverService _envRcvService;
|
||||||
|
[Obsolete("Use MediatR")]
|
||||||
private readonly IEnvelopeHistoryService _historyService;
|
private readonly IEnvelopeHistoryService _historyService;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
|
[Obsolete("Use MediatR")]
|
||||||
private readonly IEnvelopeMailService _mailService;
|
private readonly IEnvelopeMailService _mailService;
|
||||||
|
[Obsolete("Use MediatR")]
|
||||||
private readonly IEnvelopeReceiverReadOnlyService _readOnlyService;
|
private readonly IEnvelopeReceiverReadOnlyService _readOnlyService;
|
||||||
private readonly IAuthenticator _authenticator;
|
private readonly IAuthenticator _authenticator;
|
||||||
|
[Obsolete("Use MediatR")]
|
||||||
private readonly IReceiverService _rcvService;
|
private readonly IReceiverService _rcvService;
|
||||||
private readonly IEnvelopeSmsHandler _envSmsHandler;
|
private readonly IEnvelopeSmsHandler _envSmsHandler;
|
||||||
|
|
||||||
|
[Obsolete("Use MediatR")]
|
||||||
public HomeController(EnvelopeOldService envelopeOldService, ILogger<HomeController> logger, IEnvelopeReceiverService envelopeReceiverService, IEnvelopeHistoryService historyService, IStringLocalizer<Resource> localizer, IConfiguration configuration, HtmlSanitizer sanitizer, Cultures cultures, IEnvelopeMailService envelopeMailService, IEnvelopeReceiverReadOnlyService readOnlyService, IAuthenticator authenticator, IReceiverService receiverService, IEnvelopeSmsHandler envelopeSmsService) : base(logger, sanitizer, cultures, localizer)
|
public HomeController(EnvelopeOldService envelopeOldService, ILogger<HomeController> logger, IEnvelopeReceiverService envelopeReceiverService, IEnvelopeHistoryService historyService, IStringLocalizer<Resource> localizer, IConfiguration configuration, HtmlSanitizer sanitizer, Cultures cultures, IEnvelopeMailService envelopeMailService, IEnvelopeReceiverReadOnlyService readOnlyService, IAuthenticator authenticator, IReceiverService receiverService, IEnvelopeSmsHandler envelopeSmsService) : base(logger, sanitizer, cultures, localizer)
|
||||||
{
|
{
|
||||||
this.envelopeOldService = envelopeOldService;
|
this.envelopeOldService = envelopeOldService;
|
||||||
@@ -69,6 +75,7 @@ public class HomeController : ViewControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("EnvelopeKey/{envelopeReceiverId}")]
|
[HttpGet("EnvelopeKey/{envelopeReceiverId}")]
|
||||||
|
[Obsolete("Use MediatR")]
|
||||||
public async Task<IActionResult> MainAsync([FromRoute] string envelopeReceiverId, [FromQuery] string? culture = null)
|
public async Task<IActionResult> MainAsync([FromRoute] string envelopeReceiverId, [FromQuery] string? culture = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -131,6 +138,7 @@ public class HomeController : ViewControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("EnvelopeKey/{envelopeReceiverId}/Locked")]
|
[HttpGet("EnvelopeKey/{envelopeReceiverId}/Locked")]
|
||||||
|
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
|
||||||
public async Task<IActionResult> EnvelopeLocked([FromRoute] string envelopeReceiverId)
|
public async Task<IActionResult> EnvelopeLocked([FromRoute] string envelopeReceiverId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -401,6 +409,7 @@ public class HomeController : ViewControllerBase
|
|||||||
|
|
||||||
[Authorize(Roles = ReceiverRole.FullyAuth)]
|
[Authorize(Roles = ReceiverRole.FullyAuth)]
|
||||||
[HttpGet("EnvelopeKey/{envelopeReceiverId}/Success")]
|
[HttpGet("EnvelopeKey/{envelopeReceiverId}/Success")]
|
||||||
|
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
|
||||||
public async Task<IActionResult> EnvelopeSigned(string envelopeReceiverId)
|
public async Task<IActionResult> EnvelopeSigned(string envelopeReceiverId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -412,7 +421,7 @@ public class HomeController : ViewControllerBase
|
|||||||
if(!isExisting)
|
if(!isExisting)
|
||||||
return this.ViewEnvelopeNotFound();
|
return this.ViewEnvelopeNotFound();
|
||||||
|
|
||||||
Common.EnvelopeReceiver response = await envelopeOldService.LoadEnvelope(envelopeReceiverId);
|
EnvelopeReceiver response = await envelopeOldService.LoadEnvelope(envelopeReceiverId);
|
||||||
if (!envelopeOldService.ReceiverAlreadySigned((Envelope)response.Envelope, (int)response.Receiver.Id))
|
if (!envelopeOldService.ReceiverAlreadySigned((Envelope)response.Envelope, (int)response.Receiver.Id))
|
||||||
return base.Redirect($"/EnvelopeKey/{envelopeReceiverId}/Locked");
|
return base.Redirect($"/EnvelopeKey/{envelopeReceiverId}/Locked");
|
||||||
|
|
||||||
@@ -436,6 +445,7 @@ public class HomeController : ViewControllerBase
|
|||||||
|
|
||||||
[Authorize(Roles = ReceiverRole.FullyAuth)]
|
[Authorize(Roles = ReceiverRole.FullyAuth)]
|
||||||
[HttpGet("EnvelopeKey/{envelopeReceiverId}/Rejected")]
|
[HttpGet("EnvelopeKey/{envelopeReceiverId}/Rejected")]
|
||||||
|
[Obsolete("Use MediatR")]
|
||||||
public async Task<IActionResult> EnvelopeRejected(string envelopeReceiverId)
|
public async Task<IActionResult> EnvelopeRejected(string envelopeReceiverId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -467,6 +477,7 @@ public class HomeController : ViewControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("EnvelopeKey/{readOnlyKey}/ReadOnly")]
|
[HttpGet("EnvelopeKey/{readOnlyKey}/ReadOnly")]
|
||||||
|
[Obsolete("Use MediatR")]
|
||||||
public async Task<IActionResult> EnvelopeReceiverReadOnly([FromRoute] string readOnlyKey)
|
public async Task<IActionResult> EnvelopeReceiverReadOnly([FromRoute] string readOnlyKey)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user