From e0af5b769d3efdecb1575d25b568c536f2b99c53 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Thu, 28 Aug 2025 18:15:47 +0200 Subject: [PATCH] refactor(ReadHistoryQuery): update to use dto and remove response class --- .../Dto/EnvelopeHistory/EnvelopeHistoryDto.cs | 16 +++-- .../Queries/Read/ReadHistoryQuery.cs | 5 +- .../Queries/Read/ReadHistoryQueryHandler.cs | 7 ++- .../Queries/Read/ReadHistoryResponse.cs | 60 ------------------- 4 files changed, 18 insertions(+), 70 deletions(-) delete mode 100644 EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryResponse.cs diff --git a/EnvelopeGenerator.Application/Dto/EnvelopeHistory/EnvelopeHistoryDto.cs b/EnvelopeGenerator.Application/Dto/EnvelopeHistory/EnvelopeHistoryDto.cs index 53bb2488..08da8e34 100644 --- a/EnvelopeGenerator.Application/Dto/EnvelopeHistory/EnvelopeHistoryDto.cs +++ b/EnvelopeGenerator.Application/Dto/EnvelopeHistory/EnvelopeHistoryDto.cs @@ -1,5 +1,6 @@ using DigitalData.UserManager.Application.DTOs.User; using EnvelopeGenerator.Application.Dto.Receiver; +using EnvelopeGenerator.Domain; using static EnvelopeGenerator.Domain.Constants; namespace EnvelopeGenerator.Application.Dto.EnvelopeHistory; @@ -29,6 +30,16 @@ public record EnvelopeHistoryDto /// public int Status { get; set; } + /// + /// Type of reference for this history entry. + /// + public Constants.ReferenceType ReferenceType => Status.ToString().FirstOrDefault() switch + { + '1' => Constants.ReferenceType.Sender, + '2' => Constants.ReferenceType.Receiver, + _ => Constants.ReferenceType.System, + }; + /// /// Human-readable name of the status. /// @@ -54,11 +65,6 @@ public record EnvelopeHistoryDto /// public ReceiverReadDto? Receiver { get; set; } - /// - /// Type of reference for this history entry. - /// - public ReferenceType ReferenceType { get; set; } - /// /// Optional comment related to this history entry. /// diff --git a/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryQuery.cs b/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryQuery.cs index 57dc8f88..8c13cb36 100644 --- a/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryQuery.cs +++ b/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryQuery.cs @@ -1,4 +1,5 @@ -using EnvelopeGenerator.Domain; +using EnvelopeGenerator.Application.Dto.EnvelopeHistory; +using EnvelopeGenerator.Domain; using MediatR; using System.ComponentModel.DataAnnotations; @@ -15,6 +16,6 @@ public record ReadHistoryQuery( [Required] int EnvelopeId, Constants.EnvelopeStatus? Status = null, - bool? OnlyLast = true) : IRequest> + bool? OnlyLast = true) : IRequest> { }; \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryQueryHandler.cs b/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryQueryHandler.cs index cff4c4c7..7f95444f 100644 --- a/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryQueryHandler.cs +++ b/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryQueryHandler.cs @@ -1,6 +1,7 @@ using AutoMapper; using DigitalData.Core.Abstraction.Application.Repository; using DigitalData.Core.Exceptions; +using EnvelopeGenerator.Application.Dto.EnvelopeHistory; using EnvelopeGenerator.Domain.Entities; using MediatR; using Microsoft.EntityFrameworkCore; @@ -10,7 +11,7 @@ namespace EnvelopeGenerator.Application.Histories.Queries.Read; /// /// /// -public class ReadHistoryQueryHandler : IRequestHandler> +public class ReadHistoryQueryHandler : IRequestHandler> { private readonly IRepository _repo; @@ -34,7 +35,7 @@ public class ReadHistoryQueryHandler : IRequestHandler /// /// - public async Task> Handle(ReadHistoryQuery request, CancellationToken cancel = default) + public async Task> Handle(ReadHistoryQuery request, CancellationToken cancel = default) { var query = _repo.ReadOnly().Where(h => h.EnvelopeId == request.EnvelopeId); if (request.Status is not null) @@ -43,7 +44,7 @@ public class ReadHistoryQueryHandler : IRequestHandler>(hists); + return _mapper.Map>(hists); throw new NotFoundException(); } diff --git a/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryResponse.cs b/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryResponse.cs deleted file mode 100644 index 7957839b..00000000 --- a/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryResponse.cs +++ /dev/null @@ -1,60 +0,0 @@ -using EnvelopeGenerator.Domain; - -namespace EnvelopeGenerator.Application.Histories.Queries.Read; - -/// -/// Represents the history of an envelope, including its status, user actions, and references. -/// -public class ReadHistoryResponse -{ - /// - /// Gets or sets the unique identifier of the envelope history record. - /// - public long Id { get; set; } - - /// - /// Gets or sets the identifier of the associated envelope. - /// - public int EnvelopeId { get; set; } - - /// - /// Gets or sets the reference identifier of the user who performed the action. - /// - public required string UserReference { get; set; } - - /// - /// Gets or sets the status code of the envelope. - /// - public int Status { get; set; } - - /// - /// - /// - public Constants.ReferenceType ReferenceType => Status.ToString().FirstOrDefault() switch - { - '1' => Constants.ReferenceType.Sender, - '2' => Constants.ReferenceType.Receiver, - _ => Constants.ReferenceType.System, - }; - - /// - /// Gets or sets the date and time when the record was added. - /// - public DateTime AddedWhen { get; set; } - - /// - /// Gets or sets the date and time when the action occurred. - /// - public DateTime? ActionDate { get; set; } - - /// - /// Gets or sets the optional comment about the envelope history record. - /// - public string? Comment { get; set; } - - /// - public override int GetHashCode() - { - return Id.GetHashCode(); - } -} \ No newline at end of file