Skip to content

Commit ebb0111

Browse files
Merge pull request #1200 from TechnologyEnhancedLearning/Develop/Fixes/TD-5499-Replace-Web-API-layer-with-Open-API--My-Contributions
TD-5499: Replace Web API layer with Open API -My Contributions-Contri…
2 parents e3de851 + 1fb6073 commit ebb0111

File tree

5 files changed

+157
-52
lines changed

5 files changed

+157
-52
lines changed

OpenAPI/LearningHub.Nhs.OpenApi.Models/Configuration/AzureConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class AzureConfig
99
/// Gets or sets the azure blob settings.
1010
/// </summary>
1111
public AzureBlobSettings AzureBlobSettings { get; set; } = null!;
12+
1213
/// <summary>
1314
/// Gets or sets the azure storage queue.
1415
/// </summary>

OpenAPI/LearningHub.Nhs.OpenApi.Services.Interface/Services/IResourceService.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ Task<AssessmentProgressViewModel> GetAssessmentProgress(
225225
/// <returns>If the user has published resources.</returns>
226226
Task<bool> HasPublishedResourcesAsync(int userId);
227227

228+
/// <summary>
229+
/// The get resource version by id async.
230+
/// </summary>
231+
/// <param name="resourceVersionId">The resourceVersionId<see cref="int"/>.</param>
232+
/// <returns>The <see cref="Task{ResourceDetailViewModel}"/>.</returns>
233+
Task<ResourceDetailViewModel> GetResourceVersionByIdAsync(int resourceVersionId);
234+
228235
/// <summary>
229236
/// The get resource by activityStatusIds async.
230237
/// </summary>
@@ -300,6 +307,14 @@ Task<AssessmentProgressViewModel> GetAssessmentProgress(
300307
/// <returns>The <see cref="Task"/>.</returns>
301308
Task<CaseViewModel> GetCaseDetailsByIdAsync(int resourceVersionId);
302309

310+
/// <summary>
311+
/// The GetExternalContentDetails.
312+
/// </summary>
313+
/// <param name="resourceVersionId">The resourceVersionId<see cref="int"/>.</param>
314+
/// <param name="userId">userId.</param>
315+
/// <returns>The <see cref="Task{ExternalContentDetailsViewModel}"/>.</returns>
316+
Task<ExternalContentDetailsViewModel> GetExternalContentDetails(int resourceVersionId, int userId);
317+
303318
/// <summary>
304319
/// The get case resource version async.
305320
/// </summary>

OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/ResourceService.cs

Lines changed: 65 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,22 @@ public async Task<CaseViewModel> GetCaseDetailsByIdAsync(int resourceVersionId)
521521
return caseViewModel;
522522
}
523523

524+
/// <summary>
525+
/// The GetExternalContentDetails.
526+
/// </summary>
527+
/// <param name="resourceVersionId">The resourceVersionId<see cref="int"/>.</param>
528+
/// <param name="userId">userId.</param>
529+
/// <returns>The <see cref="Task{ExternalContentDetailsViewModel}"/>.</returns>
530+
public async Task<ExternalContentDetailsViewModel> GetExternalContentDetails(int resourceVersionId, int userId)
531+
{
532+
var viewModel = await this.resourceVersionRepository.GetExternalContentDetails(resourceVersionId, userId);
533+
if (viewModel != null)
534+
{
535+
viewModel.HostedContentUrl = $"{this.learningHubConfig.ContentServerUrl}/{viewModel.ExternalReference}/".ToLower();
536+
}
537+
538+
return viewModel;
539+
}
524540

525541
/// <summary>
526542
/// The GetFileStatusDetailsAsync.
@@ -667,6 +683,55 @@ public async Task<List<ResourceLicenceViewModel>> GetResourceLicencesAsync()
667683
return licenceList;
668684
}
669685

