Die grundlegende ReadByUsernameAsync-Methode wurde sowohl dem Repository als auch dem Service, einschließlich Envelope und Receiver, hinzugefügt.

This commit is contained in:
Developer 02 2024-06-17 11:19:35 +02:00
parent fc91a451f6
commit 79bb454fd1
4 changed files with 29 additions and 11 deletions

View File

@ -24,5 +24,7 @@ namespace EnvelopeGenerator.Application.Contracts
Task<DataResult<bool>> VerifyAccessCodeAsync(string envelopeReceiverId, string accessCode);
Task<DataResult<bool>> IsExisting(string envelopeReceiverId);
Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadByUsernameAsync(string username);
}
}

View File

@ -115,5 +115,12 @@ namespace EnvelopeGenerator.Application.Services
Result.Fail<string>().Notice(LogLevel.Error, Flag.DataIntegrityIssue, $"Access code is null. Envelope ID is {envelopeId} and receiver ID {receiverId}")
: Result.Success(code);
}
}
public async Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadByUsernameAsync(string username)
{
var er_list = await _repository.ReadByUsernameAsync(username: username);
var dto_list = _mapper.MapOrThrow<IEnumerable<EnvelopeReceiverDto>>(er_list);
return Result.Success(dto_list);
}
}
}

View File

@ -18,5 +18,7 @@ namespace EnvelopeGenerator.Infrastructure.Contracts
Task<EnvelopeReceiver?> ReadByIdAsync(int envelopeId, int receiverId);
Task<string?> ReadAccessCodeByIdAsync(int envelopeId, int receiverId);
Task<IEnumerable<EnvelopeReceiver>> ReadByUsernameAsync(string username);
}
}

View File

@ -14,9 +14,9 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
private IQueryable<EnvelopeReceiver> ReadWhere(string? uuid = null, string? signature = null, bool withEnvelope = false, bool withReceiver = false)
{
var query = _dbSet.AsQueryable();
var query = _dbSet.AsNoTracking();
if(uuid is not null)
if (uuid is not null)
query = query.Where(er => er.Envelope != null && er.Envelope.Uuid == uuid);
if (signature is not null)
@ -36,29 +36,36 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
public async Task<IEnumerable<EnvelopeReceiver>> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false)
=> await ReadWhere(uuid: uuid, withEnvelope: withEnvelope, withReceiver: withReceiver).ToListAsync();
public async Task<IEnumerable<EnvelopeReceiver>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true)
public async Task<IEnumerable<EnvelopeReceiver>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true)
=> await ReadWhere(signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver).ToListAsync();
public async Task<EnvelopeReceiver?> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true)
public async Task<EnvelopeReceiver?> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true)
=> await ReadWhere(uuid: uuid, signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver).FirstOrDefaultAsync();
public async Task<string?> ReadAccessCodeAsync(string uuid, string signature)
=> await ReadWhere(uuid:uuid, signature:signature)
public async Task<string?> ReadAccessCodeAsync(string uuid, string signature)
=> await ReadWhere(uuid: uuid, signature: signature)
.Select(er => er.AccessCode)
.FirstOrDefaultAsync();
public async Task<int> CountAsync(string uuid, string signature) => await ReadWhere(uuid: uuid, signature: signature).CountAsync();
public IQueryable<EnvelopeReceiver> ReadById(int envelopeId, int receiverId) => _dbSet
public IQueryable<EnvelopeReceiver> ReadById(int envelopeId, int receiverId) => _dbSet
.Where(er => er.EnvelopeId == envelopeId && er.ReceiverId == receiverId);
public async Task<EnvelopeReceiver?> ReadByIdAsync(int envelopeId, int receiverId)
public async Task<EnvelopeReceiver?> ReadByIdAsync(int envelopeId, int receiverId)
=> await ReadById(envelopeId: envelopeId, receiverId: receiverId)
.FirstOrDefaultAsync();
public async Task<string?> ReadAccessCodeByIdAsync(int envelopeId, int receiverId)
=> await ReadById(envelopeId: envelopeId, receiverId: receiverId)
.Select(er => er.AccessCode)
.FirstOrDefaultAsync();
}
.FirstOrDefaultAsync();
public async Task<IEnumerable<EnvelopeReceiver>> ReadByUsernameAsync(string username) => await _dbSet
.AsNoTracking()
.Where(er => er.Envelope!.User!.Username == username)
.Include(er => er.Envelope)
.Include(er => er.Receiver)
.ToListAsync();
}
}