Skip to content

Commit

Permalink
VCST-1363: add seo resolver (#226)
Browse files Browse the repository at this point in the history
* add seo resolver

* rename relativeUrl to permalink in SeoSearchCriteria

* change interface

* remove region
  • Loading branch information
basilkot authored Jun 20, 2024
1 parent 64094f0 commit 06c7d86
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/VirtoCommerce.CoreModule.Core/Seo/CompositeSeoResolver.cs
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();
}
}

9 changes: 9 additions & 0 deletions src/VirtoCommerce.CoreModule.Core/Seo/ISeoResolver.cs
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 src/VirtoCommerce.CoreModule.Core/Seo/SeoSearchCriteria.cs
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; }
}
}
1 change: 1 addition & 0 deletions src/VirtoCommerce.CoreModule.Web/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void Initialize(IServiceCollection serviceCollection)
serviceCollection.AddTransient<ITenantUniqueNumberGenerator, SequenceNumberGeneratorService>();

serviceCollection.AddTransient<CompositeSeoBySlugResolver>();
serviceCollection.AddTransient<CompositeSeoResolver>();

// Money rounding
serviceCollection.AddTransient<IMoneyRoundingPolicy, DefaultMoneyRoundingPolicy>();
Expand Down

0 comments on commit 06c7d86

Please sign in to comment.