From 1f234c060598651add50cde9ad67c2cd4f68d80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=ABl=20Mugnier?= <46538060+noelmugnier@users.noreply.github.com> Date: Thu, 14 Jan 2021 15:33:06 +0100 Subject: [PATCH] New - Ajout d'un endpoint pour lister les producteurs (#5) --- Sheaft.Application.Queries/BusinessQueries.cs | 7 +++++++ .../Interop/IBusinessQueries.cs | 1 + .../ProducerSummaryFilterType.cs | 15 +++++++++++++++ Sheaft.GraphQL.Filters/ProductFilterType.cs | 2 +- Sheaft.GraphQL.Services/SheaftQuery.cs | 7 +++++++ Sheaft.GraphQL.Sorts/ProducerSummarySortType.cs | 14 ++++++++++++++ Sheaft.GraphQL.Sorts/ProductQuantitySortType.cs | 2 +- Sheaft.GraphQL.Types/SheaftQueryType.cs | 8 ++++++++ 8 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 Sheaft.GraphQL.Filters/ProducerSummaryFilterType.cs create mode 100644 Sheaft.GraphQL.Sorts/ProducerSummarySortType.cs diff --git a/Sheaft.Application.Queries/BusinessQueries.cs b/Sheaft.Application.Queries/BusinessQueries.cs index c2f83decb..c05972119 100644 --- a/Sheaft.Application.Queries/BusinessQueries.cs +++ b/Sheaft.Application.Queries/BusinessQueries.cs @@ -270,6 +270,13 @@ public IQueryable GetProducer(Guid id, RequestUser currentUser) .ProjectTo(_configurationProvider); } + public IQueryable GetProducers(RequestUser currentUser) + { + return _context.Users.OfType() + .Get() + .ProjectTo(_configurationProvider); + } + public IQueryable GetStore(Guid id, RequestUser currentUser) { return _context.Users.OfType() diff --git a/Sheaft.Application.Queries/Interop/IBusinessQueries.cs b/Sheaft.Application.Queries/Interop/IBusinessQueries.cs index 74f3246b2..9e816162d 100644 --- a/Sheaft.Application.Queries/Interop/IBusinessQueries.cs +++ b/Sheaft.Application.Queries/Interop/IBusinessQueries.cs @@ -17,5 +17,6 @@ public interface IBusinessQueries Task SearchProducersAsync(Guid storeId, SearchTermsInput terms, RequestUser currentUser, CancellationToken token); Task SearchStoresAsync(Guid producerId, SearchTermsInput terms, RequestUser currentUser, CancellationToken token); Task> SuggestProducersAsync(SearchTermsInput terms, RequestUser currentUser, CancellationToken token); + IQueryable GetProducers(RequestUser currentUser); } } \ No newline at end of file diff --git a/Sheaft.GraphQL.Filters/ProducerSummaryFilterType.cs b/Sheaft.GraphQL.Filters/ProducerSummaryFilterType.cs new file mode 100644 index 000000000..9b3d79012 --- /dev/null +++ b/Sheaft.GraphQL.Filters/ProducerSummaryFilterType.cs @@ -0,0 +1,15 @@ +using HotChocolate.Types.Filters; +using Sheaft.Application.Models; + +namespace Sheaft.GraphQL.Filters +{ + public class ProducerSummaryFilterType : FilterInputType + { + protected override void Configure(IFilterInputTypeDescriptor descriptor) + { + descriptor.BindFieldsExplicitly(); + descriptor.Filter(c => c.Id).AllowEquals(); + descriptor.Filter(c => c.Name).AllowContains(); + } + } +} diff --git a/Sheaft.GraphQL.Filters/ProductFilterType.cs b/Sheaft.GraphQL.Filters/ProductFilterType.cs index 15ad3d5fe..23297c120 100644 --- a/Sheaft.GraphQL.Filters/ProductFilterType.cs +++ b/Sheaft.GraphQL.Filters/ProductFilterType.cs @@ -13,5 +13,5 @@ protected override void Configure(IFilterInputTypeDescriptor descrip descriptor.Filter(c => c.Name).AllowContains(); descriptor.Filter(c => c.Reference).AllowContains(); } - } + } } diff --git a/Sheaft.GraphQL.Services/SheaftQuery.cs b/Sheaft.GraphQL.Services/SheaftQuery.cs index b7c44780d..a6550c730 100644 --- a/Sheaft.GraphQL.Services/SheaftQuery.cs +++ b/Sheaft.GraphQL.Services/SheaftQuery.cs @@ -146,6 +146,13 @@ public IQueryable GetProducer(Guid input, [Service] IBusinessQueries busin return businessQueries.GetProducer(input, CurrentUser); } + public IQueryable GetProducers([Service] IBusinessQueries businessQueries) + { + SetLogTransaction("GraphQL", nameof(GetProducers)); + return businessQueries.GetProducers(CurrentUser); + } + + public IQueryable GetConsumer(Guid input, [Service] IConsumerQueries consumerQueries) { SetLogTransaction("GraphQL", nameof(GetConsumer), input); diff --git a/Sheaft.GraphQL.Sorts/ProducerSummarySortType.cs b/Sheaft.GraphQL.Sorts/ProducerSummarySortType.cs new file mode 100644 index 000000000..63f0d3af6 --- /dev/null +++ b/Sheaft.GraphQL.Sorts/ProducerSummarySortType.cs @@ -0,0 +1,14 @@ +using HotChocolate.Types.Sorting; +using Sheaft.Application.Models; + +namespace Sheaft.GraphQL.Sorts +{ + public class ProducerSummarySortType : SortInputType + { + protected override void Configure(ISortInputTypeDescriptor descriptor) + { + descriptor.BindFieldsExplicitly(); + descriptor.Sortable(c => c.Name); + } + } +} diff --git a/Sheaft.GraphQL.Sorts/ProductQuantitySortType.cs b/Sheaft.GraphQL.Sorts/ProductQuantitySortType.cs index cea1fa13d..48b6276c2 100644 --- a/Sheaft.GraphQL.Sorts/ProductQuantitySortType.cs +++ b/Sheaft.GraphQL.Sorts/ProductQuantitySortType.cs @@ -10,5 +10,5 @@ protected override void Configure(ISortInputTypeDescriptor c.Name); } - } + } } diff --git a/Sheaft.GraphQL.Types/SheaftQueryType.cs b/Sheaft.GraphQL.Types/SheaftQueryType.cs index e82cb10e9..e62f4e9da 100644 --- a/Sheaft.GraphQL.Types/SheaftQueryType.cs +++ b/Sheaft.GraphQL.Types/SheaftQueryType.cs @@ -242,6 +242,14 @@ protected override void Configure(IObjectTypeDescriptor descriptor) .UseSingleOrDefault() .UseSelection(); + descriptor.Field(c => c.GetProducers(default)) + .Name("producers") + .Type>>() + .UsePaging() + .UseFiltering() + .UseSorting() + .UseSelection(); + descriptor.Field(c => c.GetProducerProducts(default, default)) .Name("producerProducts") .Authorize(Policies.STORE)