Add REST action handling in InvokeRecActionCommand

Refactor `using` directives in `InvokeRecActionCommand.cs` to include `DigitalData.Core.Exceptions` and `System.Net.Http`.

Implement logic in `InvokeRecActionCommandHandler` to handle different REST actions using `HttpClient`. Introduce a `switch` statement to process "GET", "POST", "PUT", and "DELETE" actions, with a `BadRequestException` for unsupported types. Read HTTP response content asynchronously.
This commit is contained in:
Developer 02 2025-11-26 17:23:14 +01:00
parent dcd399a92e
commit 9a0a37471e

View File

@ -1,5 +1,7 @@
using MediatR;
using DigitalData.Core.Exceptions;
using MediatR;
using ReC.Application.RecActions.Queries;
using System.Net.Http;
namespace ReC.Application.RecActions.Commands;
@ -18,5 +20,31 @@ public class InvokeRecActionCommandHandler(ISender sender) : IRequestHandler<Inv
public async Task Handle(InvokeRecActionCommand request, CancellationToken cancel)
{
var actions = await sender.Send(request as ReadRecActionQuery, cancel);
foreach (var action in actions)
{
using var http = new HttpClient();
using var response = await http.GetAsync("https://example.com", cancel);
switch (action.RestType)
{
case "GET":
// Handle GET
break;
case "POST":
// Handle POST
break;
case "PUT":
// Handle PUT
break;
case "DELETE":
// Handle DELETE
break;
default:
throw new BadRequestException($"The REST type {action.RestType} is not supported.");
}
var content = await response.Content.ReadAsStringAsync(cancel);
}
}
}