Skip to content
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
50 changes: 50 additions & 0 deletions LearningHub.Nhs.WebUI/Controllers/JiraRoadmapController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace LearningHub.Nhs.WebUI.Controllers
{
using System.Net.Http;
using System.Threading.Tasks;
using LearningHub.Nhs.WebUI.Configuration;
using LearningHub.Nhs.WebUI.Interfaces;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

/// <summary>
/// Defines the <see cref="JiraRoadmapController"/>.
/// </summary>
public class JiraRoadmapController : BaseController
{
private readonly IJiraRoadmapService jiraRoadmapService;

/// <summary>
/// Initializes a new instance of the <see cref="JiraRoadmapController"/> class.
/// </summary>
/// <param name="hostingEnvironment">hostingEnvironment.</param>
/// <param name="logger">logger.</param>
/// <param name="settings">settings.</param>
/// <param name="httpClientFactory">httpClientFactory.</param>
/// <param name="jiraRoadmapService">jiraRoadmapService.</param>
public JiraRoadmapController(
IWebHostEnvironment hostingEnvironment,
ILogger<ResourceController> logger,
IOptions<Settings> settings,
IHttpClientFactory httpClientFactory,
IJiraRoadmapService jiraRoadmapService)
: base(hostingEnvironment, httpClientFactory, logger, settings.Value)
{
this.jiraRoadmapService = jiraRoadmapService;
}

/// <summary>
/// Returns public roadmap issues (data only endpoint for WebUI).
/// </summary>
/// <returns>The <see cref="Task{IActionResult}"/>.</returns>
[HttpGet]
[Route("getRoadmapIssues")]
public async Task<IActionResult> GetRoadmapIssues()
{
var roadmapResponse = await this.jiraRoadmapService.GetPublicRoadmapIssues();
return this.Json(roadmapResponse);
}
}
}
18 changes: 18 additions & 0 deletions LearningHub.Nhs.WebUI/Interfaces/IJiraRoadmapService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace LearningHub.Nhs.WebUI.Interfaces
{
using System.Collections.Generic;
using System.Threading.Tasks;
using LearningHub.Nhs.Models.JiraRoadmap;

/// <summary>
/// Defines the <see cref="IJiraRoadmapService" />.
/// </summary>
public interface IJiraRoadmapService
{
/// <summary>
/// Gets public roadmap issues from Jira Open API.
/// </summary>
/// <returns>The <see cref="Task"/>.</returns>
Task<RoadmapResponseDto> GetPublicRoadmapIssues();
}
}
52 changes: 52 additions & 0 deletions LearningHub.Nhs.WebUI/Services/JiraRoadmapService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace LearningHub.Nhs.WebUI.Services
{
using System;
using System.Threading.Tasks;
using LearningHub.Nhs.Models.JiraRoadmap;
using LearningHub.Nhs.WebUI.Interfaces;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

/// <summary>
/// Defines the <see cref="JiraRoadmapService" />.
/// </summary>
public class JiraRoadmapService : BaseService<JiraRoadmapService>, IJiraRoadmapService
{
/// <summary>
/// Initializes a new instance of the <see cref="JiraRoadmapService"/> class.
/// </summary>
/// <param name="learningHubHttpClient">The learningHubHttpClient<see cref="ILearningHubHttpClient"/>.</param>
/// <param name="openApiHttpClient">The openApiHttpClient<see cref="IOpenApiHttpClient"/>.</param>
/// <param name="logger">The logger<see cref="ILogger{JiraRoadmapService}"/>.</param>
public JiraRoadmapService(
ILearningHubHttpClient learningHubHttpClient,
IOpenApiHttpClient openApiHttpClient,
ILogger<JiraRoadmapService> logger)
: base(learningHubHttpClient, openApiHttpClient, logger)
{
}

/// <inheritdoc />
public async Task<RoadmapResponseDto> GetPublicRoadmapIssues()
{
var client = await this.OpenApiHttpClient.GetClientAsync();
var request = "JiraRoadmap/GetRoadmapIssues";
var response = await client.GetAsync(request).ConfigureAwait(false);
if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized
||
response.StatusCode == System.Net.HttpStatusCode.Forbidden)
{
throw new Exception("AccessDenied");
}

RoadmapResponseDto roadmapResponse = new RoadmapResponseDto();
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
roadmapResponse = JsonConvert.DeserializeObject<RoadmapResponseDto>(result);
}

return roadmapResponse;
}
}
}
1 change: 1 addition & 0 deletions LearningHub.Nhs.WebUI/Startup/ServiceMappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public static void AddLearningHubMappings(this IServiceCollection services, ICon
services.AddSingleton<IJsDetectionLogger, JsDetectionLogger>();
services.AddScoped<IInternalSystemService, InternalSystemService>();
services.AddScoped<IProviderService, ProviderService>();
services.AddScoped<IJiraRoadmapService, JiraRoadmapService>();

// Filters (that require DI)
services.AddScoped<LoginWizardFilter>();
Expand Down
Loading