Compare commits
7 Commits
27d731a5b0
...
5d316e43b9
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d316e43b9 | |||
| 0c8d7f6b3c | |||
| 0e7870b556 | |||
| ec119a3045 | |||
| 776813d05d | |||
| 0a3761921d | |||
| 23246d4ebf |
@@ -10,10 +10,10 @@
|
||||
<Product>ReC.API</Product>
|
||||
<PackageIcon>Assets\icon.ico</PackageIcon>
|
||||
<PackageTags>digital data rest-caller rec api</PackageTags>
|
||||
<Version>2.0.0-beta</Version>
|
||||
<AssemblyVersion>2.0.0.0</AssemblyVersion>
|
||||
<FileVersion>2.0.0.0</FileVersion>
|
||||
<InformationalVersion>2.0.0-beta</InformationalVersion>
|
||||
<Version>2.0.1-beta</Version>
|
||||
<AssemblyVersion>2.0.1.0</AssemblyVersion>
|
||||
<FileVersion>2.0.1.0</FileVersion>
|
||||
<InformationalVersion>2.0.1-beta</InformationalVersion>
|
||||
<Copyright>Copyright © 2025 Digital Data GmbH. All rights reserved.</Copyright>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
using ReC.Domain.Constants;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace ReC.Application.Common;
|
||||
|
||||
public static class HttpExtensions
|
||||
{
|
||||
private static readonly Dictionary<RestType, HttpMethod> _methods = new()
|
||||
{
|
||||
[RestType.Get] = HttpMethod.Get,
|
||||
[RestType.Post] = HttpMethod.Post,
|
||||
[RestType.Put] = HttpMethod.Put,
|
||||
[RestType.Delete] = HttpMethod.Delete,
|
||||
[RestType.Patch] = HttpMethod.Patch,
|
||||
[RestType.Head] = HttpMethod.Head,
|
||||
[RestType.Options] = HttpMethod.Options,
|
||||
[RestType.Trace] = HttpMethod.Trace,
|
||||
[RestType.Connect] = HttpMethod.Connect
|
||||
};
|
||||
|
||||
public static HttpMethod ToHttpMethod(this RestType method) => !method.IsValid()
|
||||
? throw new ArgumentOutOfRangeException(nameof(method), $"The RestType value '{method}' is not valid.")
|
||||
: _methods.TryGetValue(method, out var httpMethod)
|
||||
? httpMethod
|
||||
: new HttpMethod(method.ToHttpMethodName());
|
||||
|
||||
public static HttpRequestMessage ToHttpRequestMessage(this HttpMethod method, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri)
|
||||
=> new(method, requestUri);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using MediatR;
|
||||
using DigitalData.Core.Abstractions.Interfaces;
|
||||
using MediatR;
|
||||
using ReC.Application.RecActions.Queries;
|
||||
using ReC.Domain.Constants;
|
||||
|
||||
@@ -19,11 +20,11 @@ public class InvokeRecActionViewsCommandHandler(ISender sender) : IRequestHandle
|
||||
{
|
||||
public async Task Handle(InvokeBatchRecActionViewsCommand request, CancellationToken cancel)
|
||||
{
|
||||
var actions = await sender.Send(new ReadRecActionViewQuery() { ProfileId = request.ProfileId, Invoked = false }, cancel);
|
||||
var actions = await sender.Send(new ReadRecActionViewQuery() { ProfileId = request.ProfileId }, cancel);
|
||||
|
||||
foreach (var action in actions)
|
||||
{
|
||||
var ok = await sender.Send(action.ToInvokeCommand(), cancel);
|
||||
var ok = await sender.Send(new InvokeRecActionViewCommand() { Action = action }, cancel);
|
||||
if (!ok)
|
||||
switch (action.ErrorAction)
|
||||
{
|
||||
|
||||
@@ -19,11 +19,6 @@ public record InvokeRecActionViewCommand : IRequest<bool>
|
||||
public RecActionViewDto Action { get; set; } = null!;
|
||||
}
|
||||
|
||||
public static class InvokeRecActionViewCommandExtensions
|
||||
{
|
||||
public static InvokeRecActionViewCommand ToInvokeCommand(this RecActionViewDto dto) => new() { Action = dto };
|
||||
}
|
||||
|
||||
public class InvokeRecActionViewCommandHandler(
|
||||
ISender sender,
|
||||
IHttpClientFactory clientFactory,
|
||||
@@ -43,15 +38,10 @@ public class InvokeRecActionViewCommandHandler(
|
||||
$"Id: {action.Id}"
|
||||
);
|
||||
|
||||
using var httpReq = restType
|
||||
.ToHttpMethod()
|
||||
.ToHttpRequestMessage(action.EndpointUri);
|
||||
using var httpReq = CreateHttpRequestMessage(restType, action.EndpointUri);
|
||||
|
||||
if (action.Body is not null)
|
||||
{
|
||||
using var reqBody = new StringContent(action.Body);
|
||||
httpReq.Content = reqBody;
|
||||
}
|
||||
httpReq.Content = new StringContent(action.Body);
|
||||
|
||||
if (action.Headers is not null)
|
||||
foreach (var header in action.Headers)
|
||||
@@ -144,4 +134,24 @@ public class InvokeRecActionViewCommandHandler(
|
||||
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
private static HttpRequestMessage CreateHttpRequestMessage(RestType restType, string? endpointUri)
|
||||
{
|
||||
var method = restType switch
|
||||
{
|
||||
RestType.Get => HttpMethod.Get,
|
||||
RestType.Post => HttpMethod.Post,
|
||||
RestType.Put => HttpMethod.Put,
|
||||
RestType.Delete => HttpMethod.Delete,
|
||||
RestType.Patch => HttpMethod.Patch,
|
||||
RestType.Head => HttpMethod.Head,
|
||||
RestType.Options => HttpMethod.Options,
|
||||
RestType.Trace => HttpMethod.Trace,
|
||||
RestType.Connect => HttpMethod.Connect,
|
||||
RestType.None => throw new ArgumentOutOfRangeException(nameof(restType), $"The RestType value '{restType}' is not valid."),
|
||||
_ => new HttpMethod(restType.ToString().ToUpperInvariant())
|
||||
};
|
||||
|
||||
return new HttpRequestMessage(method, endpointUri);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,12 @@ public record ReadResultViewQuery : IRequest<IEnumerable<ResultViewDto>>
|
||||
public long? ActionId { get; init; } = null;
|
||||
|
||||
public long? ProfileId { get; init; } = null;
|
||||
|
||||
public bool IncludeAction { get; init; } = true;
|
||||
|
||||
public bool IncludeProfile { get; init; } = false;
|
||||
|
||||
public bool Last { get; init; } = false;
|
||||
}
|
||||
|
||||
public class ReadResultViewQueryHandler(IRepository<ResultView> repo, IMapper mapper) : IRequestHandler<ReadResultViewQuery, IEnumerable<ResultViewDto>>
|
||||
@@ -33,7 +39,13 @@ public class ReadResultViewQueryHandler(IRepository<ResultView> repo, IMapper ma
|
||||
if(request.ProfileId is long profileId)
|
||||
q = q.Where(rv => rv.ProfileId == profileId);
|
||||
|
||||
var entities = await q.ToListAsync(cancel);
|
||||
if(request.IncludeAction)
|
||||
q = q.Include(rv => rv.Action);
|
||||
|
||||
if(request.IncludeProfile)
|
||||
q = q.Include(rv => rv.Profile);
|
||||
|
||||
var entities = request.Last ? [await q.OrderBy(rv => rv.AddedWhen).LastOrDefaultAsync(cancel)] : await q.ToListAsync(cancel);
|
||||
|
||||
if (entities.Count == 0)
|
||||
throw new NotFoundException($"No result views found for the given criteria. Criteria: {
|
||||
|
||||
Reference in New Issue
Block a user