mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
finished CRUD on pages
This commit is contained in:
@@ -30,7 +30,7 @@ public class CanvasCoursePageService(
|
||||
}
|
||||
|
||||
|
||||
public async Task<ulong> Create(
|
||||
public async Task<CanvasPage> Create(
|
||||
ulong canvasCourseId,
|
||||
LocalCoursePage localCourse
|
||||
)
|
||||
@@ -49,22 +49,22 @@ public class CanvasCoursePageService(
|
||||
if (canvasPage == null)
|
||||
throw new Exception("created canvas course page was null");
|
||||
|
||||
return canvasPage.PageId;
|
||||
return canvasPage;
|
||||
}
|
||||
|
||||
public async Task Update(
|
||||
ulong courseId,
|
||||
string canvasPageId,
|
||||
LocalCoursePage localCourse
|
||||
ulong canvasPageId,
|
||||
LocalCoursePage localCoursePage
|
||||
)
|
||||
{
|
||||
log.Log($"updating course page: {localCourse.Name}");
|
||||
log.Log($"updating course page: {localCoursePage.Name}");
|
||||
var url = $"courses/{courseId}/pages/{canvasPageId}";
|
||||
var request = new RestRequest(url);
|
||||
var body = new
|
||||
{
|
||||
title = localCourse.Name,
|
||||
body = localCourse.GetBodyHtml()
|
||||
title = localCoursePage.Name,
|
||||
body = localCoursePage.GetBodyHtml()
|
||||
};
|
||||
var bodyObj = new { wiki_page = body };
|
||||
request.AddBody(bodyObj);
|
||||
@@ -72,7 +72,7 @@ public class CanvasCoursePageService(
|
||||
await webRequestor.PutAsync(request);
|
||||
}
|
||||
|
||||
public async Task Delete(ulong courseId, string canvasPageId)
|
||||
public async Task Delete(ulong courseId, ulong canvasPageId)
|
||||
{
|
||||
log.Log($"deleting page from canvas {canvasPageId}");
|
||||
var url = $"courses/{courseId}/pages/{canvasPageId}";
|
||||
|
||||
@@ -5,6 +5,7 @@ using CanvasModel.Courses;
|
||||
using CanvasModel.EnrollmentTerms;
|
||||
using CanvasModel.Modules;
|
||||
using RestSharp;
|
||||
using CanvasModel.Pages;
|
||||
|
||||
namespace Management.Services.Canvas;
|
||||
|
||||
@@ -145,6 +146,31 @@ public class CanvasService(
|
||||
var request = new RestRequest(url);
|
||||
request.AddBody(body);
|
||||
|
||||
var (newItem, _response) = await webRequestor.PostAsync<CanvasModuleItem>(request);
|
||||
if (newItem == null)
|
||||
throw new Exception("something went wrong updating module item with string content id");
|
||||
}
|
||||
public async Task CreatePageModuleItem(
|
||||
ulong canvasCourseId,
|
||||
ulong canvasModuleId,
|
||||
string title,
|
||||
CanvasPage canvasPage
|
||||
)
|
||||
{
|
||||
logger.Log($"creating new module item {title}");
|
||||
var url = $"courses/{canvasCourseId}/modules/{canvasModuleId}/items";
|
||||
var body = new
|
||||
{
|
||||
module_item = new
|
||||
{
|
||||
title,
|
||||
type = "Page",
|
||||
page_url = canvasPage.Url,
|
||||
}
|
||||
};
|
||||
var request = new RestRequest(url);
|
||||
request.AddBody(body);
|
||||
|
||||
var (newItem, _response) = await webRequestor.PostAsync<CanvasModuleItem>(request);
|
||||
if (newItem == null)
|
||||
throw new Exception("something went wrong updating module item with string content id");
|
||||
|
||||
Reference in New Issue
Block a user