Skip to content

Commit

Permalink
Merge pull request #304 from nikcio/feature/minor-clean-up
Browse files Browse the repository at this point in the history
feat: Minor clean up
  • Loading branch information
nikcio authored Apr 6, 2024
2 parents 6bb9eb1 + f5c6e7c commit 2a0d1f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,39 @@ namespace Examples.Docs.Content.PublicAccessExample;
[GraphQLDescription("Represents an extended content item.")]
public class CustomBasicContent : BasicContent<BasicProperty, BasicContentType, BasicContentRedirect, CustomBasicContent>
{
private readonly IPublicAccessService _publicAccessService;
private readonly IContentService _contentService;
private readonly IUmbracoContextAccessor _context;
private readonly ILogger<CustomBasicContent> _logger;

[GraphQLDescription("Gets the restrict public access settings of the content item.")]
public PermissionsModel? Permissions { get; set; }

public CustomBasicContent(CreateContent createContent, IPropertyFactory<BasicProperty> propertyFactory, IContentTypeFactory<BasicContentType> contentTypeFactory, IContentFactory<CustomBasicContent> contentFactory, IVariationContextAccessor variationContextAccessor, IPublicAccessService publicAccessService, IContentService contentService, IUmbracoContextAccessor context, ILogger<CustomBasicContent> logger) : base(createContent, propertyFactory, contentTypeFactory, contentFactory, variationContextAccessor)
{
ArgumentNullException.ThrowIfNull(createContent);

_publicAccessService = publicAccessService;
_contentService = contentService;
_context = context;
_logger = logger;
ArgumentNullException.ThrowIfNull(logger);
ArgumentNullException.ThrowIfNull(publicAccessService);
ArgumentNullException.ThrowIfNull(contentService);

if (createContent.Content == null)
{
_logger.LogWarning("Content is null");
logger.LogWarning("Content is null");
return;
}

IContent? content = _contentService.GetById(createContent.Content.Id);
IContent? content = contentService.GetById(createContent.Content.Id);

if (content == null)
{
_logger.LogWarning("Content from content service is null. Id: {ContentId}", createContent.Content.Id);
logger.LogWarning("Content from content service is null. Id: {ContentId}", createContent.Content.Id);
return;
}

PublicAccessEntry? entry = _publicAccessService.GetEntryForContent(content);
PublicAccessEntry? entry = publicAccessService.GetEntryForContent(content);

if (entry != null)
{
IUmbracoContext cache = _context.GetRequiredUmbracoContext();
IUmbracoContext cache = context.GetRequiredUmbracoContext();

if (cache.Content == null)
{
_logger.LogWarning("Content cache is null on Umbraco context");
logger.LogWarning("Content cache is null on Umbraco context");
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Nikcio.UHeadless.Content/Queries/ContentAllQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ContentAllQuery<TContent>
return contentRepository.GetContentList(x =>
{
return x?.GetAtRoot(preview, culture).SelectMany(content => content.Descendants(culture))
.Concat(x?.GetAtRoot(preview, culture) ?? Enumerable.Empty<IPublishedContent>());
.Concat(x.GetAtRoot(preview, culture) ?? Enumerable.Empty<IPublishedContent>());
}, culture, segment, fallback?.ToFallback());
}
}
}

0 comments on commit 2a0d1f6

Please sign in to comment.