From 79bb454fd17f458c4bc48aeca6c8e8296eaa00a3 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Mon, 17 Jun 2024 11:19:35 +0200 Subject: [PATCH] =?UTF-8?q?Die=20grundlegende=20ReadByUsernameAsync-Method?= =?UTF-8?q?e=20wurde=20sowohl=20dem=20Repository=20als=20auch=20dem=20Serv?= =?UTF-8?q?ice,=20einschlie=C3=9Flich=20Envelope=20und=20Receiver,=20hinzu?= =?UTF-8?q?gef=C3=BCgt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Contracts/IEnvelopeReceiverService.cs | 2 ++ .../Services/EnvelopeReceiverService.cs | 9 ++++++- .../Contracts/IEnvelopeReceiverRepository.cs | 2 ++ .../Repositories/EnvlopeReceiverRepository.cs | 27 ++++++++++++------- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/EnvelopeGenerator.Application/Contracts/IEnvelopeReceiverService.cs b/EnvelopeGenerator.Application/Contracts/IEnvelopeReceiverService.cs index dfd5d5af..be0b07f1 100644 --- a/EnvelopeGenerator.Application/Contracts/IEnvelopeReceiverService.cs +++ b/EnvelopeGenerator.Application/Contracts/IEnvelopeReceiverService.cs @@ -24,5 +24,7 @@ namespace EnvelopeGenerator.Application.Contracts Task> VerifyAccessCodeAsync(string envelopeReceiverId, string accessCode); Task> IsExisting(string envelopeReceiverId); + + Task>> ReadByUsernameAsync(string username); } } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Services/EnvelopeReceiverService.cs b/EnvelopeGenerator.Application/Services/EnvelopeReceiverService.cs index 1086def5..e008631a 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeReceiverService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeReceiverService.cs @@ -115,5 +115,12 @@ namespace EnvelopeGenerator.Application.Services Result.Fail().Notice(LogLevel.Error, Flag.DataIntegrityIssue, $"Access code is null. Envelope ID is {envelopeId} and receiver ID {receiverId}") : Result.Success(code); } - } + + public async Task>> ReadByUsernameAsync(string username) + { + var er_list = await _repository.ReadByUsernameAsync(username: username); + var dto_list = _mapper.MapOrThrow>(er_list); + return Result.Success(dto_list); + } + } } \ No newline at end of file diff --git a/EnvelopeGenerator.Infrastructure/Contracts/IEnvelopeReceiverRepository.cs b/EnvelopeGenerator.Infrastructure/Contracts/IEnvelopeReceiverRepository.cs index 019cf56c..4fe78b62 100644 --- a/EnvelopeGenerator.Infrastructure/Contracts/IEnvelopeReceiverRepository.cs +++ b/EnvelopeGenerator.Infrastructure/Contracts/IEnvelopeReceiverRepository.cs @@ -18,5 +18,7 @@ namespace EnvelopeGenerator.Infrastructure.Contracts Task ReadByIdAsync(int envelopeId, int receiverId); Task ReadAccessCodeByIdAsync(int envelopeId, int receiverId); + + Task> ReadByUsernameAsync(string username); } } \ No newline at end of file diff --git a/EnvelopeGenerator.Infrastructure/Repositories/EnvlopeReceiverRepository.cs b/EnvelopeGenerator.Infrastructure/Repositories/EnvlopeReceiverRepository.cs index 823c4ea2..265f1963 100644 --- a/EnvelopeGenerator.Infrastructure/Repositories/EnvlopeReceiverRepository.cs +++ b/EnvelopeGenerator.Infrastructure/Repositories/EnvlopeReceiverRepository.cs @@ -14,9 +14,9 @@ namespace EnvelopeGenerator.Infrastructure.Repositories private IQueryable 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> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false) => await ReadWhere(uuid: uuid, withEnvelope: withEnvelope, withReceiver: withReceiver).ToListAsync(); - public async Task> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true) + public async Task> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true) => await ReadWhere(signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver).ToListAsync(); - public async Task ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true) + public async Task 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 ReadAccessCodeAsync(string uuid, string signature) - => await ReadWhere(uuid:uuid, signature:signature) + public async Task ReadAccessCodeAsync(string uuid, string signature) + => await ReadWhere(uuid: uuid, signature: signature) .Select(er => er.AccessCode) .FirstOrDefaultAsync(); public async Task CountAsync(string uuid, string signature) => await ReadWhere(uuid: uuid, signature: signature).CountAsync(); - public IQueryable ReadById(int envelopeId, int receiverId) => _dbSet + public IQueryable ReadById(int envelopeId, int receiverId) => _dbSet .Where(er => er.EnvelopeId == envelopeId && er.ReceiverId == receiverId); - public async Task ReadByIdAsync(int envelopeId, int receiverId) + public async Task ReadByIdAsync(int envelopeId, int receiverId) => await ReadById(envelopeId: envelopeId, receiverId: receiverId) .FirstOrDefaultAsync(); public async Task ReadAccessCodeByIdAsync(int envelopeId, int receiverId) => await ReadById(envelopeId: envelopeId, receiverId: receiverId) .Select(er => er.AccessCode) - .FirstOrDefaultAsync(); - } + .FirstOrDefaultAsync(); + + public async Task> ReadByUsernameAsync(string username) => await _dbSet + .AsNoTracking() + .Where(er => er.Envelope!.User!.Username == username) + .Include(er => er.Envelope) + .Include(er => er.Receiver) + .ToListAsync(); + } } \ No newline at end of file