mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
more refactoring by feature
This commit is contained in:
@@ -14,7 +14,7 @@ import {
|
||||
import {
|
||||
useLocalCourseSettingsQuery,
|
||||
useUpdateLocalCourseSettingsMutation,
|
||||
} from "@/hooks/localCourse/localCoursesHooks";
|
||||
} from "@/features/local/course/localCoursesHooks";
|
||||
|
||||
export const useAssignmentQuery = (
|
||||
moduleName: string,
|
||||
|
||||
100
src/features/local/assignments/assignmentsFileStorageService.ts
Normal file
100
src/features/local/assignments/assignmentsFileStorageService.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
import {
|
||||
localAssignmentMarkdown,
|
||||
LocalAssignment,
|
||||
} from "@/features/local/assignments/models/localAssignment";
|
||||
import { assignmentMarkdownSerializer } from "@/features/local/assignments/models/utils/assignmentMarkdownSerializer";
|
||||
import path from "path";
|
||||
import { promises as fs } from "fs";
|
||||
import { courseItemFileStorageService } from "@/features/local/course/courseItemFileStorageService";
|
||||
import { getCoursePathByName } from "@/services/fileStorage/globalSettingsFileStorageService";
|
||||
import { directoryOrFileExists } from "@/services/fileStorage/utils/fileSystemUtils";
|
||||
|
||||
const getAssignmentNames = async (courseName: string, moduleName: string) => {
|
||||
const courseDirectory = await getCoursePathByName(courseName);
|
||||
const filePath = path.join(courseDirectory, moduleName, "assignments");
|
||||
if (!(await directoryOrFileExists(filePath))) {
|
||||
console.log(
|
||||
`Error loading course by name, assignments folder does not exist in ${filePath}`
|
||||
);
|
||||
// await fs.mkdir(filePath);
|
||||
return [];
|
||||
}
|
||||
|
||||
const assignmentFiles = await fs.readdir(filePath);
|
||||
return assignmentFiles.map((f) => f.replace(/\.md$/, ""));
|
||||
};
|
||||
const getAssignment = async (
|
||||
courseName: string,
|
||||
moduleName: string,
|
||||
assignmentName: string
|
||||
) => {
|
||||
const courseDirectory = await getCoursePathByName(courseName);
|
||||
const filePath = path.join(
|
||||
courseDirectory,
|
||||
moduleName,
|
||||
"assignments",
|
||||
assignmentName + ".md"
|
||||
);
|
||||
const rawFile = (await fs.readFile(filePath, "utf-8")).replace(/\r\n/g, "\n");
|
||||
return localAssignmentMarkdown.parseMarkdown(rawFile, assignmentName);
|
||||
};
|
||||
|
||||
export const assignmentsFileStorageService = {
|
||||
getAssignmentNames,
|
||||
getAssignment,
|
||||
async getAssignments(courseName: string, moduleName: string) {
|
||||
return await courseItemFileStorageService.getItems(
|
||||
courseName,
|
||||
moduleName,
|
||||
"Assignment"
|
||||
);
|
||||
},
|
||||
async updateOrCreateAssignment({
|
||||
courseName,
|
||||
moduleName,
|
||||
assignmentName,
|
||||
assignment,
|
||||
}: {
|
||||
courseName: string;
|
||||
moduleName: string;
|
||||
assignmentName: string;
|
||||
assignment: LocalAssignment;
|
||||
}) {
|
||||
const courseDirectory = await getCoursePathByName(courseName);
|
||||
const folder = path.join(courseDirectory, moduleName, "assignments");
|
||||
await fs.mkdir(folder, { recursive: true });
|
||||
|
||||
const filePath = path.join(
|
||||
courseDirectory,
|
||||
moduleName,
|
||||
"assignments",
|
||||
assignmentName + ".md"
|
||||
);
|
||||
|
||||
const assignmentMarkdown =
|
||||
assignmentMarkdownSerializer.toMarkdown(assignment);
|
||||
console.log(`Saving assignment ${filePath}`);
|
||||
|
||||
await fs.writeFile(filePath, assignmentMarkdown);
|
||||
},
|
||||
|
||||
async delete({
|
||||
courseName,
|
||||
moduleName,
|
||||
assignmentName,
|
||||
}: {
|
||||
courseName: string;
|
||||
moduleName: string;
|
||||
assignmentName: string;
|
||||
}) {
|
||||
const courseDirectory = await getCoursePathByName(courseName);
|
||||
const filePath = path.join(
|
||||
courseDirectory,
|
||||
moduleName,
|
||||
"assignments",
|
||||
assignmentName + ".md"
|
||||
);
|
||||
console.log("removing assignment", filePath);
|
||||
await fs.unlink(filePath);
|
||||
},
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IModuleItem } from "../../../../models/local/IModuleItem";
|
||||
import { IModuleItem } from "../../modules/IModuleItem";
|
||||
import {
|
||||
AssignmentSubmissionType,
|
||||
zodAssignmentSubmissionType,
|
||||
|
||||
Reference in New Issue
Block a user