Skip to content

Commit

Permalink
made content page new default page, added results page and querying c…
Browse files Browse the repository at this point in the history
…ontentful
  • Loading branch information
DanielClarke234 committed Jan 25, 2024
1 parent 4cc3933 commit 0dc7856
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Dfe.EarlyYearsQualification.Content.Entities;

public class CourseSummary
{
public int CourseId { get; set; }

public string CourseName { get; set; } = String.Empty;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Dfe.EarlyYearsQualification.Content.Entities;

public class ResultPage
{
public string Header { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
using Contentful.Core;
using Contentful.Core.Models;
using Contentful.Core.Search;
using Dfe.EarlyYearsQualification.Content.Entities;
using Dfe.EarlyYearsQualification.Content.Renderers;

namespace Dfe.EarlyYearsQualification.Content.Services;

public class ContentfulContentService : IContentService
{
private readonly IContentfulClient _contentfulClient;
private readonly IContentfulClient _contentfulClient;

public ContentfulContentService(IContentfulClient contentfulClient)
{
_contentfulClient = contentfulClient;
}
public ContentfulContentService(IContentfulClient contentfulClient)
{
_contentfulClient = contentfulClient;
}

public async Task<LandingPage> GetLandingPage()
{
var landingPageEntries = await _contentfulClient.GetEntriesByType<LandingPage>("landingPage");
var landingPageContent = landingPageEntries.First();
var htmlRenderer = new HtmlRenderer();
htmlRenderer.AddRenderer(new UnorderedListRenderer() { Order = 10 });
landingPageContent.ServiceIntroductionHtml = await htmlRenderer.ToHtml(landingPageContent.ServiceIntroduction);
return landingPageContent;
}
public async Task<LandingPage> GetLandingPage()
{
var landingPageEntries = await _contentfulClient.GetEntriesByType<LandingPage>("landingPage");
var landingPageContent = landingPageEntries.First();
var htmlRenderer = new HtmlRenderer();
htmlRenderer.AddRenderer(new UnorderedListRenderer() { Order = 10 });
landingPageContent.ServiceIntroductionHtml = await htmlRenderer.ToHtml(landingPageContent.ServiceIntroduction);
return landingPageContent;
}

public async Task<ResultPage> GetResultPage()
{
var resultPageEntries = await _contentfulClient.GetEntriesByType<ResultPage>("landingPage");
var resultPageContent = resultPageEntries.First();
return resultPageContent;
}

public async Task<List<CourseSummary>> GetCourseResults(string searchText)
{
var queryBuilder = new QueryBuilder<CourseSummary>().FullTextSearch(searchText);
var searchResult = await _contentfulClient.GetEntries(queryBuilder);
return searchResult.ToList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ namespace Dfe.EarlyYearsQualification.Content.Services;
public interface IContentService
{
Task<LandingPage> GetLandingPage();

Task<ResultPage> GetResultPage();

Task<List<CourseSummary>> GetCourseResults(string searchText);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ public HomeController(ILogger<HomeController> logger, IContentService contentSer
}

[HttpGet]
public IActionResult Index()
{
return View();
}

[HttpGet]
public async Task<IActionResult> Content()
public async Task<IActionResult> Index()
{
var landingPageContent = await _contentService.GetLandingPage();
var model = new LandingPageModel()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Mvc;
using Dfe.EarlyYearsQualification.Content.Services;
using Dfe.EarlyYearsQualification.Web.Models.Result;
using Dfe.EarlyYearsQualification.Content.Entities;

namespace Dfe.EarlyYearsQualification.Web.Controllers;

public class ResultController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly IContentService _contentService;

public ResultController(ILogger<HomeController> logger, IContentService contentService)
{
_logger = logger;
_contentService = contentService;
}

[HttpGet]
public async Task<IActionResult> Index(string CourseName)
{
var pageContent = await _contentService.GetResultPage();
var searchResult = await _contentService.GetCourseResults(CourseName);
var model = new ResultPageModel()
{
Header = pageContent.Header,
SearchResults = searchResult!
};

return View(model);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Dfe.EarlyYearsQualification.Content.Entities;

namespace Dfe.EarlyYearsQualification.Web.Models.Result;

public class ResultPageModel
{
public string Header { get; set; } = string.Empty;

public List<CourseSummary> SearchResults { get; set; } = new List<CourseSummary>();
}
2 changes: 2 additions & 0 deletions src/Dfe.EarlyYearsQualification.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

var app = builder.Build();

System.Diagnostics.Debugger.Launch();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
Expand Down
11 changes: 0 additions & 11 deletions src/Dfe.EarlyYearsQualification.Web/Views/Home/Content.cshtml

This file was deleted.

19 changes: 15 additions & 4 deletions src/Dfe.EarlyYearsQualification.Web/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
@{
@model Dfe.EarlyYearsQualification.Web.Models.Content.LandingPageModel

@{
ViewData["Title"] = "Home Page";
}

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
<h1 class="display-4">@Model.Header</h1>
@Html.Raw(Model.ServiceIntroduction)

@using (Html.BeginForm("Index", "Result", FormMethod.Get))
{
<label for="CourseName">Course Name:</label>
<input type="text" name="CourseName" id="CourseName" />

<input type="submit" value="Search" />
}

</div>
15 changes: 15 additions & 0 deletions src/Dfe.EarlyYearsQualification.Web/Views/Result/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@model Dfe.EarlyYearsQualification.Web.Models.Result.ResultPageModel

@{
ViewData["Title"] = "Result Page";
}

<div class="text-center">
<h1 class="display-4">@Model.Header</h1>

@foreach(var result in Model.SearchResults)
{
<div>@result.CourseId</div>
<div>@result.CourseName</div>
}
</div>

0 comments on commit 0dc7856

Please sign in to comment.