From b96c6c10f8beeb4ef069134d514b0e6d184c6d5c Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Wed, 21 Aug 2024 15:05:18 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Filterung=20nach=20emailAddress=20und?= =?UTF-8?q?=20signature=20im=20Receiver-Repository,=20-Service=20und=20-Co?= =?UTF-8?q?ntroller=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `ReadBy`-Methode im Receiver-Repository implementiert, um nach `emailAddress` und `signature` zu filtern. - `ReadByAsync`-Methode im Receiver-Service hinzugefügt, um Receiver-Daten abzurufen und zuzuordnen. - Controller-`Get`-Endpunkt aktualisiert, um optionale `emailAddress` und `signature` Query-Parameter für die Filterung zu unterstützen. - Fehlerbehandlung mit Protokollierung für fehlgeschlagene Service-Operationen im Controller hinzugefügt. --- .../Contracts/IReceiverService.cs | 2 ++ .../Services/ReceiverService.cs | 11 +++++++++ .../Controllers/ReceiverController.cs | 23 +++++++++++++++++++ .../Contracts/IReceiverRepository.cs | 1 + .../Repositories/ReceiverRepository.cs | 17 +++++++++++++- 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/EnvelopeGenerator.Application/Contracts/IReceiverService.cs b/EnvelopeGenerator.Application/Contracts/IReceiverService.cs index bde7b25c..7721d2ab 100644 --- a/EnvelopeGenerator.Application/Contracts/IReceiverService.cs +++ b/EnvelopeGenerator.Application/Contracts/IReceiverService.cs @@ -1,4 +1,5 @@ using DigitalData.Core.Abstractions.Application; +using DigitalData.Core.DTO; using EnvelopeGenerator.Application.DTOs.Receiver; using EnvelopeGenerator.Domain.Entities; @@ -6,5 +7,6 @@ namespace EnvelopeGenerator.Application.Contracts { public interface IReceiverService : ICRUDService { + public Task> ReadByAsync(string? emailAddress = null, string? signature = null); } } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Services/ReceiverService.cs b/EnvelopeGenerator.Application/Services/ReceiverService.cs index 2aa4818e..352a8240 100644 --- a/EnvelopeGenerator.Application/Services/ReceiverService.cs +++ b/EnvelopeGenerator.Application/Services/ReceiverService.cs @@ -6,6 +6,7 @@ using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; using EnvelopeGenerator.Application.Resources; using EnvelopeGenerator.Application.DTOs.Receiver; +using DigitalData.Core.DTO; namespace EnvelopeGenerator.Application.Services { @@ -15,5 +16,15 @@ namespace EnvelopeGenerator.Application.Services : base(repository, mapper) { } + + public async Task> ReadByAsync(string? emailAddress = null, string? signature = null) + { + var rcv = await _repository.ReadByAsync(emailAddress: emailAddress, signature: signature); + + if (rcv is null) + return Result.Fail(); + + return Result.Success(_mapper.MapOrThrow(rcv)); + } } } \ No newline at end of file diff --git a/EnvelopeGenerator.GeneratorAPI/Controllers/ReceiverController.cs b/EnvelopeGenerator.GeneratorAPI/Controllers/ReceiverController.cs index 5656b947..ac19b08b 100644 --- a/EnvelopeGenerator.GeneratorAPI/Controllers/ReceiverController.cs +++ b/EnvelopeGenerator.GeneratorAPI/Controllers/ReceiverController.cs @@ -1,8 +1,10 @@ using DigitalData.Core.API; +using DigitalData.Core.DTO; using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.DTOs.Receiver; using EnvelopeGenerator.Domain.Entities; using Microsoft.AspNetCore.Mvc; +using System.ComponentModel.DataAnnotations.Schema; namespace EnvelopeGenerator.GeneratorAPI.Controllers { @@ -13,5 +15,26 @@ namespace EnvelopeGenerator.GeneratorAPI.Controllers public ReceiverController(ILogger logger, IReceiverService service) : base(logger, service) { } + + [NonAction] + public override Task GetAll() + { + return base.GetAll(); + } + + [HttpGet] + public async Task Get([FromQuery] string? emailAddress = null, [FromQuery] string? signature = null) + { + if (emailAddress is null && signature is null) + return await base.GetAll(); + + return await _service.ReadByAsync(emailAddress: emailAddress, signature: signature).ThenAsync( + Success: Ok, + Fail: IActionResult (msg,ntc) => + { + _logger.LogNotice(ntc); + return StatusCode(StatusCodes.Status500InternalServerError); + }); + } } } \ No newline at end of file diff --git a/EnvelopeGenerator.Infrastructure/Contracts/IReceiverRepository.cs b/EnvelopeGenerator.Infrastructure/Contracts/IReceiverRepository.cs index bde2bd04..83ad4cad 100644 --- a/EnvelopeGenerator.Infrastructure/Contracts/IReceiverRepository.cs +++ b/EnvelopeGenerator.Infrastructure/Contracts/IReceiverRepository.cs @@ -5,5 +5,6 @@ namespace EnvelopeGenerator.Infrastructure.Contracts { public interface IReceiverRepository : ICRUDRepository { + Task ReadByAsync(string? emailAddress = null, string? signature = null); } } \ No newline at end of file diff --git a/EnvelopeGenerator.Infrastructure/Repositories/ReceiverRepository.cs b/EnvelopeGenerator.Infrastructure/Repositories/ReceiverRepository.cs index 8258c76b..53ffb2ba 100644 --- a/EnvelopeGenerator.Infrastructure/Repositories/ReceiverRepository.cs +++ b/EnvelopeGenerator.Infrastructure/Repositories/ReceiverRepository.cs @@ -1,7 +1,7 @@ using DigitalData.Core.Infrastructure; -using DigitalData.UserManager.Infrastructure.Repositories; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; +using Microsoft.EntityFrameworkCore; namespace EnvelopeGenerator.Infrastructure.Repositories { @@ -10,5 +10,20 @@ namespace EnvelopeGenerator.Infrastructure.Repositories public ReceiverRepository(EGDbContext dbContext) : base(dbContext) { } + + protected IQueryable ReadBy(string? emailAddress = null, string? signature = null) + { + IQueryable query = _dbSet.AsNoTracking(); + + if(emailAddress is not null) + query = query.Where(r => r.EmailAddress == emailAddress); + + if(signature is not null) + query = query.Where(r => r.Signature == signature); + + return query; + } + + public async Task ReadByAsync(string? emailAddress = null, string? signature = null) => await ReadBy(emailAddress, signature).FirstOrDefaultAsync(); } } \ No newline at end of file