From 2a4255e5a33369a7cc6de58a70aef4e8184ec913 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 27 Jun 2025 09:17:03 +0200 Subject: [PATCH] Refactor status parameter to use EnvelopeStatus type Updated IEnvelopeHistoryRepository and IEnvelopeHistoryService interfaces to replace int? status with Constants.EnvelopeStatus? status in CountAsync and ReadAsync methods. Adjusted ReadHistoryQueryHandler and EnvelopeHistoryService methods to accommodate the new type. Modified EnvelopeHistoryRepository to accept Constants.EnvelopeStatus? in relevant methods and marked it as obsolete, suggesting a future refactor. --- .../Repositories/IEnvelopeHistoryRepository.cs | 5 +++-- .../Contracts/Services/IEnvelopeHistoryService.cs | 4 ++-- .../Queries/Read/ReadHistoryQueryHandler.cs | 2 +- .../Services/EnvelopeHistoryService.cs | 14 +++++++------- .../Repositories/EnvelopeHistoryRepository.cs | 8 +++++--- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/EnvelopeGenerator.Application/Contracts/Repositories/IEnvelopeHistoryRepository.cs b/EnvelopeGenerator.Application/Contracts/Repositories/IEnvelopeHistoryRepository.cs index f1ed2758..7e8c7b93 100644 --- a/EnvelopeGenerator.Application/Contracts/Repositories/IEnvelopeHistoryRepository.cs +++ b/EnvelopeGenerator.Application/Contracts/Repositories/IEnvelopeHistoryRepository.cs @@ -1,4 +1,5 @@ using DigitalData.Core.Abstraction.Application.Repository; +using EnvelopeGenerator.Domain; using EnvelopeGenerator.Domain.Entities; namespace EnvelopeGenerator.Application.Contracts.Repositories; @@ -16,7 +17,7 @@ public interface IEnvelopeHistoryRepository : ICRUDRepository /// /// - Task CountAsync(int? envelopeId = null, string? userReference = null, int? status = null); + Task CountAsync(int? envelopeId = null, string? userReference = null, Constants.EnvelopeStatus? status = null); /// /// @@ -27,5 +28,5 @@ public interface IEnvelopeHistoryRepository : ICRUDRepository /// /// - Task> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null, bool withSender = false, bool withReceiver = false); + Task> ReadAsync(int? envelopeId = null, string? userReference = null, Constants.EnvelopeStatus? status = null, bool withSender = false, bool withReceiver = false); } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Contracts/Services/IEnvelopeHistoryService.cs b/EnvelopeGenerator.Application/Contracts/Services/IEnvelopeHistoryService.cs index 685ea51b..36fa0f5a 100644 --- a/EnvelopeGenerator.Application/Contracts/Services/IEnvelopeHistoryService.cs +++ b/EnvelopeGenerator.Application/Contracts/Services/IEnvelopeHistoryService.cs @@ -20,7 +20,7 @@ public interface IEnvelopeHistoryService : ICRUDService /// /// - Task CountAsync(int? envelopeId = null, string? userReference = null, int? status = null); + Task CountAsync(int? envelopeId = null, string? userReference = null, EnvelopeStatus? status = null); /// /// @@ -56,7 +56,7 @@ public interface IEnvelopeHistoryService : ICRUDService /// /// - Task> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, int? status = null, bool withSender = false, bool withReceiver = false); + Task> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, EnvelopeStatus? status = null, bool withSender = false, bool withReceiver = false); /// /// diff --git a/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryQueryHandler.cs b/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryQueryHandler.cs index ba267fb5..95c650d5 100644 --- a/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryQueryHandler.cs +++ b/EnvelopeGenerator.Application/Histories/Queries/Read/ReadHistoryQueryHandler.cs @@ -34,7 +34,7 @@ public class ReadHistoryQueryHandler : IRequestHandler public async Task> Handle(ReadHistoryQuery request, CancellationToken cancellationToken) { - var hists = await _repository.ReadAsync(request.EnvelopeId, status: request.Status is null ? null : (int) request.Status); + var hists = await _repository.ReadAsync(request.EnvelopeId, status: request.Status is null ? null : request.Status); if (!hists.Any()) throw new NotFoundException(); diff --git a/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs b/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs index 317c6887..36016337 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs @@ -33,7 +33,7 @@ public class EnvelopeHistoryService : CRUDService /// /// - public async Task CountAsync(int? envelopeId = null, string? userReference = null, int? status = null) => await _repository.CountAsync(envelopeId: envelopeId, userReference: userReference, status: status); + public async Task CountAsync(int? envelopeId = null, string? userReference = null, EnvelopeStatus? status = null) => await _repository.CountAsync(envelopeId: envelopeId, userReference: userReference, status: status); /// /// @@ -45,7 +45,7 @@ public class EnvelopeHistoryService : CRUDService HasStatus(EnvelopeStatus status, int envelopeId, string userReference) => await _repository.CountAsync( envelopeId: envelopeId, userReference: userReference, - status: (int) status) > 0; + status: status) > 0; /// /// @@ -56,7 +56,7 @@ public class EnvelopeHistoryService : CRUDService AccessCodeAlreadyRequested(int envelopeId, string userReference) => await _repository.CountAsync( envelopeId: envelopeId, userReference:userReference, - status: (int) EnvelopeStatus.AccessCodeRequested) > 0; + status: EnvelopeStatus.AccessCodeRequested) > 0; /// /// @@ -67,7 +67,7 @@ public class EnvelopeHistoryService : CRUDService IsSigned(int envelopeId, string userReference) => await _repository.CountAsync( envelopeId: envelopeId, userReference: userReference, - status: (int) EnvelopeStatus.DocumentSigned) > 0; + status: EnvelopeStatus.DocumentSigned) > 0; /// /// Checks if the specified envelope has been rejected. @@ -81,7 +81,7 @@ public class EnvelopeHistoryService : CRUDService 0; + status: EnvelopeStatus.DocumentRejected) > 0; } /// @@ -94,7 +94,7 @@ public class EnvelopeHistoryService : CRUDService /// /// - public async Task> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, int? status = null, bool withSender = false, bool withReceiver = false) + public async Task> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, EnvelopeStatus? status = null, bool withSender = false, bool withReceiver = false) { var histDTOs = _mapper.Map>( await _repository.ReadAsync( @@ -113,7 +113,7 @@ public class EnvelopeHistoryService : CRUDService /// public async Task> ReadRejectedAsync(int envelopeId, string? userReference = null) => - await ReadAsync(envelopeId: envelopeId, userReference: userReference, status: (int)EnvelopeStatus.DocumentRejected, withReceiver:true); + await ReadAsync(envelopeId: envelopeId, userReference: userReference, status: EnvelopeStatus.DocumentRejected, withReceiver:true); //TODO: use IQueryable in repository to incerease the performance /// diff --git a/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeHistoryRepository.cs b/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeHistoryRepository.cs index cfa8313a..71037e3c 100644 --- a/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeHistoryRepository.cs +++ b/EnvelopeGenerator.Infrastructure/Repositories/EnvelopeHistoryRepository.cs @@ -2,16 +2,18 @@ using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Application.Contracts.Repositories; using Microsoft.EntityFrameworkCore; +using EnvelopeGenerator.Domain; namespace EnvelopeGenerator.Infrastructure.Repositories; +[Obsolete("Use Repository")] public class EnvelopeHistoryRepository : CRUDRepository, IEnvelopeHistoryRepository { public EnvelopeHistoryRepository(EGDbContext dbContext) : base(dbContext, dbContext.EnvelopeHistories) { } - private IQueryable By(int? envelopeId = null, string? userReference = null, int? status = null, bool withSender = false, bool withReceiver = false) + private IQueryable By(int? envelopeId = null, string? userReference = null, Constants.EnvelopeStatus? status = null, bool withSender = false, bool withReceiver = false) { var query = _dbSet.AsNoTracking(); @@ -33,12 +35,12 @@ public class EnvelopeHistoryRepository : CRUDRepository CountAsync(int? envelopeId = null, string? userReference = null, int? status = null) => await By( + public async Task CountAsync(int? envelopeId = null, string? userReference = null, Constants.EnvelopeStatus? status = null) => await By( envelopeId: envelopeId, userReference: userReference, status: status).CountAsync(); - public async Task> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null, bool withSender = false, bool withReceiver = false) + public async Task> ReadAsync(int? envelopeId = null, string? userReference = null, Constants.EnvelopeStatus? status = null, bool withSender = false, bool withReceiver = false) => await By( envelopeId: envelopeId, userReference: userReference,