686+
/// <summary>
687+
/// The get resource version by id async.
688+
/// </summary>
689+
/// <param name="resourceVersionId">The resourceVersionId<see cref="int"/>.</param>
690+
/// <returns>The <see cref="Task{ResourceDetailViewModel}"/>.</returns>
691+
public async Task<ResourceDetailViewModel> GetResourceVersionByIdAsync(int resourceVersionId)
692+
{
693+
var resourceVersion = await this.resourceVersionRepository.GetBasicByIdAsync(resourceVersionId);
694+
695+
var vm = this.mapper.Map<ResourceDetailViewModel>(resourceVersion);
696+
697+
var nodeResources = await this.nodeResourceRepository.GetByResourceIdAsync(vm.ResourceId);
698+
var draftNodeResources = nodeResources.Where(x => x.VersionStatusEnum == VersionStatusEnum.Draft).ToList();
699+
var publishedNodeResources = nodeResources.Where(x => x.VersionStatusEnum == VersionStatusEnum.Published || x.VersionStatusEnum == VersionStatusEnum.Unpublished).ToList();
700+
701+
if (draftNodeResources.Count() == 0)
702+
{
703+
if (publishedNodeResources != null && publishedNodeResources.Count == 1)
704+
{
705+
vm.NodeId = publishedNodeResources[0].NodeId;
706+
vm.ResourceCatalogueId = await this.nodePathRepository.GetCatalogueRootNodeId(publishedNodeResources[0].NodeId);
707+
}
708+
else
709+
{
710+
vm.NodeId = 0;
711+
vm.ResourceCatalogueId = 0;
712+
}
713+
}
714+
else if (draftNodeResources.Count() > 1)
715+
{
716+
throw new Exception("Resource must belong to a single catalogue. ResourceVersionId: " + vm.ResourceVersionId.ToString() + ". ResourceId: " + vm.ResourceId.ToString() + ", VersionStatusEnum:" + vm.VersionStatusEnum.ToString());
717+
}
718+
else
719+
{
720+
vm.NodeId = draftNodeResources[0].NodeId;
721+
vm.ResourceCatalogueId = await this.nodePathRepository.GetCatalogueRootNodeId(draftNodeResources[0].NodeId);
722+
}
723+
724+
if (publishedNodeResources != null && publishedNodeResources.Count == 1)
725+
{
726+
vm.PublishedResourceCatalogueId = await this.nodePathRepository.GetCatalogueRootNodeId(publishedNodeResources[0].NodeId);
727+
}
728+
729+
vm.Flags = await this.GetResourceVersionFlagViewModels(resourceVersion.ResourceVersionFlag);
730+
731+
return vm;
732+
}
733+
734+
670735
/// <summary>
671736
/// The get resource version view model async.
672737
/// </summary>
@@ -1267,54 +1332,6 @@ public async Task<bool> HasPublishedResourcesAsync(int userId)
12671332
return await this.resourceRepository.UserHasPublishedResourcesAsync(userId);
12681333
}
12691334

1270-
/// <summary>
1271-
/// The get resource version by id async.
1272-
/// </summary>
1273-
/// <param name="resourceVersionId">The resourceVersionId<see cref="int"/>.</param>
1274-
/// <returns>The <see cref="Task{ResourceDetailViewModel}"/>.</returns>
1275-
public async Task<ResourceDetailViewModel> GetResourceVersionByIdAsync(int resourceVersionId)
1276-
{
1277-
var resourceVersion = await this.resourceVersionRepository.GetBasicByIdAsync(resourceVersionId);
1278-
1279-
var vm = this.mapper.Map<ResourceDetailViewModel>(resourceVersion);
1280-
1281-
var nodeResources = await this.nodeResourceRepository.GetByResourceIdAsync(vm.ResourceId);
1282-
var draftNodeResources = nodeResources.Where(x => x.VersionStatusEnum == VersionStatusEnum.Draft).ToList();
1283-
var publishedNodeResources = nodeResources.Where(x => x.VersionStatusEnum == VersionStatusEnum.Published || x.VersionStatusEnum == VersionStatusEnum.Unpublished).ToList();
1284-
1285-
if (draftNodeResources.Count() == 0)
1286-
{
1287-
if (publishedNodeResources != null && publishedNodeResources.Count == 1)
1288-
{
1289-
vm.NodeId = publishedNodeResources[0].NodeId;
1290-
vm.ResourceCatalogueId = await this.nodePathRepository.GetCatalogueRootNodeId(publishedNodeResources[0].NodeId);
1291-
}
1292-
else
1293-
{
1294-
vm.NodeId = 0;
1295-
vm.ResourceCatalogueId = 0;
1296-
}
1297-
}
1298-
else if (draftNodeResources.Count() > 1)
1299-
{
1300-
throw new Exception("Resource must belong to a single catalogue. ResourceVersionId: " + vm.ResourceVersionId.ToString() + ". ResourceId: " + vm.ResourceId.ToString() + ", VersionStatusEnum:" + vm.VersionStatusEnum.ToString());
1301-
}
1302-
else
1303-
{
1304-
vm.NodeId = draftNodeResources[0].NodeId;
1305-
vm.ResourceCatalogueId = await this.nodePathRepository.GetCatalogueRootNodeId(draftNodeResources[0].NodeId);
1306-
}
1307-
1308-
if (publishedNodeResources.Count == 1)
1309-
{
1310-
vm.PublishedResourceCatalogueId = await this.nodePathRepository.GetCatalogueRootNodeId(publishedNodeResources[0].NodeId);
1311-
}
1312-
1313-
vm.Flags = await this.GetResourceVersionFlagViewModels(resourceVersion.ResourceVersionFlag);
1314-
1315-
return vm;
1316-
}
1317-
13181335
/// <summary>
13191336
/// The save resource version flag async.
13201337
/// </summary>

