feat(Articles.GetRequest): erstellt, um Get-Anfragen zum Lesen von Artikeln mit der mediar-Erweiterung und dem Request-Handler ohne Implementierung zu bearbeiten
This commit is contained in:
parent
4688883f2e
commit
89d0e6a38a
@ -10,11 +10,8 @@ public static class MediatRExtensions
|
||||
/// <param name="mediator"></param>
|
||||
/// <param name="role">Role of logged user</param>
|
||||
/// <returns></returns>
|
||||
public static Task<bool> IsAliveAsync(this IMediator mediator, Role? role = null, int? apiVersion = null)
|
||||
public static Task<bool> IsAliveAsync(this IMediator mediator, Role? role = null, int? apiVersion = null) => mediator.Send(new GetRequest(role)
|
||||
{
|
||||
return mediator.Send(new GetRequest(role)
|
||||
{
|
||||
ApiVersion = apiVersion
|
||||
});
|
||||
}
|
||||
ApiVersion = apiVersion
|
||||
});
|
||||
}
|
||||
17
src/Leanetec.EConnect.Client/Articles/GetRequest.cs
Normal file
17
src/Leanetec.EConnect.Client/Articles/GetRequest.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using Leanetec.EConnect.Client.Models;
|
||||
using Leanetec.EConnect.Domain.Entities;
|
||||
using MediatR;
|
||||
|
||||
namespace Leanetec.EConnect.Client.Articles;
|
||||
|
||||
public record GetRequest(int? ArticleId = null) : Request<IEnumerable<Article>>, IRequest<IEnumerable<Article>>
|
||||
{
|
||||
}
|
||||
|
||||
public class GetRequestHandler : IRequestHandler<GetRequest, IEnumerable<Article>>
|
||||
{
|
||||
public Task<IEnumerable<Article>> Handle(GetRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
42
src/Leanetec.EConnect.Client/Articles/MediatRExtensions.cs
Normal file
42
src/Leanetec.EConnect.Client/Articles/MediatRExtensions.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using Leanetec.EConnect.Domain.Entities;
|
||||
using MediatR;
|
||||
|
||||
namespace Leanetec.EConnect.Client.Articles;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for the <see cref="IMediator"/> interface to simplify working with <see cref="Article"/> entities.
|
||||
/// </summary>
|
||||
public static class MediatRExtensions
|
||||
{
|
||||
#region GetRequest
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a single <see cref="Article"/> by its unique identifier.
|
||||
/// </summary>
|
||||
/// <param name="mediator">The <see cref="IMediator"/> instance used to send the request.</param>
|
||||
/// <param name="id">The unique identifier of the article to retrieve.</param>
|
||||
/// <param name="apiVersion">Optional API version to target the request.</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous operation. The task result contains the matching <see cref="Article"/>, or <c>null</c> if not found.
|
||||
/// </returns>
|
||||
public static async Task<Article?> GetArticleByIdAsync(this IMediator mediator, int id, int? apiVersion = null)
|
||||
{
|
||||
var articles = await mediator.Send(new GetRequest(id) { ApiVersion = apiVersion });
|
||||
return articles.FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all available <see cref="Article"/> entities.
|
||||
/// </summary>
|
||||
/// <param name="mediator">The <see cref="IMediator"/> instance used to send the request.</param>
|
||||
/// <param name="apiVersion">Optional API version to target the request.</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous operation. The task result contains a collection of all available <see cref="Article"/> entities.
|
||||
/// </returns>
|
||||
public static Task<IEnumerable<Article>> GetAllArticlesAsync(this IMediator mediator, int? apiVersion = null) => mediator.Send(new GetRequest()
|
||||
{
|
||||
ApiVersion = apiVersion
|
||||
});
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -10,4 +10,8 @@
|
||||
<PackageReference Include="MediatR" Version="13.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Leanetec.EConnect.Domain\Leanetec.EConnect.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user