Refactor controllers for MediatR and cleaner API design

- Switch EnvelopeController and ReceiverController to MediatR for all operations
- Encapsulate UserId in CreateEnvelopeCommand via Authorize() method
- Change CreateEnvelopeCommand binding to [FromBody]
- Add CancellationToken support to EnvelopeReceiverController
- Remove obsolete CRUD logic from ReceiverController; now only supports GET via MediatR
- Clean up unused dependencies and update controller summaries for clarity
This commit is contained in:
2026-01-28 14:14:04 +01:00
parent 114555c843
commit a3afeb175f
4 changed files with 34 additions and 78 deletions

View File

@@ -90,19 +90,18 @@ public class EnvelopeController : ControllerBase
/// <summary>
///
/// </summary>
/// <param name="envelope"></param>
/// <param name="command"></param>
/// <returns></returns>
[NonAction]
[Authorize]
[HttpPost]
public async Task<IActionResult> CreateAsync([FromQuery] CreateEnvelopeCommand envelope)
public async Task<IActionResult> CreateAsync([FromBody] CreateEnvelopeCommand command)
{
envelope.UserId = User.GetId();
var res = await _mediator.Send(envelope);
var res = await _mediator.Send(command.Authorize(User.GetId()));
if (res is null)
{
_logger.LogError("Failed to create envelope. Envelope details: {EnvelopeDetails}", JsonConvert.SerializeObject(envelope));
_logger.LogError("Failed to create envelope. Envelope details: {EnvelopeDetails}", JsonConvert.SerializeObject(command));
return StatusCode(StatusCodes.Status500InternalServerError);
}
else