Skip to content

Commit 4a9eca5

Browse files
feat: Add OrganizationId to SlugInfoQuery
1 parent 3df8e71 commit 4a9eca5

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/VirtoCommerce.Xapi.Core/Queries/SlugInfoQuery.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class SlugInfoQuery : Query<SlugInfoResponse>
2020
#pragma warning restore VC0008
2121
public string StoreId { get; set; }
2222
public string UserId { get; set; }
23+
public string OrganizationId { get; set; }
2324
public string CultureName { get; set; }
2425

2526
public override IEnumerable<QueryArgument> GetArguments()

src/VirtoCommerce.Xapi.Data/Queries/SlugInfoQueryBuilder.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
using System.Threading.Tasks;
2+
using GraphQL;
13
using MediatR;
24
using Microsoft.AspNetCore.Authorization;
35
using VirtoCommerce.Xapi.Core.BaseQueries;
6+
using VirtoCommerce.Xapi.Core.Extensions;
47
using VirtoCommerce.Xapi.Core.Models;
58
using VirtoCommerce.Xapi.Core.Queries;
69
using VirtoCommerce.Xapi.Core.Schemas;
@@ -15,5 +18,12 @@ public SlugInfoQueryBuilder(IMediator mediator, IAuthorizationService authorizat
1518
}
1619

1720
protected override string Name => "slugInfo";
21+
22+
protected override Task BeforeMediatorSend(IResolveFieldContext<object> context, SlugInfoQuery request)
23+
{
24+
request.OrganizationId = context.GetCurrentOrganizationId();
25+
26+
return base.BeforeMediatorSend(context, request);
27+
}
1828
}
1929
}

src/VirtoCommerce.Xapi.Data/Queries/SlugInfoQueryHandler.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class SlugInfoQueryHandler(
2222
: IQueryHandler<SlugInfoQuery, SlugInfoResponse>
2323
{
2424

25-
public async Task<SlugInfoResponse> Handle(SlugInfoQuery request, CancellationToken cancellationToken)
25+
public virtual async Task<SlugInfoResponse> Handle(SlugInfoQuery request, CancellationToken cancellationToken)
2626
{
2727
var result = new SlugInfoResponse();
2828

@@ -56,7 +56,7 @@ public async Task<SlugInfoResponse> Handle(SlugInfoQuery request, CancellationTo
5656
criteria.Slug = lastSegment;
5757
criteria.UserId = request.UserId;
5858

59-
result.EntityInfo = await GetBestMatchingSeoInfo(criteria, store);
59+
result.EntityInfo = await GetBestMatchingSeoInfo(request, criteria, store);
6060

6161
if (result.EntityInfo == null)
6262
{
@@ -72,7 +72,7 @@ public async Task<SlugInfoResponse> Handle(SlugInfoQuery request, CancellationTo
7272
if (brokenLinkResult.Results.Count > 0)
7373
{
7474
var resultItem = brokenLinkResult.Results.FirstOrDefault(x =>
75-
(x.Language == request.CultureName) ||
75+
x.Language == request.CultureName ||
7676
(!request.CultureName.IsNullOrEmpty() && x.Language.IsNullOrEmpty()))
7777
?? brokenLinkResult.Results.FirstOrDefault();
7878

@@ -83,9 +83,10 @@ public async Task<SlugInfoResponse> Handle(SlugInfoQuery request, CancellationTo
8383
return result;
8484
}
8585

86-
protected virtual async Task<SeoInfo> GetBestMatchingSeoInfo(SeoSearchCriteria criteria, Store store)
86+
protected virtual async Task<SeoInfo> GetBestMatchingSeoInfo(SlugInfoQuery request, SeoSearchCriteria criteria, Store store)
8787
{
8888
var itemsToMatch = await seoResolver.FindSeoAsync(criteria);
89+
8990
return itemsToMatch.GetBestMatchingSeoInfo(store, criteria.LanguageCode);
9091
}
9192
}

0 commit comments

Comments
 (0)