From 231140505ec2144cae98af6ca78bb772b00a2050 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 27 Jun 2025 12:08:30 +0200 Subject: [PATCH] Refactor ReadOnlyController to use MediatR Updated service dependencies to use MediatR, marking several fields and methods as obsolete. Modified import statements to include new namespaces and removed old ones. Adjusted the CreateAsync method to correctly access IDs and updated the RecordAsync call to use the new EnvelopeStatus reference. These changes enhance code maintainability and align with modern architectural patterns. --- .../Controllers/ReadOnlyController.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/EnvelopeGenerator.Web/Controllers/ReadOnlyController.cs b/EnvelopeGenerator.Web/Controllers/ReadOnlyController.cs index fd79de28..c58b24f3 100644 --- a/EnvelopeGenerator.Web/Controllers/ReadOnlyController.cs +++ b/EnvelopeGenerator.Web/Controllers/ReadOnlyController.cs @@ -1,10 +1,10 @@ -using DigitalData.Core.DTO; +using DigitalData.Core.Abstraction.Application.DTO; using EnvelopeGenerator.Application.Contracts.Services; using EnvelopeGenerator.Application.DTOs.EnvelopeReceiverReadOnly; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; -using static EnvelopeGenerator.CommonServices.Constants; +using static EnvelopeGenerator.Domain.Constants; namespace EnvelopeGenerator.Web.Controllers { @@ -14,12 +14,16 @@ namespace EnvelopeGenerator.Web.Controllers { private readonly ILogger _logger; + [Obsolete("Use MediatR")] private readonly IEnvelopeReceiverReadOnlyService _erroService; + [Obsolete("Use MediatR")] private readonly IEnvelopeMailService _mailService; + [Obsolete("Use MediatR")] private readonly IEnvelopeHistoryService _histService; + [Obsolete("Use MediatR")] public ReadOnlyController(ILogger logger, IEnvelopeReceiverReadOnlyService erroService, IEnvelopeMailService mailService, IEnvelopeHistoryService histService) { _logger = logger; @@ -30,6 +34,7 @@ namespace EnvelopeGenerator.Web.Controllers [HttpPost] [Authorize(Roles = ReceiverRole.FullyAuth)] + [Obsolete("Use MediatR")] public async Task CreateAsync([FromBody] EnvelopeReceiverReadOnlyCreateDto createDto) { try @@ -62,7 +67,7 @@ namespace EnvelopeGenerator.Web.Controllers } //read new entity - var read_res = await _erroService.ReadByIdAsync(creation_res.Data); + var read_res = await _erroService.ReadByIdAsync(creation_res.Data.Id); if (read_res.IsFailed) { _logger.LogNotice(creation_res); @@ -76,7 +81,7 @@ namespace EnvelopeGenerator.Web.Controllers { //TODO: implement multi-threading to history process (Task) //TODO: remove casting after change the id type - var hist_res = await _histService.RecordAsync((int)createDto.EnvelopeId, createDto.AddedWho, Common.Constants.EnvelopeStatus.EnvelopeShared); + var hist_res = await _histService.RecordAsync((int)createDto.EnvelopeId, createDto.AddedWho, EnvelopeStatus.EnvelopeShared); if (hist_res.IsFailed) { _logger.LogError("Although the envelope was sent as read-only, the EnvelopeShared hisotry could not be saved. Create DTO:\n{createDto}", JsonConvert.SerializeObject(createDto));