Introduced a new `EndpointAuthId` property in `RecActionController` and `CreateRecActionCommand` to enable handling of endpoint authentication. Updated the `RecActionController` to initialize `EndpointAuthId` with a default value of `1`. Modified the `CreateRecActionCommand` record to include a nullable `EndpointAuthId` property of type `long?`, allowing optional specification of authentication details.
45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using DigitalData.Core.Exceptions;
|
|
using MediatR;
|
|
using ReC.Application.Endpoints.Commands;
|
|
using ReC.Domain.Entities;
|
|
|
|
namespace ReC.Application.RecActions.Commands;
|
|
|
|
public record CreateRecActionCommand : IRequest
|
|
{
|
|
public long ProfileId { get; init; }
|
|
|
|
public bool Active { get; init; } = true;
|
|
|
|
public long? EndpointId { get; set; }
|
|
|
|
public string? EndpointUri { get; init; }
|
|
|
|
public string Type { get; init; } = null!;
|
|
|
|
public string? HeaderQuery { get; init; }
|
|
|
|
public string BodyQuery { get; init; } = null!;
|
|
|
|
public byte Sequence { get; set; } = 1;
|
|
|
|
public long? EndpointAuthId { get; set; }
|
|
}
|
|
|
|
public class CreateRecActionCommandHandler(ISender sender, IRepository<RecAction> repo) : IRequestHandler<CreateRecActionCommand>
|
|
{
|
|
public async Task Handle(CreateRecActionCommand request, CancellationToken cancel)
|
|
{
|
|
if(request.EndpointId is null)
|
|
if(request.EndpointUri is string endpointUri)
|
|
{
|
|
var endpoint = await sender.Send(new ObtainEndpointCommand { Uri = endpointUri }, cancel);
|
|
request.EndpointId = endpoint.Id;
|
|
}
|
|
else
|
|
throw new BadRequestException("Either EndpointId or EndpointUri must be provided.");
|
|
|
|
await repo.CreateAsync(request, cancel);
|
|
}
|
|
} |