Skip to content

Commit

Permalink
Merge pull request #900 from DFE-Digital/feat/234320/unified-contentf…
Browse files Browse the repository at this point in the history
…ul-retrieval

feat: unified Contentful retrieval
  • Loading branch information
jack-coggin authored Dec 13, 2024
2 parents 1957b85 + 279ebef commit b8beefd
Show file tree
Hide file tree
Showing 111 changed files with 504 additions and 817 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Dfe.PlanTech.Application.Caching.Interfaces;
using Dfe.PlanTech.Application.Exceptions;
using Dfe.PlanTech.Application.Persistence.Interfaces;
using Dfe.PlanTech.Application.Persistence.Models;
using Dfe.PlanTech.Domain.Content.Models.ContentSupport;
using Dfe.PlanTech.Domain.Content.Queries;
using Dfe.PlanTech.Infrastructure.Application.Models;
using Microsoft.Extensions.Logging;

namespace Dfe.PlanTech.Application.Content.Queries;
public record GetContentSupportPageQuery(
ICmsCache Cache,
IContentRepository Repository,
ILogger<GetContentSupportPageQuery> Logger) : IGetContentSupportPageQuery
{
public async Task<ContentSupportPage?> GetContentSupportPage(string slug, CancellationToken cancellationToken = default)
{
try
{
var pages = await Cache.GetOrCreateAsync($"ContentSupportPage:{slug}", () => Repository.GetEntities<ContentSupportPage>(CreateGetEntityOptions(slug), cancellationToken)) ?? [];

var page = pages.FirstOrDefault();

return page;
}
catch (Exception ex)
{
Logger.LogError(ex, "Error fetching content support page {slug} from Contentful", slug);

Check warning on line 28 in src/Dfe.PlanTech.Application/Content/Queries/GetContentSupportPageQuery.cs

View workflow job for this annotation

GitHub Actions / Build and run unit tests

Use PascalCase for named placeholders. (https://rules.sonarsource.com/csharp/RSPEC-6678)
throw new ContentfulDataUnavailableException($"Could not retrieve content support page with slug {slug}", ex);
}
}

private GetEntitiesOptions CreateGetEntityOptions(string slug) => new(10, [new ContentQueryEquals() { Field = "fields.Slug", Value = slug }]);
}
2 changes: 2 additions & 0 deletions src/Dfe.PlanTech.Application/Helpers/QueryServiceSetup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Reflection;
using Dfe.PlanTech.Application.Content.Queries;
using Dfe.PlanTech.Domain.Content.Interfaces;
using Dfe.PlanTech.Domain.Content.Queries;
using Dfe.PlanTech.Domain.Persistence.Interfaces;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -26,6 +27,7 @@ public static IServiceCollection AddCQRSServices(this IServiceCollection service
}

services.AddScoped<IGetPageQuery, GetPageQuery>();
services.AddScoped<IGetContentSupportPageQuery, GetContentSupportPageQuery>();

return services;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Dfe.PlanTech.Domain.Content.Interfaces;
using Dfe.PlanTech.Domain.Content.Models.ContentSupport;

namespace Dfe.PlanTech.Web.Models.Content;
namespace Dfe.PlanTech.Domain.Content.Interfaces;

public interface IContentSupportPage<TContent> : IContentSupportPage
where TContent : class
Expand All @@ -10,7 +10,7 @@ public interface IContentSupportPage<TContent> : IContentSupportPage

public interface IContentSupportPage : IContentComponent, IHasSlug
{
Heading Heading { get; }
CSHeading Heading { get; }
bool IsSitemap { get; }
bool HasCitation { get; }
bool HasBackToTop { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Dfe.PlanTech.Domain.Content.Models.ContentSupport;

namespace Dfe.PlanTech.Domain.Content.Queries;

/// <summary>
/// Retrieves a page from contentful
/// </summary>
public interface IGetContentSupportPageQuery
{
/// <summary>
/// Fetches content support page from <see chref="IContentRepository"/> by slug
/// </summary>
/// <param name="slug">Slug for the C&S Page</param>
/// <returns>ContentSupportPage matching slug</returns>
Task<ContentSupportPage?> GetContentSupportPage(string slug, CancellationToken cancellationToken = default);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport;

[ExcludeFromCodeCoverage]
public class CSBodyText : Target;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport;

[ExcludeFromCodeCoverage]
public class CSHeading : ContentBase;
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Dfe.PlanTech.Domain.Content.Interfaces;
using Dfe.PlanTech.Domain.Content.Models;

namespace Dfe.PlanTech.Web.Models.Content;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport;

[ExcludeFromCodeCoverage]
public class ContentBase : Contentful.Core.Models.Entry<ContentBase>, IContentComponent, IHasSlug
Expand All @@ -12,4 +11,5 @@ public class ContentBase : Contentful.Core.Models.Entry<ContentBase>, IContentCo
public string? Title { get; set; }
public string? Subtitle { get; set; }
public SystemDetails Sys { get; set; } = null!;
public Data Data { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Diagnostics.CodeAnalysis;
using Contentful.Core.Models;

namespace Dfe.PlanTech.Web.Models.Content;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport;

[ExcludeFromCodeCoverage]
public class ContentItem : ContentItemBase
{
public string Value { get; set; } = null!;
public List<Mark> Marks { get; set; } = [];
public Data Data { get; set; } = null!;

Check warning on line 11 in src/Dfe.PlanTech.Domain/Content/Models/ContentSupport/ContentItem.cs

View workflow job for this annotation

GitHub Actions / Build and run unit tests

'ContentItem.Data' hides inherited member 'ContentItemBase.Data'. Use the new keyword if hiding was intended.
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace Dfe.PlanTech.Web.Models.Content;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport;

[ExcludeFromCodeCoverage]
public class ContentItemBase : ContentBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Diagnostics.CodeAnalysis;
using Dfe.PlanTech.Domain.Content.Interfaces;

namespace Dfe.PlanTech.Web.Models.Content;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport;

[ExcludeFromCodeCoverage]
public class ContentSupportPage : ContentBase, IContentSupportPage<Entry>
public class ContentSupportPage : ContentBase, IContentSupportPage<CSBodyText>
{
public Heading Heading { get; init; } = null!;
public List<Entry> Content { get; init; } = [];
public CSHeading Heading { get; init; } = null!;
public List<CSBodyText> Content { get; init; } = [];
public bool IsSitemap { get; init; }
public bool HasCitation { get; init; }
public bool HasBackToTop { get; init; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace Dfe.PlanTech.Web.Models.Content;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport;

[ExcludeFromCodeCoverage]
public class ContentType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace Dfe.PlanTech.Web.Models.Content;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport;

[ExcludeFromCodeCoverage]
public class Data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Diagnostics.CodeAnalysis;

namespace Dfe.PlanTech.Web.Models.Content;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport;

[ExcludeFromCodeCoverage]
public class Entry : ContentBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace Dfe.PlanTech.Web.Models.Content;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport;

[ExcludeFromCodeCoverage]
public class Fields
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace Dfe.PlanTech.Web.Models.Content;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport;

[ExcludeFromCodeCoverage]
public class FileDetails
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace Dfe.PlanTech.Web.Models.Content;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport;

[ExcludeFromCodeCoverage]
public class Image
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System.Diagnostics.CodeAnalysis;
using Dfe.PlanTech.Domain.Content.Interfaces;

namespace Dfe.PlanTech.Web.Models.Content.Mapped;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped;

[ExcludeFromCodeCoverage]
public class CsContentItem
public class CsContentItem : IContentComponent
{
public string InternalName { get; set; } = null!;
public string Slug { get; set; } = null!;
public string? Title { get; set; } = null;
public string? Subtitle { get; set; } = null;
public bool UseParentHero { get; set; }

public SystemDetails Sys { get; set; } = new SystemDetails();
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Diagnostics.CodeAnalysis;
using Dfe.PlanTech.Domain.Content.Models;
using Dfe.PlanTech.Domain.Content.Interfaces;

namespace Dfe.PlanTech.Web.Models.Content.Mapped;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped;

[ExcludeFromCodeCoverage]
public class CsPage : IContentSupportPage<CsContentItem>
{
public SystemDetails Sys { get; set; } = null!;
public Heading Heading { get; set; } = null!;
public CSHeading Heading { get; set; } = null!;
public string Slug { get; set; } = null!;
public bool IsSitemap { get; set; }
public bool HasCitation { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Dfe.PlanTech.Web.Models.Content.Mapped.Types;
using Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Types;

namespace Dfe.PlanTech.Web.Models.Content.Mapped.Custom;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Custom;

[ExcludeFromCodeCoverage]
public class CustomAccordion : CustomComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Dfe.PlanTech.Web.Models.Content.Mapped.Types;
using Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Types;

namespace Dfe.PlanTech.Web.Models.Content.Mapped.Custom;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Custom;

[ExcludeFromCodeCoverage]
public class CustomAttachment : CustomComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Dfe.PlanTech.Web.Models.Content.Mapped.Types;
using Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Types;

namespace Dfe.PlanTech.Web.Models.Content.Mapped.Custom;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Custom;

[ExcludeFromCodeCoverage]
public class CustomCard : CustomComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Dfe.PlanTech.Web.Models.Content.Mapped.Types;
using Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Types;

namespace Dfe.PlanTech.Web.Models.Content.Mapped.Custom;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Custom;

[ExcludeFromCodeCoverage]
public class CustomComponent : CsContentItem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Dfe.PlanTech.Web.Models.Content.Mapped.Types;
using Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Types;

namespace Dfe.PlanTech.Web.Models.Content.Mapped.Custom;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Custom;

[ExcludeFromCodeCoverage]
public class CustomGridContainer : CustomComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped;
public class PageLink
{
public string? Title { get; set; } = null;
public string? Subtitle { get; set; } = null;
public required string Url { get; set; }
public required bool IsActive { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Dfe.PlanTech.Web.Models.Content.Mapped.Types;
using Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Types;

namespace Dfe.PlanTech.Web.Models.Content.Mapped;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped;

[ExcludeFromCodeCoverage]
public class RichTextContentItem : CsContentItem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Dfe.PlanTech.Web.Models.Content.Mapped.Types;
using Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Types;

namespace Dfe.PlanTech.Web.Models.Content.Mapped.Standard;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Standard;

[ExcludeFromCodeCoverage]
public class CsText : RichTextContentItem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Dfe.PlanTech.Web.Models.Content.Mapped.Types;
using Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Types;

namespace Dfe.PlanTech.Web.Models.Content.Mapped.Standard;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Standard;

[ExcludeFromCodeCoverage]
public class EmbeddedAsset : RichTextContentItem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using Dfe.PlanTech.Web.Models.Content.Mapped.Custom;
using Dfe.PlanTech.Web.Models.Content.Mapped.Types;
using Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Custom;
using Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Types;

namespace Dfe.PlanTech.Web.Models.Content.Mapped.Standard;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Standard;

[ExcludeFromCodeCoverage]
public class EmbeddedEntry : RichTextContentItem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Dfe.PlanTech.Web.Models.Content.Mapped.Types;
using Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Types;

namespace Dfe.PlanTech.Web.Models.Content.Mapped.Standard;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Standard;

[ExcludeFromCodeCoverage]
public class Hyperlink : RichTextContentItem
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Types;

public enum AssetContentType
{
Unknown,
Image,
Video
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Types;

public enum CustomComponentType
{
Undefined,
Accordion,
Attachment,
Card,
GridContainer,
CSAccordion,
csCard,
AccordionSection,
csJumpLinkComponent
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Dfe.PlanTech.Web.Models.Content.Mapped.Types;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport.Mapped.Types;

public enum RichTextNodeType
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Diagnostics.CodeAnalysis;

namespace Dfe.PlanTech.Web.Models.Content;
namespace Dfe.PlanTech.Domain.Content.Models.ContentSupport;

[ExcludeFromCodeCoverage]
public class Sys
{
public string Id { get; set; } = null!;
public ContentType? ContentType { get; set; } = null!;
public DateTime? CreatedAt { get; init; }
public DateTime? UpdatedAt { get; init; }
Expand Down
Loading

0 comments on commit b8beefd

Please sign in to comment.