Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Vertical navigation changes and bug fixes #164

Merged
merged 14 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# sts-knowledgebase
Using Specify part of knowledgebase -DfE help schools to describe the digital technology they want to buy?.
# sts-contentsupport

Web application to surface additional support for STS services

## Requirements

- .Net 8.0 and any supported IDE for DEV running.


## Running locally

- The startup project is [./src/Dfe.ContentSupport.Web](./src/Dfe.ContentSupport.Web)
- Add 'dotNet-user-secret' to .NET secrets found in keyvault s190d01-cands-kv
- Add yourself with some permissions in the keyvault
- s190d01-cands-kv/access_policies
- The secrets should be pulled from the keyvault by using them settings. You may need to add your public IP to the firewall on the keyvault
- s190d01-cands-kv/networking
- Run the application using the http profile
- Go to URL/content/SLUG to test

This file was deleted.

28 changes: 2 additions & 26 deletions src/Dfe.ContentSupport.Web/Controllers/ContentController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics;
using Dfe.ContentSupport.Web.Models.Mapped;
using Dfe.ContentSupport.Web.Services;
using Dfe.ContentSupport.Web.ViewModels;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -13,25 +12,7 @@ public class ContentController(IContentService contentService, ILayoutService la
: Controller
{
public const string ErrorActionName = "error";

public async Task<IActionResult> Home()
{
var defaultModel = new CsPage
{
Heading = new Models.Heading
{
Title = "Department for Education",
Subtitle = "Content and Support"
}
};

ViewBag.pages = await contentService.GetCsPages();

return View(defaultModel);
}




[HttpGet("{slug}/{page?}")]
public async Task<IActionResult> Index(string slug, string page = "", bool isPreview = false, [FromQuery] List<string>? tags = null)
{
Expand Down Expand Up @@ -67,12 +48,7 @@ public async Task<IActionResult> Index(string slug, string page = "", bool isPre
return RedirectToAction(ErrorActionName);
}
}


public IActionResult Privacy()
{
return View();
}


[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
Expand Down
3 changes: 2 additions & 1 deletion src/Dfe.ContentSupport.Web/Dfe.ContentSupport.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
<ItemGroup>
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.1" />
<PackageReference Include="Azure.Identity" Version="1.11.4" />
<PackageReference Include="contentful.aspnetcore" Version="7.5.1" />
<PackageReference Include="contentful.csharp" Version="7.5.1" />
<PackageReference Include="GovUk.Frontend.AspNetCore" Version="1.5.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.0" />
<PackageReference Include="Polly.Extensions.Http" Version="3.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Polly;
using Polly.Extensions.Http;

namespace Dfe.ContentSupport.Web.Extensions;

public static class HttpClientPolicyExtensions
{
public static void AddRetryPolicy(IHttpClientBuilder builder) =>
builder
.SetHandlerLifetime(TimeSpan.FromMinutes(5))
.AddPolicyHandler(GetRetryPolicy());

public static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy() =>
HttpPolicyExtensions.HandleTransientHttpError()
.OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.NotFound)
.WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dfe.ContentSupport.Web.Configuration;
using Dfe.ContentSupport.Web.Http;
using Contentful.Core;
using Contentful.Core.Configuration;
using Dfe.ContentSupport.Web.Configuration;
using Dfe.ContentSupport.Web.Models.Mapped;
using Dfe.ContentSupport.Web.Services;
using Microsoft.Extensions.Options;
Expand All @@ -10,19 +11,16 @@ public static class WebApplicationBuilderExtensions
{
public static void InitCsDependencyInjection(this WebApplicationBuilder app)
{
app.Services.Configure<CsContentfulOptions>(app.Configuration.GetSection("cs:contentful"))
.AddSingleton(sp => sp.GetRequiredService<IOptions<CsContentfulOptions>>().Value);

app.Services.Configure<TrackingOptions>(app.Configuration.GetSection("tracking"))
.AddSingleton(sp => sp.GetRequiredService<IOptions<TrackingOptions>>().Value);

app.Services.Configure<SupportedAssetTypes>(app.Configuration.GetSection("cs:supportedAssetTypes"))
.AddSingleton(sp => sp.GetRequiredService<IOptions<SupportedAssetTypes>>().Value);

app.Services
.AddTransient<ICacheService<List<CsPage>>, CsPagesCacheService>();

app.Services.SetupContentfulClient(app);

app.Services.AddTransient<ICacheService<List<CsPage>>, CsPagesCacheService>();
app.Services.AddTransient<IModelMapper, ModelMapper>();
app.Services.AddTransient<IContentfulService, ContentfulService>();
app.Services.AddTransient<IContentService, ContentService>();
app.Services.AddTransient<ILayoutService, LayoutService>();

Expand All @@ -33,13 +31,27 @@ public static void InitCsDependencyInjection(this WebApplicationBuilder app)
options.ConsentCookieValue = "false";
});


}

public static void SetupContentfulClient(this IServiceCollection services, WebApplicationBuilder app)
{
app.Services.Configure<ContentfulOptions>(app.Configuration.GetSection("cs:contentful"))
.AddSingleton(sp => sp.GetRequiredService<IOptions<ContentfulOptions>>().Value);

services.AddScoped<IContentfulClient, ContentfulClient>();

if (app.Environment.EnvironmentName.Equals("e2e"))
{
app.Services.AddTransient<IHttpContentfulClient, StubHttpContentfulClient>();
services.AddScoped<IContentfulService, StubContentfulService>();
}
else
{
app.Services.AddTransient<IHttpContentfulClient, HttpContentfulClient>();
services.AddScoped<IContentfulService, ContentfulService>();
}



HttpClientPolicyExtensions.AddRetryPolicy(services.AddHttpClient<ContentfulClient>());
}
}
33 changes: 0 additions & 33 deletions src/Dfe.ContentSupport.Web/Http/HttpContentfulClient.cs

This file was deleted.

10 changes: 0 additions & 10 deletions src/Dfe.ContentSupport.Web/Http/IHttpContentfulClient.cs

This file was deleted.

22 changes: 0 additions & 22 deletions src/Dfe.ContentSupport.Web/Http/StubHttpContentfulClient.cs

This file was deleted.

8 changes: 4 additions & 4 deletions src/Dfe.ContentSupport.Web/Models/ContentBase.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Diagnostics.CodeAnalysis;

namespace Dfe.ContentSupport.Web.Models;

[ExcludeFromCodeCoverage]
public class ContentBase : Contentful.Core.Models.Entry<ContentBase>
{
public string InternalName { get; set; } = null!;

public string? Title { get; set; } = null;

public string? Subtitle { get; set; } = null;
public string Slug { get; set; } = null!;
public string? Title { get; set; }
public string? Subtitle { get; set; }
}
1 change: 1 addition & 0 deletions src/Dfe.ContentSupport.Web/Models/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public class Entry : ContentBase
{
public string JumpIdentifier { get; set; } = null!;
public ContentItemBase RichText { get; set; } = null!;
public bool UseParentHero { get; set; }
}
6 changes: 1 addition & 5 deletions src/Dfe.ContentSupport.Web/Models/Heading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@
namespace Dfe.ContentSupport.Web.Models;

[ExcludeFromCodeCoverage]
public class Heading : ContentBase
{
public string Title { get; init; } = null!;
public string Subtitle { get; init; } = null!;
}
public class Heading : ContentBase;
3 changes: 3 additions & 0 deletions src/Dfe.ContentSupport.Web/Models/Mapped/CsContentItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace Dfe.ContentSupport.Web.Models.Mapped;
public class CsContentItem
{
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; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ public CustomAccordion()
public List<CustomAccordion> Accordions { get; set; } = null!;
public RichTextContentItem? Body { get; set; }
public string SummaryLine { get; set; } = null!;
public string Title { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Dfe.ContentSupport.Web.Models.Mapped.Types;
using Dfe.ContentSupport.Web.Models.Mapped.Types;
using System.Diagnostics.CodeAnalysis;

namespace Dfe.ContentSupport.Web.Models.Mapped.Custom;
Expand All @@ -13,7 +13,6 @@ public CustomAttachment()

public string ContentType { get; set; } = null!;
public long Size { get; set; }
public string Title { get; set; } = null!;
public string Uri { get; set; } = null!;
public DateTime? UpdatedAt { get; set; } = null!;
public DateTime? UpdatedAt { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ public CustomCard()
public string ImageAlt { get; set; } = null!;
public string ImageUri { get; set; } = null!;
public string Meta { get; set; } = null!;
public string Title { get; set; } = null!;
public string Uri { get; set; } = null!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ public EmbeddedAsset()
public AssetContentType AssetContentType { get; set; } = AssetContentType.Unknown;

public string Description { get; set; } = null!;
public string Title { get; set; } = null!;
public string Uri { get; set; } = null!;
}
4 changes: 2 additions & 2 deletions src/Dfe.ContentSupport.Web/Models/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ namespace Dfe.ContentSupport.Web.Models;
[ExcludeFromCodeCoverage]
public class Target : Entry
{
public Fields Fields { get; set; } = null!;
public string Title { get; set; } = null!;
public new Fields Fields { get; set; } = null!;
public Asset Asset { get; set; } = null!;
public string SummaryLine { get; set; } = null!;
public string Description { get; set; } = null!;
Expand All @@ -16,4 +15,5 @@ public class Target : Entry
public string Uri { get; set; } = null!;
public Image Image { get; set; } = null!;
public List<Target> Content { get; set; } = [];
public new string Title { get; set; } = null!;
}
4 changes: 0 additions & 4 deletions src/Dfe.ContentSupport.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using Azure.Identity;
using Contentful.AspNetCore;
using Dfe.ContentSupport.Web.Extensions;
using GovUk.Frontend.AspNetCore;


namespace Dfe.ContentSupport.Web;

[ExcludeFromCodeCoverage]
Expand All @@ -24,7 +22,6 @@ public static void Main(string[] args)
builder.Services.AddHealthChecks();

builder.Services.AddGovUkFrontend();
builder.Services.AddContentful(builder.Configuration);
builder.InitCsDependencyInjection();

var app = builder.Build();
Expand All @@ -34,7 +31,6 @@ public static void Main(string[] args)
app.UseHsts();
}


app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
Expand Down
5 changes: 1 addition & 4 deletions src/Dfe.ContentSupport.Web/Services/ContentService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Xml.Linq;
using Contentful.Core.Search;
using Dfe.ContentSupport.Web.Models.Mapped;
using Dfe.ContentSupport.Web.ViewModels;

Expand Down Expand Up @@ -59,9 +58,7 @@ public async Task<List<CsPage>> GetContentSupportPages(
}


var builder = QueryBuilder<ContentSupportPage>.New.ContentTypeIs(nameof(ContentSupportPage))
.FieldEquals($"fields.{field}", value);
var result = await contentfulService.ContentfulClient(isPreview).Query(builder);
var result = await contentfulService.GetContentSupportPages(field, value);
var pages = modelMapper.MapToCsPages(result);

if (!isPreview)
Expand Down
Loading
Loading