Refactor controllers and views for MediatR integration

Updated several C# controllers to use the new
`DigitalData.Core.Abstraction.Application.DTO` namespace
and removed references to `DigitalData.Core.DTO`. Added
`[Obsolete("Use MediatR")]` attributes to indicate a shift
towards MediatR for request handling. Improved error
handling and code organization in key methods. Updated
Razor view files to reflect namespace changes for
consistency across the application.
This commit is contained in:
tekh 2025-06-27 13:24:12 +02:00
parent e628309734
commit fcbe956095
7 changed files with 69 additions and 63 deletions

View File

@ -4,25 +4,28 @@ using Microsoft.AspNetCore.Mvc;
using EnvelopeGenerator.Extensions;
using Microsoft.Extensions.Localization;
using EnvelopeGenerator.Application.Resources;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.Extensions;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Authorization;
using static EnvelopeGenerator.CommonServices.Constants;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication;
using EnvelopeGenerator.Application.Contracts.Services;
using DigitalData.Core.Abstraction.Application.DTO;
using static EnvelopeGenerator.Domain.Constants;
namespace EnvelopeGenerator.Web.Controllers;
//TODO: Add authorization as well as limiting the link duration (intermediate token with different role) or sign it
public class TFARegController : ViewControllerBase
{
[Obsolete("Use MediatR")]
private readonly IEnvelopeReceiverService _envRcvService;
private readonly IAuthenticator _authenticator;
[Obsolete("Use MediatR")]
private readonly IReceiverService _rcvService;
private readonly TFARegParams _params;
[Obsolete("Use MediatR")]
public TFARegController(ILogger<TFARegController> logger, HtmlSanitizer sanitizer, Cultures cultures, IStringLocalizer<Resource> localizer, IEnvelopeReceiverService erService, IAuthenticator authenticator, IReceiverService receiverService, IOptions<TFARegParams> tfaRegParamsOptions) : base(logger, sanitizer, cultures, localizer)
{
_envRcvService = erService;
@ -34,6 +37,7 @@ public class TFARegController : ViewControllerBase
//TODO: move under auth route
[Authorize]
[HttpGet("tfa/{envelopeReceiverId}")]
[Obsolete("Use MediatR")]
public async Task<IActionResult> Reg(string envelopeReceiverId)
{
try

View File

@ -1,66 +1,66 @@
using DigitalData.Core.API;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Extensions;
using EnvelopeGenerator.Domain.Entities;
using Microsoft.AspNetCore.Mvc;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
using EnvelopeGenerator.Application.Contracts.Services;
using DigitalData.Core.Abstraction.Application.DTO;
namespace EnvelopeGenerator.Web.Controllers.Test
namespace EnvelopeGenerator.Web.Controllers.Test;
[Obsolete("Use MediatR")]
public class TestEnvelopeReceiverController : ReadControllerBase<IEnvelopeReceiverService, EnvelopeReceiverDto, EnvelopeReceiver, (int Envelope, int Receiver)>
{
public class TestEnvelopeReceiverController : ReadControllerBase<IEnvelopeReceiverService, EnvelopeReceiverDto, EnvelopeReceiver, (int Envelope, int Receiver)>
public TestEnvelopeReceiverController(ILogger<TestEnvelopeReceiverController> logger, IEnvelopeReceiverService service) : base(logger, service)
{
public TestEnvelopeReceiverController(ILogger<TestEnvelopeReceiverController> logger, IEnvelopeReceiverService service) : base(logger, service)
}
[HttpGet("verify-access-code/{envelope_receiver_id}")]
public async Task<IActionResult> VerifyAccessCode([FromRoute] string envelope_receiver_id, [FromQuery] string access_code)
{
var verification = await _service.VerifyAccessCodeAsync(envelopeReceiverId:envelope_receiver_id, accessCode: access_code);
if (verification.IsSuccess)
return Ok(verification);
else if (verification.HasFlag(Flag.SecurityBreach))
return Forbid();
else if (verification.HasFlag(Flag.SecurityBreachOrDataIntegrity))
return Conflict();
else
return this.InnerServiceError(verification);
}
[HttpGet("e-r-id/{envelope_receiver_id}")]
public async Task<IActionResult> GetByEnvelopeReceiverId([FromRoute] string envelope_receiver_id)
{
var er_result = await _service.ReadByEnvelopeReceiverIdAsync(envelopeReceiverId: envelope_receiver_id);
if (er_result.IsSuccess)
return Ok(er_result);
else
return this.InnerServiceError(er_result);
}
[HttpGet("decode")]
public IActionResult DecodeEnvelopeReceiverId(string envelopeReceiverId, bool isReadOnly = false)
{
if (isReadOnly)
{
var readOnlyId = envelopeReceiverId.DecodeEnvelopeReceiverReadOnlyId();
return Ok(new { readOnlyId });
}
[HttpGet("verify-access-code/{envelope_receiver_id}")]
public async Task<IActionResult> VerifyAccessCode([FromRoute] string envelope_receiver_id, [FromQuery] string access_code)
else
{
var verification = await _service.VerifyAccessCodeAsync(envelopeReceiverId:envelope_receiver_id, accessCode: access_code);
if (verification.IsSuccess)
return Ok(verification);
else if (verification.HasFlag(Flag.SecurityBreach))
return Forbid();
else if (verification.HasFlag(Flag.SecurityBreachOrDataIntegrity))
return Conflict();
else
return this.InnerServiceError(verification);
}
[HttpGet("e-r-id/{envelope_receiver_id}")]
public async Task<IActionResult> GetByEnvelopeReceiverId([FromRoute] string envelope_receiver_id)
{
var er_result = await _service.ReadByEnvelopeReceiverIdAsync(envelopeReceiverId: envelope_receiver_id);
if (er_result.IsSuccess)
return Ok(er_result);
else
return this.InnerServiceError(er_result);
}
[HttpGet("decode")]
public IActionResult DecodeEnvelopeReceiverId(string envelopeReceiverId, bool isReadOnly = false)
{
if (isReadOnly)
{
var readOnlyId = envelopeReceiverId.DecodeEnvelopeReceiverReadOnlyId();
return Ok(new { readOnlyId });
}
else
{
var (EnvelopeUuid, ReceiverSignature) = envelopeReceiverId.DecodeEnvelopeReceiverId();
return Ok(new { uuid = EnvelopeUuid, signature = ReceiverSignature });
}
}
[HttpGet("encode")]
public IActionResult EncodeEnvelopeReceiverId(string? uuid = null, string? signature = null, long? readOnlyId = null)
{
if(readOnlyId is long readOnlyId_long)
return Ok(readOnlyId_long.EncodeEnvelopeReceiverId());
else
return Ok((uuid ?? string.Empty, signature ?? string.Empty).EncodeEnvelopeReceiverId());
var (EnvelopeUuid, ReceiverSignature) = envelopeReceiverId.DecodeEnvelopeReceiverId();
return Ok(new { uuid = EnvelopeUuid, signature = ReceiverSignature });
}
}
[HttpGet("encode")]
public IActionResult EncodeEnvelopeReceiverId(string? uuid = null, string? signature = null, long? readOnlyId = null)
{
if(readOnlyId is long readOnlyId_long)
return Ok(readOnlyId_long.EncodeEnvelopeReceiverId());
else
return Ok((uuid ?? string.Empty, signature ?? string.Empty).EncodeEnvelopeReceiverId());
}
}

View File

@ -4,6 +4,7 @@ using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Web.Controllers.Test;
[Obsolete("Use MediatR")]
public class TestEnvelopeTypeController : TestControllerBase<IEnvelopeTypeService, EnvelopeTypeDto, EnvelopeType, int>
{
public TestEnvelopeTypeController(ILogger<TestEnvelopeTypeController> logger, IEnvelopeTypeService service) : base(logger, service)

View File

@ -2,13 +2,13 @@
using EnvelopeGenerator.Application.DTOs;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Web.Controllers.Test
{
public class TestUserReceiverController : TestControllerBase< IUserReceiverService, UserReceiverDto, UserReceiver, int>
{
public TestUserReceiverController(ILogger<TestUserReceiverController> logger, IUserReceiverService service) : base(logger, service)
{
namespace EnvelopeGenerator.Web.Controllers.Test;
[Obsolete("Use MediatR")]
public class TestUserReceiverController : TestControllerBase< IUserReceiverService, UserReceiverDto, UserReceiver, int>
{
public TestUserReceiverController(ILogger<TestUserReceiverController> logger, IUserReceiverService service) : base(logger, service)
{
}
}
}

View File

@ -4,7 +4,7 @@
@{
var nonce = _accessor.HttpContext?.Items["csp-nonce"] as string;
}
@using DigitalData.Core.DTO;
@using DigitalData.Core.Abstraction.Application.DTO;
@using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver
@using Newtonsoft.Json
@using Newtonsoft.Json.Serialization

View File

@ -2,7 +2,7 @@
var nonce = _accessor.HttpContext?.Items["csp-nonce"] as string;
var cImg = _cImgOpt.Value;
}
@using DigitalData.Core.DTO;
@using DigitalData.Core.Abstraction.Application;
@using EnvelopeGenerator.Application.DTOs;
@using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver
@using EnvelopeGenerator.Application.DTOs.EnvelopeReceiverReadOnly

View File

@ -1,5 +1,6 @@
@using EnvelopeGenerator.CommonServices;
@using static EnvelopeGenerator.CommonServices.Constants;
@using EnvelopeGenerator.Domain;
@using static EnvelopeGenerator.Domain.Constants;
@{
ViewData["Title"] = "Debug";
}