Refactor ReceiverController to use ReadReceiverQuery

Aktualisierte Get- und Delete-Methoden, um ReadReceiverQuery
für die Parameterbehandlung zu verwenden, was die Organisation und Kapselung verbessert.
Service-Aufrufe wurden angepasst, um Eigenschaften des neuen Query-Objekts
anstelle von individuellen Parametern zu verwenden.
This commit is contained in:
Developer 02 2025-04-10 16:40:07 +02:00
parent 02c7040b39
commit ecf0771f9e

View File

@ -2,6 +2,7 @@
using DigitalData.Core.DTO; using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.Contracts.Services; using EnvelopeGenerator.Application.Contracts.Services;
using EnvelopeGenerator.Application.DTOs.Receiver; using EnvelopeGenerator.Application.DTOs.Receiver;
using EnvelopeGenerator.Application.Receivers.Queries.Read;
using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Domain.Entities;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -18,14 +19,14 @@ namespace EnvelopeGenerator.GeneratorAPI.Controllers
} }
[HttpGet] [HttpGet]
public async Task<IActionResult> Get([FromQuery] string? emailAddress = null, [FromQuery] string? signature = null) public async Task<IActionResult> Get([FromQuery] ReadReceiverQuery receiver)
{ {
if (emailAddress is null && signature is null) if (receiver.EmailAddress is null && receiver.Signature is null)
return await base.GetAll(); return await base.GetAll();
try try
{ {
return await _service.ReadByAsync(emailAddress: emailAddress, signature: signature).ThenAsync( return await _service.ReadByAsync(emailAddress: receiver.EmailAddress, signature: receiver.Signature).ThenAsync(
Success: Ok, Success: Ok,
Fail: IActionResult (msg, ntc) => Fail: IActionResult (msg, ntc) =>
{ {
@ -50,15 +51,15 @@ namespace EnvelopeGenerator.GeneratorAPI.Controllers
} }
[HttpDelete] [HttpDelete]
public async Task<IActionResult> Delete([FromQuery] int? id = null, [FromQuery]string? emailAddress = null, [FromQuery] string? signature = null) public async Task<IActionResult> Delete([FromQuery] ReadReceiverQuery receiver)
{ {
if(id is int id_int) if(receiver.Id is int id_int)
return await base.Delete(id_int); return await base.Delete(id_int);
try try
{ {
if (emailAddress is not null || signature is not null) if (receiver.EmailAddress is not null || receiver.Signature is not null)
return await _service.DeleteByAsync(emailAddress: emailAddress, signature: signature).ThenAsync( return await _service.DeleteByAsync(emailAddress: receiver.EmailAddress, signature: receiver.Signature).ThenAsync(
Success: Ok, Success: Ok,
Fail: IActionResult (msg, ntc) => Fail: IActionResult (msg, ntc) =>
{ {