-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
made content page new default page, added results page and querying c…
…ontentful
- Loading branch information
1 parent
4cc3933
commit 0dc7856
Showing
11 changed files
with
122 additions
and
36 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/Dfe.EarlyYearsQualification.Content/Entities/CourseSummary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/Dfe.EarlyYearsQualification.Content/Entities/ResultPage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
43 changes: 29 additions & 14 deletions
43
src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/Dfe.EarlyYearsQualification.Web/Controllers/ResultController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Dfe.EarlyYearsQualification.Web/Models/Result/ResultPageModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
src/Dfe.EarlyYearsQualification.Web/Views/Home/Content.cshtml
This file was deleted.
Oops, something went wrong.
19 changes: 15 additions & 4 deletions
19
src/Dfe.EarlyYearsQualification.Web/Views/Home/Index.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
src/Dfe.EarlyYearsQualification.Web/Views/Result/Index.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |