Skip to content

Commit

Permalink
Merge pull request #70 from fortedigital/feature/68-fix-nullish-conte…
Browse files Browse the repository at this point in the history
…nt-usage-urls

Fix returning null as content usage url
  • Loading branch information
Fifok authored Aug 14, 2023
2 parents ac80dd4 + 53e1906 commit c9f2cdf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ namespace Forte.Optimizely.ContentUsage.Api.Features.ContentType;

public class ContentTypeUsagesRepository
{
private readonly ServiceAccessor<IAsyncDatabaseExecutor> dataExecutorAccessor;
private readonly ServiceAccessor<IAsyncDatabaseExecutor> _dataExecutorAccessor;

public ContentTypeUsagesRepository(ServiceAccessor<IAsyncDatabaseExecutor> dataExecutorAccessor)
{
this.dataExecutorAccessor = dataExecutorAccessor;
_dataExecutorAccessor = dataExecutorAccessor;
}

public async Task<IEnumerable<ContentTypeUsageCounter>> ListContentTypesUsagesCounters(
CancellationToken cancellationToken)
{
var executor = this.dataExecutorAccessor();
var executor = _dataExecutorAccessor();
return await executor.ExecuteAsync((Func<Task<IEnumerable<ContentTypeUsageCounter>>>)(async () =>
{
var command1 = executor.CreateCommand();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace Forte.Optimizely.ContentUsage.Api.Services;
public class ContentTypeService
{
private readonly IContentTypeRepository _contentTypeRepository;
private readonly ContentTypeUsagesRepository contentTypeUsagesRepository;
private readonly ContentTypeUsagesRepository _contentTypeUsagesRepository;


public ContentTypeService(IContentTypeRepository contentTypeRepository, ContentTypeUsagesRepository contentTypeUsagesRepository)
{
_contentTypeRepository = contentTypeRepository;
this.contentTypeUsagesRepository = contentTypeUsagesRepository;
_contentTypeUsagesRepository = contentTypeUsagesRepository;
}

public IEnumerable<ContentType> GetAll(ContentTypesFilterCriteria? filterCriteria)
Expand All @@ -34,7 +34,7 @@ public IEnumerable<ContentType> GetAll(ContentTypesFilterCriteria? filterCriteri

public async Task<IEnumerable<ContentTypeUsageCounter>> GetAllCounters(CancellationToken cancellationToken)
{
return await contentTypeUsagesRepository.ListContentTypesUsagesCounters(cancellationToken);
return await _contentTypeUsagesRepository.ListContentTypesUsagesCounters(cancellationToken);
}

public ContentType? Get(Guid guid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,28 @@ public ContentUsageService(IUrlResolver urlResolver, IContentSoftLinkRepository
public IEnumerable<string> GetPageUrls(EPiServerContentUsage contentUsage)
{
var contentLink = contentUsage.ContentLink;
var url = _urlResolver.GetUrl(contentLink, contentUsage.LanguageBranch);

var pageUrls = SearchForPageUrls(contentLink, contentUsage.LanguageBranch);

return pageUrls;
}

private IEnumerable<string> SearchForPageUrls(ContentReference contentLink, string languageBranch)
{
var url = _urlResolver.GetUrl(contentLink, languageBranch);

if (!string.IsNullOrEmpty(url))
return CheckIsPublished(contentLink) ? new[] { url } : new string[] { };

var pageLinks = _contentSoftLinkRepository.Load(contentLink, true)
var softLinks = _contentSoftLinkRepository.Load(contentLink, true);
var pageLinks = softLinks
.Where(softLink => softLink.SoftLinkType == ReferenceType.PageLinkReference)
.Select(softLink => softLink.OwnerContentLink)
.Where(ownerContentLink => ownerContentLink != null && CheckIsPublished(ownerContentLink));

return pageLinks.Select(pageLink => _urlResolver.GetUrl(pageLink, contentUsage.LanguageBranch));
var pageUrls = pageLinks.SelectMany(pageLink => SearchForPageUrls(pageLink, languageBranch));

return pageUrls;
}

public string GetEditUrl(EPiServerContentUsage contentUsage)
Expand Down

0 comments on commit c9f2cdf

Please sign in to comment.