From 80a759e965cf438d544fe82722a4f2b32fd73bc6 Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Fri, 14 Feb 2025 14:59:40 +0000 Subject: [PATCH 1/2] Fixed the issue with ESR link for the resources not loading for first launch --- .../Controllers/ContentServerController.cs | 8 +- .../IScormResourceVersionRepository.cs | 4 +- .../ScormResourceVersionRepository.cs | 153 +++++++++--------- .../IScormContentServerService.cs | 4 +- .../ScormContentServerService.cs | 8 +- 5 files changed, 88 insertions(+), 89 deletions(-) diff --git a/WebAPI/LearningHub.Nhs.API/Controllers/ContentServerController.cs b/WebAPI/LearningHub.Nhs.API/Controllers/ContentServerController.cs index 9a95d80b0..9c662942b 100644 --- a/WebAPI/LearningHub.Nhs.API/Controllers/ContentServerController.cs +++ b/WebAPI/LearningHub.Nhs.API/Controllers/ContentServerController.cs @@ -45,11 +45,11 @@ public ContentServerController( /// The . [HttpPost] [Route("GetContentDetailsByExternalUrl")] - public async Task GetContentDetailsByExternalUrl([FromBody] string externalUrl) + public IActionResult GetContentDetailsByExternalUrl([FromBody] string externalUrl) { string decodedUrl = HttpUtility.UrlDecode(externalUrl); - var details = await this.scormContentServerService.GetContentDetailsByExternalUrl(decodedUrl); + var details = this.scormContentServerService.GetContentDetailsByExternalUrl(decodedUrl); return this.Ok(details); } @@ -61,9 +61,9 @@ public async Task GetContentDetailsByExternalUrl([FromBody] strin /// The . [HttpGet] [Route("GetContentDetailsByExternalReference/{externalReference}")] - public async Task GetContentDetailsByExternalReference(string externalReference) + public IActionResult GetContentDetailsByExternalReference(string externalReference) { - var details = await this.scormContentServerService.GetContentDetailsByExternalReference(externalReference); + var details = this.scormContentServerService.GetContentDetailsByExternalReference(externalReference); return this.Ok(details); } diff --git a/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IScormResourceVersionRepository.cs b/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IScormResourceVersionRepository.cs index 803a80896..0dfa086cf 100644 --- a/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IScormResourceVersionRepository.cs +++ b/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IScormResourceVersionRepository.cs @@ -30,7 +30,7 @@ public interface IScormResourceVersionRepository : IGenericRepository /// The external reference (guid). /// A ContentServerViewModel. - Task GetContentServerDetailsByLHExternalReference(string externalReference); + ContentServerViewModel GetContentServerDetailsByLHExternalReference(string externalReference); /// /// Gets the SCORM content details for a particular historic external URL. These historic URLs have to be supported to @@ -38,7 +38,7 @@ public interface IScormResourceVersionRepository : IGenericRepository /// The external Url. /// A ContentServerViewModel. - Task GetScormContentServerDetailsByHistoricExternalUrl(string externalUrl); + ContentServerViewModel GetScormContentServerDetailsByHistoricExternalUrl(string externalUrl); /// /// GetExternalReferenceByResourceId. diff --git a/WebAPI/LearningHub.Nhs.Repository/Resources/ScormResourceVersionRepository.cs b/WebAPI/LearningHub.Nhs.Repository/Resources/ScormResourceVersionRepository.cs index 5272bd7f8..d97d8492f 100644 --- a/WebAPI/LearningHub.Nhs.Repository/Resources/ScormResourceVersionRepository.cs +++ b/WebAPI/LearningHub.Nhs.Repository/Resources/ScormResourceVersionRepository.cs @@ -1,93 +1,92 @@ namespace LearningHub.Nhs.Repository.Resources { - using System.Collections.Generic; - using System.Data; - using System.Linq; - using System.Threading.Tasks; - using LearningHub.Nhs.Models.Entities.Resource; - using LearningHub.Nhs.Models.Resource; - using LearningHub.Nhs.Repository.Interface; - using LearningHub.Nhs.Repository.Interface.Resources; - using Microsoft.Data.SqlClient; - using Microsoft.EntityFrameworkCore; + using System.Collections.Generic; + using System.Data; + using System.Linq; + using System.Threading.Tasks; + using LearningHub.Nhs.Models.Entities.Resource; + using LearningHub.Nhs.Models.Resource; + using LearningHub.Nhs.Repository.Interface; + using LearningHub.Nhs.Repository.Interface.Resources; + using Microsoft.Data.SqlClient; + using Microsoft.EntityFrameworkCore; + /// + /// The Scorm resource version repository. + /// + public class ScormResourceVersionRepository : GenericRepository, IScormResourceVersionRepository + { /// - /// The Scorm resource version repository. + /// Initializes a new instance of the class. /// - public class ScormResourceVersionRepository : GenericRepository, IScormResourceVersionRepository + /// The db context. + /// The Timezone offset manager. + public ScormResourceVersionRepository(LearningHubDbContext dbContext, ITimezoneOffsetManager tzOffsetManager) + : base(dbContext, tzOffsetManager) { - /// - /// Initializes a new instance of the class. - /// - /// The db context. - /// The Timezone offset manager. - public ScormResourceVersionRepository(LearningHubDbContext dbContext, ITimezoneOffsetManager tzOffsetManager) - : base(dbContext, tzOffsetManager) - { - } + } - /// - /// The get by id async. - /// - /// The id. - /// The . - public async Task GetByIdAsync(int id) - { - return await this.DbContext.ScormResourceVersion.AsNoTracking().FirstOrDefaultAsync(r => r.Id == id && !r.Deleted); - } + /// + /// The get by id async. + /// + /// The id. + /// The . + public async Task GetByIdAsync(int id) + { + return await this.DbContext.ScormResourceVersion.AsNoTracking().FirstOrDefaultAsync(r => r.Id == id && !r.Deleted); + } - /// - /// The get by resource version id async. - /// - /// The resource versionid. - /// Allows deleted items to be returned. - /// The . - public async Task GetByResourceVersionIdAsync(int resourceVersionId, bool includeDeleted = false) - { - return await this.DbContext.ScormResourceVersion - .Include(r => r.File) - .Include(r => r.ScormResourceVersionManifest) - .AsNoTracking().FirstOrDefaultAsync(r => r.ResourceVersionId == resourceVersionId && (includeDeleted || !r.Deleted)); - } + /// + /// The get by resource version id async. + /// + /// The resource versionid. + /// Allows deleted items to be returned. + /// The . + public async Task GetByResourceVersionIdAsync(int resourceVersionId, bool includeDeleted = false) + { + return await this.DbContext.ScormResourceVersion + .Include(r => r.File) + .Include(r => r.ScormResourceVersionManifest) + .AsNoTracking().FirstOrDefaultAsync(r => r.ResourceVersionId == resourceVersionId && (includeDeleted || !r.Deleted)); + } - /// - /// Gets the SCORM content details for a particular Learning Hub external reference (guid). - /// - /// The external reference (guid). - /// A ContentServerViewModel. - public async Task GetContentServerDetailsByLHExternalReference(string externalReference) - { - var param0 = new SqlParameter("@externalReference", SqlDbType.NVarChar) { Value = externalReference }; + /// + /// Gets the SCORM content details for a particular Learning Hub external reference (guid). + /// + /// The external reference (guid). + /// A ContentServerViewModel. + public ContentServerViewModel GetContentServerDetailsByLHExternalReference(string externalReference) + { + var param0 = new SqlParameter("@externalReference", SqlDbType.NVarChar) { Value = externalReference }; - var scormContentData = await this.DbContext.ContentServerViewModel.FromSqlRaw("[resources].[GetContentServerDetailsForLHExternalReference] @externalReference", param0).AsNoTracking().ToListAsync(); + var scormContentServerViewModel = this.DbContext.ContentServerViewModel.FromSqlRaw("[resources].[GetContentServerDetailsForLHExternalReference] @externalReference", param0).AsEnumerable().FirstOrDefault(); - ContentServerViewModel scormContentServerViewModel = scormContentData.AsEnumerable().FirstOrDefault(); - return scormContentServerViewModel; - } + return scormContentServerViewModel; + } - /// - /// Gets the SCORM content details for a particular historic external URL. These historic URLs have to be supported to - /// allow historic ESR links on migrated resources to continue to work. - /// - /// The external Url. - /// A ContentServerViewModel. - public async Task GetScormContentServerDetailsByHistoricExternalUrl(string externalUrl) - { - var param0 = new SqlParameter("@externalUrl", SqlDbType.NVarChar) { Value = externalUrl }; + /// + /// Gets the SCORM content details for a particular historic external URL. These historic URLs have to be supported to + /// allow historic ESR links on migrated resources to continue to work. + /// + /// The external Url. + /// A ContentServerViewModel. + public ContentServerViewModel GetScormContentServerDetailsByHistoricExternalUrl(string externalUrl) + { + var param0 = new SqlParameter("@externalUrl", SqlDbType.NVarChar) { Value = externalUrl }; + + var scormContentServerViewModel = this.DbContext.ContentServerViewModel.FromSqlRaw("[resources].[GetScormContentServerDetailsForHistoricExternalUrl] @externalUrl", param0).ToList().FirstOrDefault(); - var scormContentData = await this.DbContext.ContentServerViewModel.FromSqlRaw("[resources].[GetScormContentServerDetailsForHistoricExternalUrl] @externalUrl", param0).AsNoTracking().ToListAsync(); - ContentServerViewModel scormContentServerViewModel = scormContentData.FirstOrDefault(); - return scormContentServerViewModel; - } + return scormContentServerViewModel; + } - /// - public async Task> GetExternalReferenceByResourceId(int resourceId) - { - return await (from rr in this.DbContext.ResourceReference - join er in this.DbContext.ExternalReference on rr.Id equals er.ResourceReferenceId - where rr.ResourceId == resourceId - select er.Reference) - .ToListAsync(); - } + /// + public async Task> GetExternalReferenceByResourceId(int resourceId) + { + return await (from rr in this.DbContext.ResourceReference + join er in this.DbContext.ExternalReference on rr.Id equals er.ResourceReferenceId + where rr.ResourceId == resourceId + select er.Reference) + .ToListAsync(); } + } } \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Services.Interface/IScormContentServerService.cs b/WebAPI/LearningHub.Nhs.Services.Interface/IScormContentServerService.cs index 8bd397e45..9bc5ffe50 100644 --- a/WebAPI/LearningHub.Nhs.Services.Interface/IScormContentServerService.cs +++ b/WebAPI/LearningHub.Nhs.Services.Interface/IScormContentServerService.cs @@ -14,14 +14,14 @@ public interface IScormContentServerService /// /// The externalUrl. /// The . - Task GetContentDetailsByExternalUrl(string externalUrl); + ContentServerViewModel GetContentDetailsByExternalUrl(string externalUrl); /// /// The GetContentDetailsByExternalReference. /// /// The externalReference. /// The . - Task GetContentDetailsByExternalReference(string externalReference); + ContentServerViewModel GetContentDetailsByExternalReference(string externalReference); /// /// The LogResourceReferenceEventAsync. diff --git a/WebAPI/LearningHub.Nhs.Services/ScormContentServerService.cs b/WebAPI/LearningHub.Nhs.Services/ScormContentServerService.cs index 75fa13b5c..5fef76ecf 100644 --- a/WebAPI/LearningHub.Nhs.Services/ScormContentServerService.cs +++ b/WebAPI/LearningHub.Nhs.Services/ScormContentServerService.cs @@ -63,9 +63,9 @@ public ScormContentServerService( /// /// The externalUrl. /// The . - public async Task GetContentDetailsByExternalUrl(string externalUrl) + public ContentServerViewModel GetContentDetailsByExternalUrl(string externalUrl) { - var response = await this.scormResourceVersionRepository.GetScormContentServerDetailsByHistoricExternalUrl(externalUrl); + var response = this.scormResourceVersionRepository.GetScormContentServerDetailsByHistoricExternalUrl(externalUrl); return response; } @@ -75,9 +75,9 @@ public async Task GetContentDetailsByExternalUrl(string /// /// The externalReference. /// The . - public async Task GetContentDetailsByExternalReference(string externalReference) + public ContentServerViewModel GetContentDetailsByExternalReference(string externalReference) { - var response = await this.scormResourceVersionRepository.GetContentServerDetailsByLHExternalReference(externalReference); + var response = this.scormResourceVersionRepository.GetContentServerDetailsByLHExternalReference(externalReference); return response; } From dcd501f026b101bd6ad5917c660e621c5ed99b74 Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Fri, 14 Feb 2025 15:04:05 +0000 Subject: [PATCH 2/2] formatted --- .../ScormResourceVersionRepository.cs | 150 +++++++++--------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/WebAPI/LearningHub.Nhs.Repository/Resources/ScormResourceVersionRepository.cs b/WebAPI/LearningHub.Nhs.Repository/Resources/ScormResourceVersionRepository.cs index d97d8492f..adb80296a 100644 --- a/WebAPI/LearningHub.Nhs.Repository/Resources/ScormResourceVersionRepository.cs +++ b/WebAPI/LearningHub.Nhs.Repository/Resources/ScormResourceVersionRepository.cs @@ -1,92 +1,92 @@ namespace LearningHub.Nhs.Repository.Resources { - using System.Collections.Generic; - using System.Data; - using System.Linq; - using System.Threading.Tasks; - using LearningHub.Nhs.Models.Entities.Resource; - using LearningHub.Nhs.Models.Resource; - using LearningHub.Nhs.Repository.Interface; - using LearningHub.Nhs.Repository.Interface.Resources; - using Microsoft.Data.SqlClient; - using Microsoft.EntityFrameworkCore; + using System.Collections.Generic; + using System.Data; + using System.Linq; + using System.Threading.Tasks; + using LearningHub.Nhs.Models.Entities.Resource; + using LearningHub.Nhs.Models.Resource; + using LearningHub.Nhs.Repository.Interface; + using LearningHub.Nhs.Repository.Interface.Resources; + using Microsoft.Data.SqlClient; + using Microsoft.EntityFrameworkCore; - /// - /// The Scorm resource version repository. - /// - public class ScormResourceVersionRepository : GenericRepository, IScormResourceVersionRepository - { /// - /// Initializes a new instance of the class. + /// The Scorm resource version repository. /// - /// The db context. - /// The Timezone offset manager. - public ScormResourceVersionRepository(LearningHubDbContext dbContext, ITimezoneOffsetManager tzOffsetManager) - : base(dbContext, tzOffsetManager) + public class ScormResourceVersionRepository : GenericRepository, IScormResourceVersionRepository { - } + /// + /// Initializes a new instance of the class. + /// + /// The db context. + /// The Timezone offset manager. + public ScormResourceVersionRepository(LearningHubDbContext dbContext, ITimezoneOffsetManager tzOffsetManager) + : base(dbContext, tzOffsetManager) + { + } - /// - /// The get by id async. - /// - /// The id. - /// The . - public async Task GetByIdAsync(int id) - { - return await this.DbContext.ScormResourceVersion.AsNoTracking().FirstOrDefaultAsync(r => r.Id == id && !r.Deleted); - } + /// + /// The get by id async. + /// + /// The id. + /// The . + public async Task GetByIdAsync(int id) + { + return await this.DbContext.ScormResourceVersion.AsNoTracking().FirstOrDefaultAsync(r => r.Id == id && !r.Deleted); + } - /// - /// The get by resource version id async. - /// - /// The resource versionid. - /// Allows deleted items to be returned. - /// The . - public async Task GetByResourceVersionIdAsync(int resourceVersionId, bool includeDeleted = false) - { - return await this.DbContext.ScormResourceVersion - .Include(r => r.File) - .Include(r => r.ScormResourceVersionManifest) - .AsNoTracking().FirstOrDefaultAsync(r => r.ResourceVersionId == resourceVersionId && (includeDeleted || !r.Deleted)); - } + /// + /// The get by resource version id async. + /// + /// The resource versionid. + /// Allows deleted items to be returned. + /// The . + public async Task GetByResourceVersionIdAsync(int resourceVersionId, bool includeDeleted = false) + { + return await this.DbContext.ScormResourceVersion + .Include(r => r.File) + .Include(r => r.ScormResourceVersionManifest) + .AsNoTracking().FirstOrDefaultAsync(r => r.ResourceVersionId == resourceVersionId && (includeDeleted || !r.Deleted)); + } - /// - /// Gets the SCORM content details for a particular Learning Hub external reference (guid). - /// - /// The external reference (guid). - /// A ContentServerViewModel. - public ContentServerViewModel GetContentServerDetailsByLHExternalReference(string externalReference) - { - var param0 = new SqlParameter("@externalReference", SqlDbType.NVarChar) { Value = externalReference }; + /// + /// Gets the SCORM content details for a particular Learning Hub external reference (guid). + /// + /// The external reference (guid). + /// A ContentServerViewModel. + public ContentServerViewModel GetContentServerDetailsByLHExternalReference(string externalReference) + { + var param0 = new SqlParameter("@externalReference", SqlDbType.NVarChar) { Value = externalReference }; - var scormContentServerViewModel = this.DbContext.ContentServerViewModel.FromSqlRaw("[resources].[GetContentServerDetailsForLHExternalReference] @externalReference", param0).AsEnumerable().FirstOrDefault(); + var scormContentServerViewModel = this.DbContext.ContentServerViewModel.FromSqlRaw("[resources].[GetContentServerDetailsForLHExternalReference] @externalReference", param0).AsEnumerable().FirstOrDefault(); - return scormContentServerViewModel; - } + return scormContentServerViewModel; + } - /// - /// Gets the SCORM content details for a particular historic external URL. These historic URLs have to be supported to - /// allow historic ESR links on migrated resources to continue to work. - /// - /// The external Url. - /// A ContentServerViewModel. - public ContentServerViewModel GetScormContentServerDetailsByHistoricExternalUrl(string externalUrl) - { - var param0 = new SqlParameter("@externalUrl", SqlDbType.NVarChar) { Value = externalUrl }; + /// + /// Gets the SCORM content details for a particular historic external URL. These historic URLs have to be supported to + /// allow historic ESR links on migrated resources to continue to work. + /// + /// The external Url. + /// A ContentServerViewModel. + public ContentServerViewModel GetScormContentServerDetailsByHistoricExternalUrl(string externalUrl) + { + var param0 = new SqlParameter("@externalUrl", SqlDbType.NVarChar) { Value = externalUrl }; - var scormContentServerViewModel = this.DbContext.ContentServerViewModel.FromSqlRaw("[resources].[GetScormContentServerDetailsForHistoricExternalUrl] @externalUrl", param0).ToList().FirstOrDefault(); + var scormContentServerViewModel = this.DbContext.ContentServerViewModel.FromSqlRaw("[resources].[GetScormContentServerDetailsForHistoricExternalUrl] @externalUrl", param0).ToList().FirstOrDefault(); - return scormContentServerViewModel; - } + return scormContentServerViewModel; + } - /// - public async Task> GetExternalReferenceByResourceId(int resourceId) - { - return await (from rr in this.DbContext.ResourceReference - join er in this.DbContext.ExternalReference on rr.Id equals er.ResourceReferenceId - where rr.ResourceId == resourceId - select er.Reference) - .ToListAsync(); + /// + public async Task> GetExternalReferenceByResourceId(int resourceId) + { + return await (from rr in this.DbContext.ResourceReference + join er in this.DbContext.ExternalReference on rr.Id equals er.ResourceReferenceId + where rr.ResourceId == resourceId + select er.Reference) + .ToListAsync(); + } } - } } \ No newline at end of file