Skip to content

Commit

Permalink
#DLF-156 - Filtrer les produits du searchProducts via le producerId d…
Browse files Browse the repository at this point in the history
…e l'url
  • Loading branch information
noelmugnier committed Dec 20, 2020
1 parent ce59917 commit c2b7950
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Sheaft.Application.Mappers/ProducerProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public ProducerProfile()
.ForMember(d => d.Address, opt => opt.MapFrom(r => r.Address))
.ForMember(d => d.Tags, opt => opt.MapFrom(r => r.Tags.Select(t => t.Tag)));

CreateMap<Producer, ProducerSummaryDto>()
.ForMember(d => d.Address, opt => opt.MapFrom(r => r.Address));

CreateMap<RegisterProducerInput, RegisterProducerCommand>();
CreateMap<UpdateProducerInput, UpdateProducerCommand>();
}
Expand Down
17 changes: 17 additions & 0 deletions Sheaft.Application.Models/Dto/ProducerSummaryDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Sheaft.Domain.Enums;
using System;
using System.Collections.Generic;

namespace Sheaft.Application.Models
{
public class ProducerSummaryDto
{
public Guid Id { get; set; }
public string Name { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Picture { get; set; }
public string Description { get; set; }
public AddressDto Address { get; set; }
}
}
4 changes: 2 additions & 2 deletions Sheaft.Application.Queries/BusinessQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ public IQueryable<BusinessProfileDto> GetMyProfile(RequestUser currentUser)
.ProjectTo<BusinessProfileDto>(_configurationProvider);
}

public IQueryable<ProducerDto> GetProducer(Guid id, RequestUser currentUser)
public IQueryable<T> GetProducer<T>(Guid id, RequestUser currentUser)
{
return _context.Users.OfType<Producer>()
.Get(c => c.Id == id)
.ProjectTo<ProducerDto>(_configurationProvider);
.ProjectTo<T>(_configurationProvider);
}

