refactor(ReadHistoryQuery): update to use dto and remove response class
This commit is contained in:
parent
b8c348afb6
commit
e0af5b769d
@ -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
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Type of reference for this history entry.
|
||||
/// </summary>
|
||||
public Constants.ReferenceType ReferenceType => Status.ToString().FirstOrDefault() switch
|
||||
{
|
||||
'1' => Constants.ReferenceType.Sender,
|
||||
'2' => Constants.ReferenceType.Receiver,
|
||||
_ => Constants.ReferenceType.System,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Human-readable name of the status.
|
||||
/// </summary>
|
||||
@ -54,11 +65,6 @@ public record EnvelopeHistoryDto
|
||||
/// </summary>
|
||||
public ReceiverReadDto? Receiver { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Type of reference for this history entry.
|
||||
/// </summary>
|
||||
public ReferenceType ReferenceType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional comment related to this history entry.
|
||||
/// </summary>
|
||||
|
||||
@ -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<IEnumerable<ReadHistoryResponse>>
|
||||
bool? OnlyLast = true) : IRequest<IEnumerable<EnvelopeHistoryDto>>
|
||||
{
|
||||
};
|
||||
@ -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;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class ReadHistoryQueryHandler : IRequestHandler<ReadHistoryQuery, IEnumerable<ReadHistoryResponse>>
|
||||
public class ReadHistoryQueryHandler : IRequestHandler<ReadHistoryQuery, IEnumerable<EnvelopeHistoryDto>>
|
||||
{
|
||||
private readonly IRepository<EnvelopeHistory> _repo;
|
||||
|
||||
@ -34,7 +35,7 @@ public class ReadHistoryQueryHandler : IRequestHandler<ReadHistoryQuery, IEnumer
|
||||
/// <param name="cancel"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotFoundException"></exception>
|
||||
public async Task<IEnumerable<ReadHistoryResponse>> Handle(ReadHistoryQuery request, CancellationToken cancel = default)
|
||||
public async Task<IEnumerable<EnvelopeHistoryDto>> 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<ReadHistoryQuery, IEnumer
|
||||
var hists = await query.ToListAsync(cancel);
|
||||
|
||||
if (hists.Count == 0)
|
||||
return _mapper.Map<IEnumerable<ReadHistoryResponse>>(hists);
|
||||
return _mapper.Map<IEnumerable<EnvelopeHistoryDto>>(hists);
|
||||
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
@ -1,60 +0,0 @@
|
||||
using EnvelopeGenerator.Domain;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Histories.Queries.Read;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the history of an envelope, including its status, user actions, and references.
|
||||
/// </summary>
|
||||
public class ReadHistoryResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the unique identifier of the envelope history record.
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the identifier of the associated envelope.
|
||||
/// </summary>
|
||||
public int EnvelopeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the reference identifier of the user who performed the action.
|
||||
/// </summary>
|
||||
public required string UserReference { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the status code of the envelope.
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Constants.ReferenceType ReferenceType => Status.ToString().FirstOrDefault() switch
|
||||
{
|
||||
'1' => Constants.ReferenceType.Sender,
|
||||
'2' => Constants.ReferenceType.Receiver,
|
||||
_ => Constants.ReferenceType.System,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the record was added.
|
||||
/// </summary>
|
||||
public DateTime AddedWhen { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the action occurred.
|
||||
/// </summary>
|
||||
public DateTime? ActionDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional comment about the envelope history record.
|
||||
/// </summary>
|
||||
public string? Comment { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Id.GetHashCode();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user