Skip to content

Commit

Permalink
New - Ajout d'un endpoint pour lister les producteurs (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmugnier authored Jan 14, 2021
1 parent dc66394 commit 1f234c0
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Sheaft.Application.Queries/BusinessQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ public IQueryable<T> GetProducer<T>(Guid id, RequestUser currentUser)
.ProjectTo<T>(_configurationProvider);
}

public IQueryable<ProducerSummaryDto> GetProducers(RequestUser currentUser)
{
return _context.Users.OfType<Producer>()
.Get()
.ProjectTo<ProducerSummaryDto>(_configurationProvider);
}

public IQueryable<StoreDto> GetStore(Guid id, RequestUser currentUser)
{
return _context.Users.OfType<Store>()
Expand Down
1 change: 1 addition & 0 deletions Sheaft.Application.Queries/Interop/IBusinessQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public interface IBusinessQueries
Task<ProducersSearchDto> SearchProducersAsync(Guid storeId, SearchTermsInput terms, RequestUser currentUser, CancellationToken token);
Task<StoresSearchDto> SearchStoresAsync(Guid producerId, SearchTermsInput terms, RequestUser currentUser, CancellationToken token);
Task<IEnumerable<ProducerSuggestDto>> SuggestProducersAsync(SearchTermsInput terms, RequestUser currentUser, CancellationToken token);
IQueryable<ProducerSummaryDto> GetProducers(RequestUser currentUser);
}
}
15 changes: 15 additions & 0 deletions Sheaft.GraphQL.Filters/ProducerSummaryFilterType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using HotChocolate.Types.Filters;
using Sheaft.Application.Models;

namespace Sheaft.GraphQL.Filters
{
public class ProducerSummaryFilterType : FilterInputType<ProducerSummaryDto>
{
protected override void Configure(IFilterInputTypeDescriptor<ProducerSummaryDto> descriptor)
{
descriptor.BindFieldsExplicitly();
descriptor.Filter(c => c.Id).AllowEquals();
descriptor.Filter(c => c.Name).AllowContains();
}
}
}
2 changes: 1 addition & 1 deletion Sheaft.GraphQL.Filters/ProductFilterType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ protected override void Configure(IFilterInputTypeDescriptor<ProductDto> descrip
descriptor.Filter(c => c.Name).AllowContains();
descriptor.Filter(c => c.Reference).AllowContains();
}
}
}
}
7 changes: 7 additions & 0 deletions Sheaft.GraphQL.Services/SheaftQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ public IQueryable<T> GetProducer<T>(Guid input, [Service] IBusinessQueries busin
return businessQueries.GetProducer<T>(input, CurrentUser);
}

public IQueryable<ProducerSummaryDto> GetProducers([Service] IBusinessQueries businessQueries)
{
SetLogTransaction("GraphQL", nameof(GetProducers));
return businessQueries.GetProducers(CurrentUser);
}


public IQueryable<ConsumerDto> GetConsumer(Guid input, [Service] IConsumerQueries consumerQueries)
{
SetLogTransaction("GraphQL", nameof(GetConsumer), input);
Expand Down
14 changes: 14 additions & 0 deletions Sheaft.GraphQL.Sorts/ProducerSummarySortType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using HotChocolate.Types.Sorting;
using Sheaft.Application.Models;

namespace Sheaft.GraphQL.Sorts
{
public class ProducerSummarySortType : SortInputType<ProducerSummaryDto>
{
protected override void Configure(ISortInputTypeDescriptor<ProducerSummaryDto> descriptor)
{
descriptor.BindFieldsExplicitly();
descriptor.Sortable(c => c.Name);
}
}
}
2 changes: 1 addition & 1 deletion Sheaft.GraphQL.Sorts/ProductQuantitySortType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ protected override void Configure(ISortInputTypeDescriptor<PurchaseOrderProductQ
descriptor.BindFieldsExplicitly();
descriptor.Sortable(c => c.Name);
}
}
}
}
8 changes: 8 additions & 0 deletions Sheaft.GraphQL.Types/SheaftQueryType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ protected override void Configure(IObjectTypeDescriptor<SheaftQuery> descriptor)
.UseSingleOrDefault()
.UseSelection();

descriptor.Field(c => c.GetProducers(default))
.Name("producers")
.Type<NonNullType<ListType<ProducerSummaryType>>>()
.UsePaging<ProducerSummaryType>()
.UseFiltering<ProducerSummaryFilterType>()
.UseSorting<ProducerSummarySortType>()
.UseSelection();

descriptor.Field(c => c.GetProducerProducts(default, default))
.Name("producerProducts")
.Authorize(Policies.STORE)
Expand Down

0 comments on commit 1f234c0

Please sign in to comment.