-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/VirtoCommerce.CoreModule.Core/Seo/CompositeSeoResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace VirtoCommerce.CoreModule.Core.Seo; | ||
|
||
public class CompositeSeoResolver : ISeoResolver | ||
{ | ||
private readonly IEnumerable<ISeoResolver> _resolvers; | ||
private readonly CompositeSeoBySlugResolver _seoBySlugResolver; | ||
|
||
public CompositeSeoResolver(IEnumerable<ISeoResolver> resolvers, CompositeSeoBySlugResolver seoBySlugResolver) | ||
{ | ||
_resolvers = resolvers; | ||
_seoBySlugResolver = seoBySlugResolver; | ||
} | ||
|
||
public async Task<IList<SeoInfo>> FindSeoAsync(SeoSearchCriteria criteria) | ||
{ | ||
var tasks = _resolvers.Select(x => x.FindSeoAsync(criteria)).ToArray(); | ||
var result = (await Task.WhenAll(tasks)).SelectMany(x => x).Where(x => x.ObjectId != null && x.ObjectType != null).Distinct(); | ||
var fallbackResults = await _seoBySlugResolver.FindSeoBySlugAsync(criteria.Slug); | ||
return result.Union(fallbackResults).ToList(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace VirtoCommerce.CoreModule.Core.Seo; | ||
|
||
public interface ISeoResolver | ||
{ | ||
Task<IList<SeoInfo>> FindSeoAsync(SeoSearchCriteria criteria); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/VirtoCommerce.CoreModule.Core/Seo/SeoSearchCriteria.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using VirtoCommerce.Platform.Core.Common; | ||
|
||
namespace VirtoCommerce.CoreModule.Core.Seo | ||
{ | ||
public class SeoSearchCriteria : SearchCriteriaBase | ||
{ | ||
public string Slug { get; set; } | ||
public string StoreId { get; set; } | ||
public string Permalink { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters