From a76a079736dfd00423cb13ec41bbe70504a87729 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Tue, 6 May 2025 22:26:26 +0200 Subject: [PATCH] Enhance Get method in ReceiverController Updated the Get method to check for receiver.Id along with EmailAddress and Signature. If Id is provided, it attempts to read by ID and returns NotFound if not found. If Id is not provided, it falls back to reading by EmailAddress and Signature, now also returning NotFound instead of a 500 error for missing receivers. --- .../Controllers/ReceiverController.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/EnvelopeGenerator.GeneratorAPI/Controllers/ReceiverController.cs b/EnvelopeGenerator.GeneratorAPI/Controllers/ReceiverController.cs index 9920b5de..95243234 100644 --- a/EnvelopeGenerator.GeneratorAPI/Controllers/ReceiverController.cs +++ b/EnvelopeGenerator.GeneratorAPI/Controllers/ReceiverController.cs @@ -38,17 +38,24 @@ public class ReceiverController : CRUDControllerBaseWithErrorHandling Get([FromQuery] ReadReceiverQuery receiver) { - if (receiver.EmailAddress is null && receiver.Signature is null) + if (receiver.Id is null && receiver.EmailAddress is null && receiver.Signature is null) return await base.GetAll(); try { + if(receiver.Id is int id) + return await _service.ReadByIdAsync(id).ThenAsync( + Success: Ok, + Fail: IActionResult (msg, ntc) => + { + return NotFound(); + }); + return await _service.ReadByAsync(emailAddress: receiver.EmailAddress, signature: receiver.Signature).ThenAsync( Success: Ok, Fail: IActionResult (msg, ntc) => { - _logger.LogNotice(ntc); - return StatusCode(StatusCodes.Status500InternalServerError); + return NotFound(); }); } catch (Exception ex)