mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
after removing canvas id from module
This commit is contained in:
@@ -65,7 +65,7 @@ public class CanvasModuleService
|
||||
return items;
|
||||
}
|
||||
|
||||
public async Task<Dictionary<ulong, IEnumerable<CanvasModuleItem>>> GetAllModulesItems(
|
||||
public async Task<Dictionary<CanvasModule, IEnumerable<CanvasModuleItem>>> GetAllModulesItems(
|
||||
ulong courseId,
|
||||
IEnumerable<CanvasModule> modules
|
||||
)
|
||||
@@ -78,7 +78,7 @@ public class CanvasModuleService
|
||||
}
|
||||
);
|
||||
|
||||
var output = new Dictionary<ulong, IEnumerable<CanvasModuleItem>>();
|
||||
var output = new Dictionary<CanvasModule, IEnumerable<CanvasModuleItem>>();
|
||||
var itemTasksResult = await Task.WhenAll(itemsTasks);
|
||||
foreach (var (module, items) in itemTasksResult)
|
||||
{
|
||||
@@ -86,7 +86,7 @@ public class CanvasModuleService
|
||||
throw new Exception(
|
||||
"i'm not sure how we got here, but module and items are null after looking up module items"
|
||||
);
|
||||
output[module.Id] = items;
|
||||
output[module] = items;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -1,27 +1,18 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using CanvasModel.Quizzes;
|
||||
using LocalModels;
|
||||
using RestSharp;
|
||||
|
||||
namespace Management.Services.Canvas;
|
||||
|
||||
public class CanvasQuizService
|
||||
public class CanvasQuizService(
|
||||
IWebRequestor webRequestor,
|
||||
CanvasServiceUtils utils,
|
||||
CanvasAssignmentService assignments
|
||||
)
|
||||
{
|
||||
private readonly IWebRequestor webRequestor;
|
||||
private readonly CanvasServiceUtils utils;
|
||||
private readonly CanvasAssignmentService assignments;
|
||||
|
||||
public CanvasQuizService(
|
||||
IWebRequestor webRequestor,
|
||||
CanvasServiceUtils utils,
|
||||
CanvasAssignmentService assignments
|
||||
)
|
||||
{
|
||||
this.webRequestor = webRequestor;
|
||||
this.utils = utils;
|
||||
this.assignments = assignments;
|
||||
}
|
||||
private readonly IWebRequestor webRequestor = webRequestor;
|
||||
private readonly CanvasServiceUtils utils = utils;
|
||||
private readonly CanvasAssignmentService assignments = assignments;
|
||||
|
||||
public async Task<IEnumerable<CanvasQuiz>> GetAll(ulong courseId)
|
||||
{
|
||||
|
||||
@@ -6,9 +6,12 @@ using YamlDotNet.Serialization.NamingConventions;
|
||||
public class FileStorageManager
|
||||
{
|
||||
private readonly MyLogger<FileStorageManager> logger;
|
||||
private static readonly string _basePath = "../storage";
|
||||
|
||||
public FileStorageManager(MyLogger<FileStorageManager> logger)
|
||||
{
|
||||
if (!Directory.Exists(_basePath))
|
||||
throw new Exception("storage folder not found");
|
||||
this.logger = logger;
|
||||
}
|
||||
public string CourseToYaml(LocalCourse course)
|
||||
@@ -32,18 +35,18 @@ public class FileStorageManager
|
||||
{
|
||||
var courseString = CourseToYaml(course);
|
||||
|
||||
var courseDirectory = $"../storage/{course.Settings.Name}";
|
||||
var courseDirectory = $"{_basePath}/{course.Settings.Name}";
|
||||
if (!Directory.Exists(courseDirectory))
|
||||
Directory.CreateDirectory(courseDirectory);
|
||||
|
||||
await saveModules(course);
|
||||
|
||||
await File.WriteAllTextAsync($"../storage/{course.Settings.Name}.yml", courseString);
|
||||
await File.WriteAllTextAsync($"{_basePath}/{course.Settings.Name}.yml", courseString);
|
||||
}
|
||||
|
||||
private async Task saveModules(LocalCourse course)
|
||||
{
|
||||
var courseDirectory = $"../storage/{course.Settings.Name}";
|
||||
var courseDirectory = $"{_basePath}/{course.Settings.Name}";
|
||||
|
||||
await saveSettings(course, courseDirectory);
|
||||
foreach (var module in course.Modules)
|
||||
@@ -67,7 +70,7 @@ public class FileStorageManager
|
||||
|
||||
private async Task saveQuizzes(LocalCourse course, LocalModule module)
|
||||
{
|
||||
var quizzesDirectory = $"../storage/{course.Settings.Name}/{module.Name}/quizzes";
|
||||
var quizzesDirectory = $"{_basePath}/{course.Settings.Name}/{module.Name}/quizzes";
|
||||
if (!Directory.Exists(quizzesDirectory))
|
||||
Directory.CreateDirectory(quizzesDirectory);
|
||||
|
||||
@@ -106,7 +109,7 @@ public class FileStorageManager
|
||||
|
||||
private async Task saveAssignments(LocalCourse course, LocalModule module)
|
||||
{
|
||||
var assignmentsDirectory = $"../storage/{course.Settings.Name}/{module.Name}/assignments";
|
||||
var assignmentsDirectory = $"{_basePath}/{course.Settings.Name}/{module.Name}/assignments";
|
||||
if (!Directory.Exists(assignmentsDirectory))
|
||||
Directory.CreateDirectory(assignmentsDirectory);
|
||||
|
||||
@@ -139,22 +142,83 @@ public class FileStorageManager
|
||||
logger.Log($"removing old assignment, it has probably been renamed {file}");
|
||||
File.Delete(file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<LocalCourse>> LoadSavedCourses()
|
||||
{
|
||||
string path = "../storage/";
|
||||
if (!Directory.Exists(path))
|
||||
throw new Exception("storage folder not found");
|
||||
|
||||
var fileNames = Directory.GetFiles(path);
|
||||
var fileNames = Directory.GetFiles(_basePath);
|
||||
|
||||
var courses = await Task.WhenAll(
|
||||
fileNames
|
||||
.Where(name => name.EndsWith(".yml"))
|
||||
.Select(async n => ParseCourse(await File.ReadAllTextAsync($"../storage/{n}")))
|
||||
.Select(async n => ParseCourse(await File.ReadAllTextAsync($"{_basePath}/{n}")))
|
||||
);
|
||||
return courses;
|
||||
}
|
||||
|
||||
// public async Task<LocalCourse> LoadCourseByName(string courseName)
|
||||
// {
|
||||
// var courseDirectory = $"{_basePath}/{courseName}";
|
||||
// if (!Directory.Exists(courseDirectory))
|
||||
// {
|
||||
// var errorMessage = $"error loading course by name, could not find folder {courseDirectory}";
|
||||
// logger.Log(errorMessage);
|
||||
// throw new LoadCourseFromFileException(errorMessage);
|
||||
// }
|
||||
// var settingsPath = $"{courseDirectory}/settings.yml";
|
||||
// if (!Directory.Exists(settingsPath))
|
||||
// {
|
||||
// var errorMessage = $"error loading course by name, settings file {settingsPath}";
|
||||
// logger.Log(errorMessage);
|
||||
// throw new LoadCourseFromFileException(errorMessage);
|
||||
// }
|
||||
|
||||
// var settingsString = await File.ReadAllTextAsync(settingsPath);
|
||||
// var settings = LocalCourseSettings.ParseYaml(settingsString);
|
||||
|
||||
// var modulePaths = Directory.GetDirectories(courseDirectory);
|
||||
// var modules = modulePaths
|
||||
// .Select(LoadModuleFromPath)
|
||||
// .ToArray();
|
||||
|
||||
// }
|
||||
|
||||
// public async Task<LocalModule> LoadModuleFromPath(string modulePath)
|
||||
// {
|
||||
// var assignmentsPath = $"{modulePath}/assignments";
|
||||
// if (!Directory.Exists(assignmentsPath))
|
||||
// {
|
||||
// var errorMessage = $"error loading course by name, assignments folder does not exist in {modulePath}";
|
||||
// logger.Log(errorMessage);
|
||||
// throw new LoadCourseFromFileException(errorMessage);
|
||||
// }
|
||||
|
||||
// var quizzesPath = $"{modulePath}/quizzes";
|
||||
// if (!Directory.Exists(quizzesPath))
|
||||
// {
|
||||
// var errorMessage = $"error loading course by name, quizzes folder does not exist in {modulePath}";
|
||||
// logger.Log(errorMessage);
|
||||
// throw new LoadCourseFromFileException(errorMessage);
|
||||
// }
|
||||
|
||||
|
||||
// var assignments = LoadAssignmentsFromPath(assignmentsPath);
|
||||
// var quizzes = LoadQuizzesFromPath(quizzesPath);
|
||||
|
||||
|
||||
// }
|
||||
// public async Task<IEnumerable<LocalAssignment>> LoadAssignmentsFromPath(string assignmentsFolder)
|
||||
// {
|
||||
|
||||
// }
|
||||
// public async Task<IEnumerable<LocalAssignment>> LoadQuizzesFromPath(string quizzesFolder)
|
||||
// {
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
public class LoadCourseFromFileException(string message) : Exception(message)
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user