OpenAPI/LearningHub.Nhs.OpenApi/Controllers/ResourceController.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,17 @@ public async Task<ActionResult> GetCaseResourceVersionAsync(int resourceVersionI
281281
return this.Ok(await this.resourceService.GetCaseDetailsByIdAsync(resourceVersionId));
282282
}
283283

284+
/// <summary>
285+
/// The GetExternalContentDetailsById.
286+
/// </summary>
287+
/// <param name="resourceVersionId">The resourceVersionId<see cref="int"/>.</param>
288+
/// <returns>The <see cref="Task{ActionResult}"/>.</returns>
289+
[HttpGet("GetExternalContentDetailsById/{resourceVersionId}")]
290+
public async Task<ActionResult> GetScormContentDetailsById(int resourceVersionId)
291+
{
292+
return this.Ok(await this.resourceService.GetExternalContentDetails(resourceVersionId, this.CurrentUserId.GetValueOrDefault()));
293+
}
294+
284295
/// <summary>
285296
/// The GetFileStatusDetailsAsync.
286297
/// </summary>
@@ -342,6 +353,17 @@ public async Task<ActionResult> GetResourceLicences()
342353
return this.Ok(await this.resourceService.GetResourceLicencesAsync());
343354
}
344355

356+
/// <summary>
357+
/// Get specific ResourceVersion by Id.
358+
/// </summary>
359+
/// <param name="resourceVersionId">The resourceVersionId<see cref="int"/>.</param>
360+
/// <returns>The <see cref="Task{ActionResult}"/>.</returns>
361+
[HttpGet("GetResourceVersion/{resourceVersionId}")]
362+
public async Task<ActionResult> GetResourceVersionAsync(int resourceVersionId)
363+
{
364+
return this.Ok(await this.resourceService.GetResourceVersionByIdAsync(resourceVersionId));
365+
}
366+
345367
/// <summary>
346368
/// Get specific ResourceVersionViewModel by Id.
347369
/// </summary>
@@ -798,7 +820,7 @@ public async Task<IActionResult> DuplicateBlocks(DuplicateBlocksRequestModel dup
798820
/// <returns>The <see cref="Task{IActionResult}"/>.</returns>
799821
[HttpPost]
800822
[Route("CreateResource")]
801-
public async Task<IActionResult> CreateResourceAsync(ResourceDetailViewModel viewModel)
823+
public async Task<IActionResult> CreateResourceAsync([FromBody] ResourceDetailViewModel viewModel)
802824
{
803825
var vr = await this.resourceService.CreateResourceAsync(viewModel, this.CurrentUserId.GetValueOrDefault());
804826
if (vr.IsValid)
@@ -891,7 +913,7 @@ public async Task<IActionResult> SubmitResourceVersionForPublishAsync(PublishVie
891913
[HttpPost]
892914
[Authorize(Policy = "ReadWrite")]
893915
[Route("UpdateResourceVersion")]
894-
public async Task<IActionResult> UpdateResourceVersionAsync(ResourceDetailViewModel resourceDetailViewModel)
916+
public async Task<IActionResult> UpdateResourceVersionAsync([FromBody] ResourceDetailViewModel resourceDetailViewModel)
895917
{
896918
var vr = await this.resourceService.UpdateResourceVersionAsync(resourceDetailViewModel, this.CurrentUserId.GetValueOrDefault());
897919

@@ -1093,7 +1115,7 @@ public async Task<IActionResult> DeleteResourceAttributeFileAsync(FileDeleteRequ
10931115
/// <returns>The <see cref="Task{IActionResult}"/>.</returns>
10941116
[HttpPost]
10951117
[Route("UpdateAudioDetail")]
1096-
public async Task<IActionResult> UpdateAudioDetailAsync(AudioUpdateRequestViewModel audioViewModel)
1118+
public async Task<IActionResult> UpdateAudioDetailAsync([FromBody] AudioUpdateRequestViewModel audioViewModel)
10971119
{
10981120
var vr = await this.resourceService.UpdateAudioDetailAsync(audioViewModel, this.CurrentUserId.GetValueOrDefault());
10991121

@@ -1114,7 +1136,7 @@ public async Task<IActionResult> UpdateAudioDetailAsync(AudioUpdateRequestViewMo
11141136
/// <returns>The <see cref="Task{IActionResult}"/>.</returns>
11151137
[HttpPost]
11161138
[Route("UpdateArticleDetail")]
1117-
public async Task<IActionResult> UpdateArticleDetailAsync(ArticleUpdateRequestViewModel articleViewModel)
1139+
public async Task<IActionResult> UpdateArticleDetailAsync([FromBody] ArticleUpdateRequestViewModel articleViewModel)
11181140
{
11191141
var vr = await this.resourceService.UpdateArticleDetailAsync(articleViewModel, this.CurrentUserId.GetValueOrDefault());
11201142

OpenAPI/LearningHub.Nhs.OpenApi/SwaggerDefinitions/v1.3.0.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3554,6 +3554,31 @@
35543554
}
35553555
}
35563556
},
3557+
"/Resource/GetExternalContentDetailsById/{resourceVersionId}": {
3558+
"get": {
3559+
"tags": [
3560+
"Resource"
3561+
],
3562+
"summary": "Get External content details of a resource by ResourceVersionId.",
3563+
"parameters": [
3564+
{
3565+
"name": "resourceVersionId",
3566+
"in": "path",
3567+
"description": "The resourceVersionIdSystem.Int32.",
3568+
"required": true,
3569+
"schema": {
3570+
"type": "integer",
3571+
"format": "int32"
3572+
}
3573+
}
3574+
],
3575+
"responses": {
3576+
"200": {
3577+
"description": "OK"
3578+
}
3579+
}
3580+
}
3581+
},
35573582
"/Resource/GetWeblinkDetails/{resourceVersionId}": {
35583583
"get": {
35593584
"tags": [
@@ -3682,6 +3707,31 @@
36823707
}
36833708
}
36843709
},
3710+
"/Resource/GetResourceVersion/{resourceVersionId}": {
3711+
"get": {
3712+
"tags": [
3713+
"Resource"
3714+
],
3715+
"summary": "Get specific ResourceVersion by Id.",
3716+
"parameters": [
3717+
{
3718+
"name": "resourceVersionId",
3719+
"in": "path",
3720+
"description": "The resourceVersionIdSystem.Int32.",
3721+
"required": true,
3722+
"schema": {
3723+
"type": "integer",
3724+
"format": "int32"
3725+
}
3726+
}
3727+
],
3728+
"responses": {
3729+
"200": {
3730+
"description": "OK"
3731+
}
3732+
}
3733+
}
3734+
},
36853735
"/Resource/GetResourceVersionViewModel/{resourceVersionId}": {
36863736
"get": {
36873737
"tags": [

0 commit comments

Comments
 (0)