diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Services.Interface/Services/IMoodleApiService.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Services.Interface/Services/IMoodleApiService.cs index 1721140b..398f5dd3 100644 --- a/OpenAPI/LearningHub.Nhs.OpenApi.Services.Interface/Services/IMoodleApiService.cs +++ b/OpenAPI/LearningHub.Nhs.OpenApi.Services.Interface/Services/IMoodleApiService.cs @@ -30,7 +30,15 @@ public interface IMoodleApiService /// Moodle user id. /// pageNumber. /// List of MoodleCourseResponseModel. - Task> GetRecentEnrolledCoursesAsync(int userId, int? months = null); + Task> GetRecentEnrolledCoursesAsync(int userId, int? months = null); + + /// + /// GetEnrolledCoursesAsync. + /// + /// Moodle user id. + /// pageNumber. + /// List of MoodleCourseResponseModel. + Task> GetEnrolledCoursesHistoryAsync(int userId); /// /// GetEnrolledCoursesAsync. diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/MoodleApiService.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/MoodleApiService.cs index 80c61d1d..8ce99d99 100644 --- a/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/MoodleApiService.cs +++ b/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/MoodleApiService.cs @@ -136,6 +136,38 @@ public async Task> GetRecentEnrolledCour } } + /// + /// GetEnrolledCoursesAsync. + /// + /// Moodle user id. + /// A representing the result of the asynchronous operation. + public async Task> GetEnrolledCoursesHistoryAsync(int userId) + { + try + { + userId = 3; + var parameters = new Dictionary + { + { "userid", userId.ToString() } + }; + + // Fetch enrolled courses + var recentEnrolledCourses = await GetCallMoodleApiAsync>( + "mylearningservice_get_recent_courses", + parameters + ); + + if (recentEnrolledCourses == null || recentEnrolledCourses.Count == 0) + return new List(); + + return recentEnrolledCourses.ToList(); + } + catch (Exception ex) + { + return null; + } + } + /// /// GetUserLearningHistory. /// diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/MyLearningService.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/MyLearningService.cs index 9f44364a..a9c10a37 100644 --- a/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/MyLearningService.cs +++ b/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/MyLearningService.cs @@ -227,7 +227,7 @@ public async Task GetUserLearningHistoryA { var result = await resourceActivityRepository.GetUserLearningHistory(userId, requestModel); - var entrolledCourses = await this.moodleApiService.GetRecentEnrolledCoursesAsync(userId); + var entrolledCourses = await this.moodleApiService.GetEnrolledCoursesHistoryAsync(userId); List mappedMyLearningActivities = new(); List mappedEnrolledCourses = new(); diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserRecentLearningActivities.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserRecentLearningActivities.sql index ca8bf962..98e1e035 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserRecentLearningActivities.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserRecentLearningActivities.sql @@ -5,7 +5,7 @@ -- -- Modification History ------------------------------------------------------------------------------- -ALTER PROCEDURE [activity].[GetUserRecentLearningActivities] ( +CREATE PROCEDURE [activity].[GetUserRecentLearningActivities] ( @userId INT ) AS diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUsersLearningHistory.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUsersLearningHistory.sql index bf7218e3..ac0cf543 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUsersLearningHistory.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUsersLearningHistory.sql @@ -5,7 +5,7 @@ -- -- Modification History ------------------------------------------------------------------------------- -ALTER PROCEDURE [activity].[GetUsersLearningHistory] ( +CREATE PROCEDURE [activity].[GetUsersLearningHistory] ( @userId INT ) AS