From 3341acfd9d82d0f87d91ee3e5b3d0b24dd3d0e55 Mon Sep 17 00:00:00 2001 From: Jelle Maas Date: Mon, 13 Feb 2023 12:30:21 +0100 Subject: [PATCH] Fix module filter not returning empty list when option is null --- Epsilon.Canvas.Abstractions/ICanvasModuleCollectionFetcher.cs | 2 +- Epsilon.Canvas/CanvasModuleCollectionFetcher.cs | 4 ++-- Epsilon.Cli/Startup.cs | 2 +- Epsilon/Export/ExportOptions.cs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Epsilon.Canvas.Abstractions/ICanvasModuleCollectionFetcher.cs b/Epsilon.Canvas.Abstractions/ICanvasModuleCollectionFetcher.cs index f06dcf3c..f10fa543 100644 --- a/Epsilon.Canvas.Abstractions/ICanvasModuleCollectionFetcher.cs +++ b/Epsilon.Canvas.Abstractions/ICanvasModuleCollectionFetcher.cs @@ -4,5 +4,5 @@ namespace Epsilon.Canvas.Abstractions; public interface ICanvasModuleCollectionFetcher { - public IAsyncEnumerable GetAll(int courseId, String[] allowedModules); + public IAsyncEnumerable GetAll(int courseId, IEnumerable? allowedModules); } \ No newline at end of file diff --git a/Epsilon.Canvas/CanvasModuleCollectionFetcher.cs b/Epsilon.Canvas/CanvasModuleCollectionFetcher.cs index 8d2b76dc..2c6c7db0 100644 --- a/Epsilon.Canvas/CanvasModuleCollectionFetcher.cs +++ b/Epsilon.Canvas/CanvasModuleCollectionFetcher.cs @@ -21,7 +21,7 @@ IOutcomeHttpService outcomeService _outcomeService = outcomeService; } - public async IAsyncEnumerable GetAll(int courseId, string[] allowedModules) + public async IAsyncEnumerable GetAll(int courseId, IEnumerable? allowedModules) { var response = await _outcomeService.GetResults(courseId, new[] { "outcomes", "alignments" }); var modules = await _moduleService.GetAll(courseId, new[] { "items" }); @@ -31,7 +31,7 @@ public async IAsyncEnumerable GetAll(int courseId foreach (var module in modules.ToArray()) { - if (allowedModules.Length == 0 || allowedModules.Contains(module.Name)) + if (allowedModules == null || !allowedModules.Any() || allowedModules.Contains(module.Name)) { Debug.Assert(module.Items != null, "module.Items != null"); diff --git a/Epsilon.Cli/Startup.cs b/Epsilon.Cli/Startup.cs index 10a6dc24..f33e0733 100644 --- a/Epsilon.Cli/Startup.cs +++ b/Epsilon.Cli/Startup.cs @@ -62,7 +62,7 @@ private async Task ExecuteAsync() return; } - var modules = _exportOptions.Modules.Split(","); + var modules = _exportOptions.Modules?.Split(","); _logger.LogInformation("Targeting Canvas course: {CourseId}, at {Url}", _canvasSettings.CourseId, _canvasSettings.ApiUrl); _logger.LogInformation("Downloading results, this may take a few seconds..."); diff --git a/Epsilon/Export/ExportOptions.cs b/Epsilon/Export/ExportOptions.cs index 2e71d572..f931748b 100644 --- a/Epsilon/Export/ExportOptions.cs +++ b/Epsilon/Export/ExportOptions.cs @@ -5,8 +5,8 @@ public class ExportOptions public string OutputName { get; set; } = $"{Constants.ProjectName}-Export-{{DateTime}}"; public string Formats { get; set; } = "console"; - - public string Modules { get; set; } = ""; + + public string? Modules { get; set; } = null; public string FormattedOutputName => OutputName .Replace("{DateTime}", DateTime.Now.ToString("ddMMyyyyHHmmss"));