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.
This commit is contained in:
parent
0800e4d13e
commit
2a4255e5a3
@ -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<EnvelopeHistory, l
|
||||
/// <param name="userReference"></param>
|
||||
/// <param name="status"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> CountAsync(int? envelopeId = null, string? userReference = null, int? status = null);
|
||||
Task<int> CountAsync(int? envelopeId = null, string? userReference = null, Constants.EnvelopeStatus? status = null);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@ -27,5 +28,5 @@ public interface IEnvelopeHistoryRepository : ICRUDRepository<EnvelopeHistory, l
|
||||
/// <param name="withSender"></param>
|
||||
/// <param name="withReceiver"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<EnvelopeHistory>> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null, bool withSender = false, bool withReceiver = false);
|
||||
Task<IEnumerable<EnvelopeHistory>> ReadAsync(int? envelopeId = null, string? userReference = null, Constants.EnvelopeStatus? status = null, bool withSender = false, bool withReceiver = false);
|
||||
}
|
||||
@ -20,7 +20,7 @@ public interface IEnvelopeHistoryService : ICRUDService<EnvelopeHistoryCreateDto
|
||||
/// <param name="userReference"></param>
|
||||
/// <param name="status"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> CountAsync(int? envelopeId = null, string? userReference = null, int? status = null);
|
||||
Task<int> CountAsync(int? envelopeId = null, string? userReference = null, EnvelopeStatus? status = null);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@ -56,7 +56,7 @@ public interface IEnvelopeHistoryService : ICRUDService<EnvelopeHistoryCreateDto
|
||||
/// <param name="withSender"></param>
|
||||
/// <param name="withReceiver"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<EnvelopeHistoryDto>> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, int? status = null, bool withSender = false, bool withReceiver = false);
|
||||
Task<IEnumerable<EnvelopeHistoryDto>> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, EnvelopeStatus? status = null, bool withSender = false, bool withReceiver = false);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
||||
@ -34,7 +34,7 @@ public class ReadHistoryQueryHandler : IRequestHandler<ReadHistoryQuery, IEnumer
|
||||
/// <exception cref="NotFoundException"></exception>
|
||||
public async Task<IEnumerable<ReadHistoryResponse>> 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();
|
||||
|
||||
@ -33,7 +33,7 @@ public class EnvelopeHistoryService : CRUDService<IEnvelopeHistoryRepository, En
|
||||
/// <param name="userReference"></param>
|
||||
/// <param name="status"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<int> CountAsync(int? envelopeId = null, string? userReference = null, int? status = null) => await _repository.CountAsync(envelopeId: envelopeId, userReference: userReference, status: status);
|
||||
public async Task<int> CountAsync(int? envelopeId = null, string? userReference = null, EnvelopeStatus? status = null) => await _repository.CountAsync(envelopeId: envelopeId, userReference: userReference, status: status);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@ -45,7 +45,7 @@ public class EnvelopeHistoryService : CRUDService<IEnvelopeHistoryRepository, En
|
||||
public async Task<bool> HasStatus(EnvelopeStatus status, int envelopeId, string userReference) => await _repository.CountAsync(
|
||||
envelopeId: envelopeId,
|
||||
userReference: userReference,
|
||||
status: (int) status) > 0;
|
||||
status: status) > 0;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@ -56,7 +56,7 @@ public class EnvelopeHistoryService : CRUDService<IEnvelopeHistoryRepository, En
|
||||
public async Task<bool> AccessCodeAlreadyRequested(int envelopeId, string userReference) => await _repository.CountAsync(
|
||||
envelopeId: envelopeId,
|
||||
userReference:userReference,
|
||||
status: (int) EnvelopeStatus.AccessCodeRequested) > 0;
|
||||
status: EnvelopeStatus.AccessCodeRequested) > 0;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@ -67,7 +67,7 @@ public class EnvelopeHistoryService : CRUDService<IEnvelopeHistoryRepository, En
|
||||
public async Task<bool> IsSigned(int envelopeId, string userReference) => await _repository.CountAsync(
|
||||
envelopeId: envelopeId,
|
||||
userReference: userReference,
|
||||
status: (int) EnvelopeStatus.DocumentSigned) > 0;
|
||||
status: EnvelopeStatus.DocumentSigned) > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the specified envelope has been rejected.
|
||||
@ -81,7 +81,7 @@ public class EnvelopeHistoryService : CRUDService<IEnvelopeHistoryRepository, En
|
||||
return await _repository.CountAsync(
|
||||
envelopeId: envelopeId,
|
||||
userReference: userReference,
|
||||
status: (int)EnvelopeStatus.DocumentRejected) > 0;
|
||||
status: EnvelopeStatus.DocumentRejected) > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -94,7 +94,7 @@ public class EnvelopeHistoryService : CRUDService<IEnvelopeHistoryRepository, En
|
||||
/// <param name="withSender"></param>
|
||||
/// <param name="withReceiver"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<EnvelopeHistoryDto>> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, int? status = null, bool withSender = false, bool withReceiver = false)
|
||||
public async Task<IEnumerable<EnvelopeHistoryDto>> ReadAsync(int? envelopeId = null, string? userReference = null, ReferenceType? referenceType = null, EnvelopeStatus? status = null, bool withSender = false, bool withReceiver = false)
|
||||
{
|
||||
var histDTOs = _mapper.Map<IEnumerable<EnvelopeHistoryDto>>(
|
||||
await _repository.ReadAsync(
|
||||
@ -113,7 +113,7 @@ public class EnvelopeHistoryService : CRUDService<IEnvelopeHistoryRepository, En
|
||||
/// <param name="userReference"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<EnvelopeHistoryDto>> 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
|
||||
/// <summary>
|
||||
|
||||
@ -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<EnvelopeHistory, long, EGDbContext>, IEnvelopeHistoryRepository
|
||||
{
|
||||
public EnvelopeHistoryRepository(EGDbContext dbContext) : base(dbContext, dbContext.EnvelopeHistories)
|
||||
{
|
||||
}
|
||||
|
||||
private IQueryable<EnvelopeHistory> By(int? envelopeId = null, string? userReference = null, int? status = null, bool withSender = false, bool withReceiver = false)
|
||||
private IQueryable<EnvelopeHistory> 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<EnvelopeHistory, long, E
|
||||
return query;
|
||||
}
|
||||
|
||||
public async Task<int> CountAsync(int? envelopeId = null, string? userReference = null, int? status = null) => await By(
|
||||
public async Task<int> CountAsync(int? envelopeId = null, string? userReference = null, Constants.EnvelopeStatus? status = null) => await By(
|
||||
envelopeId: envelopeId,
|
||||
userReference: userReference,
|
||||
status: status).CountAsync();
|
||||
|
||||
public async Task<IEnumerable<EnvelopeHistory>> ReadAsync(int? envelopeId = null, string? userReference = null, int? status = null, bool withSender = false, bool withReceiver = false)
|
||||
public async Task<IEnumerable<EnvelopeHistory>> ReadAsync(int? envelopeId = null, string? userReference = null, Constants.EnvelopeStatus? status = null, bool withSender = false, bool withReceiver = false)
|
||||
=> await By(
|
||||
envelopeId: envelopeId,
|
||||
userReference: userReference,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user