extracted a lot of canvas interfaces

This commit is contained in:
2024-05-03 15:22:26 -06:00
parent 353bd6df82
commit 9bae17a2a6
34 changed files with 183 additions and 130 deletions

View File

@@ -8,12 +8,12 @@ public class AssignmentEditorContext
{
public event Action? StateHasChanged;
public CanvasService canvas { get; }
public ICanvasService canvas { get; }
private CoursePlanner planner { get; }
public AssignmentEditorContext(
MyLogger<AssignmentEditorContext> logger,
CanvasService canvas,
ICanvasService canvas,
CoursePlanner planner
)
{

View File

@@ -16,7 +16,7 @@ public class CoursePlanner
{
private readonly MyLogger<CoursePlanner> logger;
private readonly FileStorageManager fileStorageManager;
private readonly CanvasService canvas;
private readonly ICanvasService canvas;
private readonly ILogger<CoursePlanner> _otherLogger;
public bool LoadingCanvasData { get; internal set; } = false;
@@ -24,7 +24,7 @@ public class CoursePlanner
public CoursePlanner(
MyLogger<CoursePlanner> logger,
FileStorageManager fileStorageManager,
CanvasService canvas,
ICanvasService canvas,
ILogger<CoursePlanner> otherLogger
)
{

View File

@@ -6,12 +6,12 @@ using Management.Services.Canvas;
public class PageEditorContext(
CoursePlanner planner,
CanvasService canvas,
ICanvasService canvas,
MyLogger<PageEditorContext> logger)
{
public event Action? StateHasChanged;
private CoursePlanner planner { get; } = planner;
private CanvasService canvas { get; } = canvas;
private ICanvasService canvas { get; } = canvas;
private readonly MyLogger<PageEditorContext> logger = logger;

View File

@@ -7,12 +7,12 @@ using Management.Services.Canvas;
public class QuizEditorContext(
CoursePlanner planner,
CanvasService canvas,
ICanvasService canvas,
MyLogger<QuizEditorContext> logger)
{
public event Action? StateHasChanged;
private CoursePlanner planner { get; } = planner;
private CanvasService canvas { get; } = canvas;
private ICanvasService canvas { get; } = canvas;
private readonly MyLogger<QuizEditorContext> logger = logger;

View File

@@ -11,7 +11,7 @@ public static partial class AssignmentGroupSyncronizationExtensions
this LocalCourse localCourse,
ulong courseCanvasId,
IEnumerable<CanvasAssignmentGroup> canvasAssignmentGroups,
CanvasService canvas
ICanvasService canvas
)
{
var canvasAssignmentGroupIds = canvasAssignmentGroups.Select(g => g.Id).ToArray();

View File

@@ -16,7 +16,7 @@ public static partial class AssignmentSyncronizationExtensions
ulong canvasCourseId,
LocalAssignment localAssignment,
IEnumerable<CanvasAssignment> canvasAssignments,
CanvasService canvas
ICanvasService canvas
)
{
var canvasAssignment = canvasAssignments.FirstOrDefault(
@@ -42,7 +42,7 @@ public static partial class AssignmentSyncronizationExtensions
ulong canvasCourseId,
LocalAssignment localAssignment,
CanvasAssignment canvasAssignment,
CanvasService canvas,
ICanvasService canvas,
ulong? canvasAssignmentGroupId
)
{

View File

@@ -12,7 +12,7 @@ public static partial class ModuleSyncronizationExtensions
// this LocalCourse localCourse,
// ulong canvasId,
// IEnumerable<CanvasModule> canvasModules,
// CanvasService canvas
// ICanvasService canvas
// )
// {
// var currentCanvasPositions = canvasModules.ToDictionary(m => m.Id, m => m.Position);
@@ -34,7 +34,7 @@ public static partial class ModuleSyncronizationExtensions
this LocalModule localModule,
ulong canvasId,
ulong moduleCanvasId,
CanvasService canvas
ICanvasService canvas
)
{
var canvasModuleItems = await canvas.Modules.GetModuleItems(canvasId, moduleCanvasId);
@@ -79,7 +79,7 @@ public static partial class ModuleSyncronizationExtensions
ulong canvasId,
CanvasModule canvasModule,
Dictionary<CanvasModule, IEnumerable<CanvasModuleItem>> canvasModulesItems,
CanvasService canvas,
ICanvasService canvas,
IEnumerable<CanvasAssignment> canvasAssignments
)
{

View File

@@ -7,7 +7,7 @@ public static class PageSynchronizationExtension
public static async Task<CanvasPage?> AddPageToCanvas(
this LocalCourse localCourse,
LocalCoursePage localPage,
CanvasService canvas
ICanvasService canvas
)
{
if (localCourse.Settings.CanvasId == null)

View File

@@ -17,7 +17,7 @@ public static partial class QuizSyncronizationExtensions
public static async Task<ulong?> AddQuizToCanvas(
this LocalCourse localCourse,
LocalQuiz localQuiz,
CanvasService canvas
ICanvasService canvas
)
{
if (localCourse.Settings.CanvasId == null)

View File

@@ -4,7 +4,15 @@ using RestSharp;
namespace Management.Services.Canvas;
public class CanvasAssignmentGroupService
public interface ICanvasAssignmentGroupService
{
Task<IEnumerable<CanvasAssignmentGroup>> GetAll(ulong courseId);
Task<LocalAssignmentGroup> Create(ulong canvasCourseId, LocalAssignmentGroup localAssignmentGroup);
Task Update(ulong canvasCourseId, LocalAssignmentGroup localAssignmentGroup);
}
public class CanvasAssignmentGroupService: ICanvasAssignmentGroupService
{
private readonly IWebRequestor webRequestor;
private readonly CanvasServiceUtils utils;

View File

@@ -3,12 +3,28 @@ using LocalModels;
using RestSharp;
namespace Management.Services.Canvas;
public interface ICanvasAssignmentService
{
Task<IEnumerable<CanvasAssignment>> GetAll(ulong courseId);
Task<ulong> Create(
ulong canvasCourseId,
LocalAssignment localAssignment,
ulong? canvasAssignmentGroupId
);
Task Update(
ulong courseId,
ulong canvasAssignmentId,
LocalAssignment localAssignment,
ulong? canvasAssignmentGroupId
);
Task Delete(ulong courseId, ulong assignmentCanvasId, string assignmentName);
Task CreateRubric(ulong courseId, ulong assignmentCanvasId, LocalAssignment localAssignment);
}
public class CanvasAssignmentService(
IWebRequestor webRequestor,
CanvasServiceUtils utils,
MyLogger<CanvasAssignmentService> logger
)
): ICanvasAssignmentService
{
private readonly IWebRequestor webRequestor = webRequestor;
private readonly CanvasServiceUtils utils = utils;

View File

@@ -6,11 +6,18 @@ using LocalModels;
using RestSharp;
namespace Management.Services.Canvas;
public interface ICanvasCoursePageService
{
Task<IEnumerable<CanvasPage>> GetAll(ulong courseId);
Task<CanvasPage> Create(ulong canvasCourseId, LocalCoursePage localCourse);
Task Update(ulong courseId, ulong canvasPageId, LocalCoursePage localCoursePage);
Task Delete(ulong courseId, ulong canvasPageId);
}
public class CanvasCoursePageService(
IWebRequestor webRequestor,
CanvasServiceUtils utils,
MyLogger<CanvasCoursePageService> logger
)
) : ICanvasCoursePageService
{
private readonly IWebRequestor webRequestor = webRequestor;
private readonly CanvasServiceUtils utils = utils;

View File

@@ -5,7 +5,18 @@ using RestSharp;
namespace Management.Services.Canvas;
public class CanvasModuleService
public interface ICanvasModuleService
{
Task<IEnumerable<CanvasModule>> GetModules(ulong courseId);
Task<CanvasModule> CreateModule(ulong courseId, string name);
Task UpdateModule(ulong courseId, ulong moduleId, string name, uint position);
Task<IEnumerable<CanvasModuleItem>> GetModuleItems(ulong courseId, ulong moduleId);
Task<Dictionary<CanvasModule, IEnumerable<CanvasModuleItem>>> GetAllModulesItems(ulong courseId, IEnumerable<CanvasModule> modules);
}
public class CanvasModuleService: ICanvasModuleService
{
private readonly IWebRequestor webRequestor;

View File

@@ -4,16 +4,23 @@ using RestSharp;
namespace Management.Services.Canvas;
public interface ICanvasQuizService
{
Task<IEnumerable<CanvasQuiz>> GetAll(ulong courseId);
Task<ulong> Create(ulong canvasCourseId, LocalQuiz localQuiz, ulong? canvasAssignmentGroupId);
Task CreateQuizQuestions(ulong canvasCourseId, ulong canvasQuizId, LocalQuiz localQuiz);
}
public class CanvasQuizService(
IWebRequestor webRequestor,
CanvasServiceUtils utils,
CanvasAssignmentService assignments,
ICanvasAssignmentService assignments,
ILogger<CanvasQuizService> logger
)
): ICanvasQuizService
{
private readonly IWebRequestor webRequestor = webRequestor;
private readonly CanvasServiceUtils utils = utils;
private readonly CanvasAssignmentService assignments = assignments;
private readonly ICanvasAssignmentService assignments = assignments;
private readonly ILogger<CanvasQuizService> logger = logger;
public async Task<IEnumerable<CanvasQuiz>> GetAll(ulong courseId)

View File

@@ -9,26 +9,43 @@ using RestSharp;
namespace Management.Services.Canvas;
public interface ICanvasService
{
ICanvasAssignmentService Assignments { get; }
ICanvasAssignmentGroupService AssignmentGroups { get; }
ICanvasModuleService Modules { get; }
ICanvasQuizService Quizzes { get; }
ICanvasCoursePageService Pages { get; }
Task<IEnumerable<EnrollmentTermModel>> GetTerms();
Task<IEnumerable<CourseModel>> GetCourses(ulong termId);
Task<CourseModel> GetCourse(ulong courseId);
Task<IEnumerable<EnrollmentTermModel>> GetCurrentTermsFor(DateTime? queryDate = null);
Task UpdateModuleItem(ulong canvasCourseId, ulong canvasModuleId, CanvasModuleItem item);
Task CreateModuleItem(ulong canvasCourseId, ulong canvasModuleId, string title, string type, ulong contentId);
Task CreateModuleItem(ulong canvasCourseId, ulong canvasModuleId, string title, string type, string contentId);
Task CreatePageModuleItem(ulong canvasCourseId, ulong canvasModuleId, string title, CanvasPage canvasPage);
}
public class CanvasService(
IWebRequestor webRequestor,
CanvasServiceUtils utils,
CanvasAssignmentService Assignments,
CanvasAssignmentGroupService AssignmentGroups,
CanvasModuleService Modules,
CanvasQuizService Quizzes,
CanvasCoursePageService Pages,
MyLogger<CanvasService> logger
)
ICanvasAssignmentService Assignments,
ICanvasAssignmentGroupService AssignmentGroups,
ICanvasModuleService Modules,
ICanvasQuizService Quizzes,
ICanvasCoursePageService Pages,
MyLogger<ICanvasService> logger
):ICanvasService
{
private readonly IWebRequestor webRequestor = webRequestor;
private readonly CanvasServiceUtils utils = utils;
private readonly MyLogger<CanvasService> logger = logger;
private readonly MyLogger<ICanvasService> logger = logger;
public CanvasAssignmentService Assignments { get; } = Assignments;
public CanvasAssignmentGroupService AssignmentGroups { get; } = AssignmentGroups;
public CanvasModuleService Modules { get; } = Modules;
public CanvasQuizService Quizzes { get; } = Quizzes;
public CanvasCoursePageService Pages { get; } = Pages;
public ICanvasAssignmentService Assignments { get; } = Assignments;
public ICanvasAssignmentGroupService AssignmentGroups { get; } = AssignmentGroups;
public ICanvasModuleService Modules { get; } = Modules;
public ICanvasQuizService Quizzes { get; } = Quizzes;
public ICanvasCoursePageService Pages { get; } = Pages;
public async Task<IEnumerable<EnrollmentTermModel>> GetTerms()
{

View File

@@ -2,6 +2,7 @@ using RestSharp;
namespace Management.Services.Canvas;
public class CanvasServiceUtils
{
private const string BaseUrl = "https://snow.instructure.com/api/v1/";

View File

@@ -1,15 +0,0 @@
using Microsoft.AspNetCore.SignalR;
public class SignalRHub : Hub
{
public async Task SendMessage(string user, string message)
{
await Clients.All.SendAsync("ReceiveMessage", user, message);
}
public override Task OnConnectedAsync()
{
var connectionId = Context.ConnectionId;
// Store the connection ID for later use, e.g., in a database or in-memory store
return base.OnConnectedAsync();
}
}