Compare commits

...

7 Commits

Author SHA1 Message Date
5d316e43b9 Bump version to 2.0.1-beta in ReC.API.csproj
Updated <Version>, <AssemblyVersion>, <FileVersion>, and <InformationalVersion> fields in the project file from 2.0.0-beta to 2.0.1-beta to reflect a new pre-release build. No other changes were made.
2026-03-03 08:19:31 +01:00
0c8d7f6b3c Add 'Last' option to ReadResultViewQuery for latest result
Added a Last property to ReadResultViewQuery to allow fetching only the most recent ResultView entity. Updated the handler logic to return either the last result or all results based on this property.
2026-03-02 16:17:21 +01:00
0e7870b556 Refactor: remove HttpExtensions and inline HTTP method mapping
Removed HttpExtensions.cs and its extension methods for RestType-to-HttpMethod conversion. Introduced a private static CreateHttpRequestMessage method in InvokeRecActionViewCommandHandler to handle HTTP method mapping and request creation directly, reducing indirection and simplifying dependencies.
2026-03-02 14:31:38 +01:00
ec119a3045 Add options to include Action/Profile in ResultView queries
Added IncludeAction and IncludeProfile properties to ReadResultViewQuery, allowing callers to control eager loading of related Action and Profile entities. Updated handler to conditionally include these navigation properties based on the new flags for more flexible data retrieval.
2026-03-02 13:57:14 +01:00
776813d05d Simplify StringContent assignment in HTTP request
Refactored code to assign StringContent directly to httpReq.Content without a using block. Disposal of StringContent is now handled by HttpRequestMessage, improving code clarity and resource management.
2026-03-02 13:40:43 +01:00
0a3761921d Refactor RecActionView command invocation, remove extension
Removed the ToInvokeCommand extension method and now construct InvokeRecActionViewCommand instances directly in the batch handler. Also added an unused using directive in InvokeBatchRecActionViewsCommand.cs.
2026-03-02 13:11:50 +01:00
23246d4ebf Remove Invoked filter from ReadRecActionViewQuery
Previously, only uninvoked actions were fetched by applying Invoked = false in ReadRecActionViewQuery. Now, the filter is removed to retrieve all actions for the given ProfileId, regardless of their Invoked status.
2026-03-02 10:44:04 +01:00
5 changed files with 43 additions and 49 deletions

View File

@@ -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>

View File

@@ -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);
}

View File

@@ -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)
{

View File

@@ -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);
}
}

View File

@@ -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: {