public IQueryable<StoreDto> GetStore(Guid id, RequestUser currentUser)
Expand Down
2 changes: 1 addition & 1 deletion Sheaft.Application.Queries/Interop/IBusinessQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Sheaft.Application.Queries
{
public interface IBusinessQueries
{
IQueryable<ProducerDto> GetProducer(Guid id, RequestUser currentUser);
IQueryable<T> GetProducer<T>(Guid id, RequestUser currentUser);
IQueryable<StoreDto> GetStore(Guid id, RequestUser currentUser);
IQueryable<BusinessProfileDto> GetMyProfile(RequestUser currentUser);
Task<SirenBusinessDto> RetrieveSiretInfosAsync(string siret, RequestUser currentUser, CancellationToken token);
Expand Down
4 changes: 2 additions & 2 deletions Sheaft.Application.Queries/ProductQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task<ProductsSearchDto> SearchAsync(SearchProductsInput terms, Requ
"product_id", "product_name", "product_onSalePricePerUnit", "product_onSalePrice", "product_rating", "product_ratings_count", "product_image", "product_tags", "producer_id", "producer_name", "producer_email", "producer_phone", "producer_zipcode", "producer_city", "producer_longitude", "producer_latitude", "product_returnable", "product_unit", "product_quantityPerUnit", "product_conditioning", "product_available"
},
IncludeTotalResultCount = true,
HighlightFields = new List<string>() { "product_name" },
HighlightFields = new List<string>(),
HighlightPreTag = "<b>",
HighlightPostTag = "</b>"
};
Expand All @@ -63,7 +63,7 @@ public async Task<ProductsSearchDto> SearchAsync(SearchProductsInput terms, Requ

var filter = "removed eq 0 and product_searchable eq true";
if (terms.ProducerId.HasValue)
filter += $" and producer_id eq '{terms.ProducerId.Value:N}'";
filter += $" and producer_id eq '{terms.ProducerId.Value.ToString("D").ToLowerInvariant()}'";
if (terms.Tags != null)
{
foreach (var tag in terms.Tags)
Expand Down
4 changes: 2 additions & 2 deletions Sheaft.GraphQL.Services/SheaftMutation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,14 @@ public async Task<IQueryable<ProducerDto>> RegisterProducerAsync(RegisterProduce
{
SetLogTransaction("GraphQL", nameof(RegisterProducerAsync));
var result = await ExecuteCommandAsync<RegisterProducerCommand, Guid>(_mapper.Map(input, new RegisterProducerCommand(CurrentUser)), Token);
return businessQueries.GetProducer(result, CurrentUser);
return businessQueries.GetProducer<ProducerDto>(result, CurrentUser);
}

public async Task<IQueryable<ProducerDto>> UpdateProducerAsync(UpdateProducerInput input, [Service] IBusinessQueries businessQueries)
{
SetLogTransaction("GraphQL", nameof(UpdateProducerAsync));
await ExecuteCommandAsync<UpdateProducerCommand, bool>(_mapper.Map(input, new UpdateProducerCommand(CurrentUser)), Token);
return businessQueries.GetProducer(input.Id, CurrentUser);
return businessQueries.GetProducer<ProducerDto>(input.Id, CurrentUser);
}

public async Task<IQueryable<BusinessLegalDto>> CreateBusinessLegalsAsync(CreateBusinessLegalInput input, [Service] ILegalQueries legalQueries)
Expand Down
4 changes: 2 additions & 2 deletions Sheaft.GraphQL.Services/SheaftQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ public IQueryable<ProductDto> GetStoreProducts([Service] IProductQueries product
return productQueries.GetStoreProducts(CurrentUser.Id, CurrentUser);
}

public IQueryable<ProducerDto> GetProducer(Guid input, [Service] IBusinessQueries businessQueries)
public IQueryable<T> GetProducer<T>(Guid input, [Service] IBusinessQueries businessQueries)
{
SetLogTransaction("GraphQL", nameof(GetProducer), input);
return businessQueries.GetProducer(input, CurrentUser);
return businessQueries.GetProducer<T>(input, CurrentUser);
}

public IQueryable<ConsumerDto> GetConsumer(Guid input, [Service] IConsumerQueries consumerQueries)
Expand Down
23 changes: 23 additions & 0 deletions Sheaft.GraphQL.Types/Outputs/ProducerSummaryType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using HotChocolate.Types;
using Sheaft.Application.Models;
using Sheaft.GraphQL.Filters;

namespace Sheaft.GraphQL.Types
{

public class ProducerSummaryType : SheaftOutputType<ProducerSummaryDto>
{
protected override void Configure(IObjectTypeDescriptor<ProducerSummaryDto> descriptor)
{
descriptor.Field(c => c.Id).Type<NonNullType<IdType>>();
descriptor.Field(c => c.Picture);
descriptor.Field(c => c.Description);
descriptor.Field(c => c.FirstName);
descriptor.Field(c => c.LastName);
descriptor.Field(c => c.Name);

descriptor.Field(c => c.Address)
.Type<NonNullType<AddressType>>();
}
}
}
10 changes: 9 additions & 1 deletion Sheaft.GraphQL.Types/SheaftQueryType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HotChocolate.Types;
using HotChocolate.Types.Relay;
using Sheaft.Application.Models;
using Sheaft.Core.Security;
using Sheaft.GraphQL.Filters;
using Sheaft.GraphQL.Services;
Expand Down Expand Up @@ -226,14 +227,21 @@ protected override void Configure(IObjectTypeDescriptor<SheaftQuery> descriptor)
.UseSelection();

//PRODUCER
descriptor.Field(c => c.GetProducer(default, default))
descriptor.Field(c => c.GetProducer<ProducerDto>(default, default))
.Name("producer")
.Authorize(Policies.OWNER)
.Argument("input", c => c.Type<NonNullType<IdType>>())
.Type<NonNullType<ProducerType>>()
.UseSingleOrDefault()
.UseSelection();

descriptor.Field(c => c.GetProducer<ProducerSummaryDto>(default, default))
.Name("producerSummary")
.Argument("input", c => c.Type<NonNullType<IdType>>())
.Type<NonNullType<ProducerSummaryType>>()
.UseSingleOrDefault()
.UseSelection();

descriptor.Field(c => c.GetProducerProducts(default, default))
.Name("producerProducts")
.Authorize(Policies.STORE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ POST https://sheaft-search.search.windows.net/indexes?api-version=2020-06-30&all
"retrievable": true,
"searchable": false,
"sortable": true,
"analyzer": "standard.lucene",
"analyzer": null,
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
Expand Down Expand Up @@ -116,7 +116,7 @@ POST https://sheaft-search.search.windows.net/indexes?api-version=2020-06-30&all
"name": "producer_id",
"type": "Edm.String",
"facetable": false,
"filterable": false,
"filterable": true,
"key": false,
"retrievable": true,
"searchable": false,
Expand All @@ -136,7 +136,7 @@ POST https://sheaft-search.search.windows.net/indexes?api-version=2020-06-30&all
"retrievable": true,
"searchable": false,
"sortable": true,
"analyzer": "standard.lucene",
"analyzer": null,
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
Expand Down
1 change: 1 addition & 0 deletions Sheaft.Web.Api/Extensions/SchemaBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static ISchemaBuilder RegisterTypes(this ISchemaBuilder services)
services.AddType<UserType>();
services.AddType<StoreType>();
services.AddType<ProducerType>();
services.AddType<ProducerSummaryType>();
services.AddType<DepartmentType>();
services.AddType<RegionType>();
services.AddType<NationalityType>();
Expand Down

0 comments on commit c2b7950

Please sign in to comment.