diff --git a/src/Leanetec.EConnect.Client/Alive/MediatRExtensions.cs b/src/Leanetec.EConnect.Client/Alive/MediatRExtensions.cs index 42d754e..a412b7f 100644 --- a/src/Leanetec.EConnect.Client/Alive/MediatRExtensions.cs +++ b/src/Leanetec.EConnect.Client/Alive/MediatRExtensions.cs @@ -10,11 +10,8 @@ public static class MediatRExtensions /// /// Role of logged user /// - public static Task IsAliveAsync(this IMediator mediator, Role? role = null, int? apiVersion = null) + public static Task 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 + }); } \ No newline at end of file diff --git a/src/Leanetec.EConnect.Client/Articles/GetRequest.cs b/src/Leanetec.EConnect.Client/Articles/GetRequest.cs new file mode 100644 index 0000000..05f421e --- /dev/null +++ b/src/Leanetec.EConnect.Client/Articles/GetRequest.cs @@ -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>, IRequest> +{ +} + +public class GetRequestHandler : IRequestHandler> +{ + public Task> Handle(GetRequest request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/src/Leanetec.EConnect.Client/Articles/MediatRExtensions.cs b/src/Leanetec.EConnect.Client/Articles/MediatRExtensions.cs new file mode 100644 index 0000000..fb48a47 --- /dev/null +++ b/src/Leanetec.EConnect.Client/Articles/MediatRExtensions.cs @@ -0,0 +1,42 @@ +using Leanetec.EConnect.Domain.Entities; +using MediatR; + +namespace Leanetec.EConnect.Client.Articles; + +/// +/// Extension methods for the interface to simplify working with entities. +/// +public static class MediatRExtensions +{ + #region GetRequest + + /// + /// Retrieves a single by its unique identifier. + /// + /// The instance used to send the request. + /// The unique identifier of the article to retrieve. + /// Optional API version to target the request. + /// + /// A task that represents the asynchronous operation. The task result contains the matching , or null if not found. + /// + public static async Task GetArticleByIdAsync(this IMediator mediator, int id, int? apiVersion = null) + { + var articles = await mediator.Send(new GetRequest(id) { ApiVersion = apiVersion }); + return articles.FirstOrDefault(); + } + + /// + /// Retrieves all available entities. + /// + /// The instance used to send the request. + /// Optional API version to target the request. + /// + /// A task that represents the asynchronous operation. The task result contains a collection of all available entities. + /// + public static Task> GetAllArticlesAsync(this IMediator mediator, int? apiVersion = null) => mediator.Send(new GetRequest() + { + ApiVersion = apiVersion + }); + + #endregion +} diff --git a/src/Leanetec.EConnect.Client/Leanetec.EConnect.Client.csproj b/src/Leanetec.EConnect.Client/Leanetec.EConnect.Client.csproj index db4c3f8..ee85239 100644 --- a/src/Leanetec.EConnect.Client/Leanetec.EConnect.Client.csproj +++ b/src/Leanetec.EConnect.Client/Leanetec.EConnect.Client.csproj @@ -10,4 +10,8 @@ + + + +