diff --git a/LearningHub.Nhs.WebUI/Controllers/JiraRoadmapController.cs b/LearningHub.Nhs.WebUI/Controllers/JiraRoadmapController.cs new file mode 100644 index 000000000..eec6515d8 --- /dev/null +++ b/LearningHub.Nhs.WebUI/Controllers/JiraRoadmapController.cs @@ -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; + + /// + /// Defines the . + /// + public class JiraRoadmapController : BaseController + { + private readonly IJiraRoadmapService jiraRoadmapService; + + /// + /// Initializes a new instance of the class. + /// + /// hostingEnvironment. + /// logger. + /// settings. + /// httpClientFactory. + /// jiraRoadmapService. + public JiraRoadmapController( + IWebHostEnvironment hostingEnvironment, + ILogger logger, + IOptions settings, + IHttpClientFactory httpClientFactory, + IJiraRoadmapService jiraRoadmapService) + : base(hostingEnvironment, httpClientFactory, logger, settings.Value) + { + this.jiraRoadmapService = jiraRoadmapService; + } + + /// + /// Returns public roadmap issues (data only endpoint for WebUI). + /// + /// The . + [HttpGet] + [Route("getRoadmapIssues")] + public async Task GetRoadmapIssues() + { + var roadmapResponse = await this.jiraRoadmapService.GetPublicRoadmapIssues(); + return this.Json(roadmapResponse); + } + } +} diff --git a/LearningHub.Nhs.WebUI/Interfaces/IJiraRoadmapService.cs b/LearningHub.Nhs.WebUI/Interfaces/IJiraRoadmapService.cs new file mode 100644 index 000000000..610846970 --- /dev/null +++ b/LearningHub.Nhs.WebUI/Interfaces/IJiraRoadmapService.cs @@ -0,0 +1,18 @@ +namespace LearningHub.Nhs.WebUI.Interfaces +{ + using System.Collections.Generic; + using System.Threading.Tasks; + using LearningHub.Nhs.Models.JiraRoadmap; + + /// + /// Defines the . + /// + public interface IJiraRoadmapService + { + /// + /// Gets public roadmap issues from Jira Open API. + /// + /// The . + Task GetPublicRoadmapIssues(); + } +} diff --git a/LearningHub.Nhs.WebUI/Services/JiraRoadmapService.cs b/LearningHub.Nhs.WebUI/Services/JiraRoadmapService.cs new file mode 100644 index 000000000..49b3aebf3 --- /dev/null +++ b/LearningHub.Nhs.WebUI/Services/JiraRoadmapService.cs @@ -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; + + /// + /// Defines the . + /// + public class JiraRoadmapService : BaseService, IJiraRoadmapService + { + /// + /// Initializes a new instance of the class. + /// + /// The learningHubHttpClient. + /// The openApiHttpClient. + /// The logger. + public JiraRoadmapService( + ILearningHubHttpClient learningHubHttpClient, + IOpenApiHttpClient openApiHttpClient, + ILogger logger) + : base(learningHubHttpClient, openApiHttpClient, logger) + { + } + + /// + public async Task 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(result); + } + + return roadmapResponse; + } + } +} \ No newline at end of file diff --git a/LearningHub.Nhs.WebUI/Startup/ServiceMappings.cs b/LearningHub.Nhs.WebUI/Startup/ServiceMappings.cs index 26f75aeb1..c3cbf096c 100644 --- a/LearningHub.Nhs.WebUI/Startup/ServiceMappings.cs +++ b/LearningHub.Nhs.WebUI/Startup/ServiceMappings.cs @@ -115,6 +115,7 @@ public static void AddLearningHubMappings(this IServiceCollection services, ICon services.AddSingleton(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); // Filters (that require DI) services.AddScoped();