From 6d0e29c80cd0c1640ea46d5511133df11509b039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Wed, 22 Jul 2026 23:22:31 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20homework=20API=20cove?= =?UTF-8?q?rage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add frontend homework endpoint wrappers and shared response types - expose course homework creation and listing helpers - add missing small parity wrappers for note, session, subject, term, and user endpoints - cover new and updated API helpers with targeted vitest tests - update build rule to skip repeat builds after a passing build or explicit user waiver --- AGENTS.md | 14 +- src/api/__tests__/courses/courses.test.ts | 28 +++ src/api/__tests__/homework/homework.test.ts | 210 ++++++++++++++++++ src/api/__tests__/notes/notes.test.ts | 13 ++ src/api/__tests__/sessions/sessions.test.ts | 24 ++ src/api/__tests__/subjects/subjects.test.ts | 13 ++ src/api/__tests__/terms/terms.test.ts | 13 ++ src/api/__tests__/users/users.test.ts | 28 +++ src/api/client/types.ts | 61 +++++ src/api/courses/getCourseHomework.ts | 12 + src/api/courses/index.ts | 2 + src/api/courses/postCourseHomework.ts | 14 ++ src/api/homework/deleteHomeworkById.ts | 5 + .../homework/deleteHomeworkResultByUserId.ts | 5 + src/api/homework/deleteHomeworkSubmission.ts | 5 + .../homework/deleteHomeworkSubmissionFile.ts | 5 + src/api/homework/getHomework.ts | 8 + src/api/homework/getHomeworkById.ts | 6 + src/api/homework/getHomeworkReport.ts | 12 + src/api/homework/getHomeworkResult.ts | 6 + src/api/homework/getHomeworkSubmission.ts | 6 + .../homework/getHomeworkSubmissionFileBlob.ts | 5 + .../homework/getHomeworkSubmissionFileUrl.ts | 3 + src/api/homework/getHomeworkSubmissions.ts | 12 + src/api/homework/index.ts | 16 ++ src/api/homework/patchHomeworkById.ts | 14 ++ src/api/homework/postHomeworkResult.ts | 12 + src/api/homework/postHomeworkSubmission.ts | 10 + .../homework/postHomeworkSubmissionFile.ts | 8 + src/api/notes/getNoteById.ts | 6 + src/api/notes/index.ts | 1 + .../deleteSessionAttendanceByUserId.ts | 5 + src/api/sessions/getSessionById.ts | 6 + src/api/sessions/index.ts | 2 + src/api/subjects/getSubjectById.ts | 6 + src/api/subjects/index.ts | 1 + src/api/terms/getTermById.ts | 6 + src/api/terms/index.ts | 1 + src/api/users/getUserById.ts | 6 + src/api/users/index.ts | 2 + src/api/users/patchUserPreferences.ts | 7 + 41 files changed, 611 insertions(+), 8 deletions(-) create mode 100644 src/api/__tests__/homework/homework.test.ts create mode 100644 src/api/courses/getCourseHomework.ts create mode 100644 src/api/courses/postCourseHomework.ts create mode 100644 src/api/homework/deleteHomeworkById.ts create mode 100644 src/api/homework/deleteHomeworkResultByUserId.ts create mode 100644 src/api/homework/deleteHomeworkSubmission.ts create mode 100644 src/api/homework/deleteHomeworkSubmissionFile.ts create mode 100644 src/api/homework/getHomework.ts create mode 100644 src/api/homework/getHomeworkById.ts create mode 100644 src/api/homework/getHomeworkReport.ts create mode 100644 src/api/homework/getHomeworkResult.ts create mode 100644 src/api/homework/getHomeworkSubmission.ts create mode 100644 src/api/homework/getHomeworkSubmissionFileBlob.ts create mode 100644 src/api/homework/getHomeworkSubmissionFileUrl.ts create mode 100644 src/api/homework/getHomeworkSubmissions.ts create mode 100644 src/api/homework/index.ts create mode 100644 src/api/homework/patchHomeworkById.ts create mode 100644 src/api/homework/postHomeworkResult.ts create mode 100644 src/api/homework/postHomeworkSubmission.ts create mode 100644 src/api/homework/postHomeworkSubmissionFile.ts create mode 100644 src/api/notes/getNoteById.ts create mode 100644 src/api/sessions/deleteSessionAttendanceByUserId.ts create mode 100644 src/api/sessions/getSessionById.ts create mode 100644 src/api/subjects/getSubjectById.ts create mode 100644 src/api/terms/getTermById.ts create mode 100644 src/api/users/getUserById.ts create mode 100644 src/api/users/patchUserPreferences.ts diff --git a/AGENTS.md b/AGENTS.md index fd8684d..7b40412 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -173,13 +173,11 @@ Rules: agent shows the user the exact proposed commit message (title + all bullets) and asks for **explicit approval**. `git commit` never runs before approval is given. This applies to every commit, including small ones — no exceptions. -- **Mandatory pre-commit check, every time:** once approved, right before - running the commit: - 1. Run `bun run build` (`tsc --noEmit && vite build`) — the project already has - `noUnusedLocals` / `noUnusedParameters` enabled, so any unused import or - variable fails the build. - 2. If the build fails, remove the unused imports/variables and re-run until - it passes. - 3. Only commit once the build is green. +- **Mandatory pre-commit check:** once approved, right before running the commit, + run `bun run build` (`tsc --noEmit && vite build`) unless a build has already + passed since the last code change. If the user explicitly says not to run a + build for the current action, do not run it. If the build fails, remove the + unused imports/variables and re-run until it passes. Only commit once the build + is green or the user explicitly waived the build for that action. - This workflow (format + approval + pre-commit check) applies always, without exception, to every commit in this repo. diff --git a/src/api/__tests__/courses/courses.test.ts b/src/api/__tests__/courses/courses.test.ts index 184d6be..3258d0d 100644 --- a/src/api/__tests__/courses/courses.test.ts +++ b/src/api/__tests__/courses/courses.test.ts @@ -15,6 +15,8 @@ import { getCourseExams } from "../../courses"; import { postCourseExam } from "../../courses"; import { postCourseTeacher } from "../../courses"; import { deleteCourseTeacherByUserId } from "../../courses"; +import { getCourseHomework } from "../../courses"; +import { postCourseHomework } from "../../courses"; import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; describe("courses API", () => { @@ -220,4 +222,30 @@ describe("courses API", () => { expect(init?.method).toBe("POST"); expect(init?.body).toBe(JSON.stringify(data)); }); + + it("getCourseHomework calls /courses/:id/homework", async () => { + const mockPage = { items: [{ id: "hw1" }], total: 1 }; + mockFetchSuccess(mockPage); + + const result = await getCourseHomework("c1", { limit: 5 }); + expect(result).toEqual({ ...mockPage, limit: null, offset: 0 }); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/courses/c1/homework?limit=5"); + expect(init?.method).toBe("GET"); + }); + + it("postCourseHomework calls /courses/:id/homework", async () => { + const mockHomework = { id: "hw1", course: "c1" }; + mockFetchSuccess(mockHomework); + + const data = { title: "HW", subject_id: "sub1", due_at: 1900000000000, assigned: ["u1"] }; + const result = await postCourseHomework("c1", data); + expect(result).toEqual(mockHomework); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/courses/c1/homework"); + expect(init?.method).toBe("POST"); + expect(init?.body).toBe(JSON.stringify(data)); + }); }); diff --git a/src/api/__tests__/homework/homework.test.ts b/src/api/__tests__/homework/homework.test.ts new file mode 100644 index 0000000..4cf2a3e --- /dev/null +++ b/src/api/__tests__/homework/homework.test.ts @@ -0,0 +1,210 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; +import { + deleteHomeworkById, + deleteHomeworkResultByUserId, + deleteHomeworkSubmission, + deleteHomeworkSubmissionFile, + getHomework, + getHomeworkById, + getHomeworkReport, + getHomeworkResult, + getHomeworkSubmission, + getHomeworkSubmissionFileBlob, + getHomeworkSubmissionFileUrl, + getHomeworkSubmissions, + patchHomeworkById, + postHomeworkResult, + postHomeworkSubmission, + postHomeworkSubmissionFile, +} from "../../homework"; +import { lastFetchCall, mockFetch204, mockFetchBlob, mockFetchSuccess } from "../helpers/mock-fetch"; + +describe("homework API", () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + it("getHomework calls /homework with pagination", async () => { + const mockPage = { items: [{ id: "hw1" }], total: 1 }; + mockFetchSuccess(mockPage); + + const result = await getHomework({ limit: 10, offset: 5 }); + expect(result).toEqual({ ...mockPage, limit: null, offset: 0 }); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework?limit=10&offset=5"); + expect(init?.method).toBe("GET"); + }); + + it("getHomeworkById calls /homework/:id", async () => { + const mockHomework = { id: "hw1" }; + mockFetchSuccess(mockHomework); + + const result = await getHomeworkById("hw1"); + expect(result).toEqual(mockHomework); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework/hw1"); + expect(init?.method).toBe("GET"); + }); + + it("patchHomeworkById calls /homework/:id", async () => { + const mockHomework = { id: "hw1", title: "New" }; + mockFetchSuccess(mockHomework); + + const body = { title: "New", assigned: null }; + const result = await patchHomeworkById("hw1", body); + expect(result).toEqual(mockHomework); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework/hw1"); + expect(init?.method).toBe("PATCH"); + expect(init?.body).toBe(JSON.stringify(body)); + }); + + it("deleteHomeworkById calls /homework/:id", async () => { + mockFetch204(); + + await deleteHomeworkById("hw1"); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework/hw1"); + expect(init?.method).toBe("DELETE"); + }); + + it("postHomeworkSubmission calls /homework/:id/submission", async () => { + const mockSubmission = { homework: "hw1", text: "Done" }; + mockFetchSuccess(mockSubmission); + + const body = { text: "Done" }; + const result = await postHomeworkSubmission("hw1", body); + expect(result).toEqual(mockSubmission); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework/hw1/submission"); + expect(init?.method).toBe("POST"); + expect(init?.body).toBe(JSON.stringify(body)); + }); + + it("getHomeworkSubmission calls /homework/:id/submission", async () => { + const mockSubmission = { homework: "hw1" }; + mockFetchSuccess(mockSubmission); + + const result = await getHomeworkSubmission("hw1"); + expect(result).toEqual(mockSubmission); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework/hw1/submission"); + expect(init?.method).toBe("GET"); + }); + + it("deleteHomeworkSubmission calls /homework/:id/submission", async () => { + mockFetch204(); + + await deleteHomeworkSubmission("hw1"); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework/hw1/submission"); + expect(init?.method).toBe("DELETE"); + }); + + it("postHomeworkSubmissionFile calls /homework/:id/submission/files with FormData", async () => { + const mockFile = { id: "f1", name: "a.txt" }; + mockFetchSuccess(mockFile, 201); + + const file = new File(["x"], "a.txt", { type: "text/plain" }); + const result = await postHomeworkSubmissionFile("hw1", file); + expect(result).toEqual(mockFile); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework/hw1/submission/files"); + expect(init?.method).toBe("POST"); + expect(init?.body).toBeInstanceOf(FormData); + }); + + it("getHomeworkSubmissionFileBlob calls /homework/:id/submission/files/:fid", async () => { + const blob = new Blob(["x"], { type: "text/plain" }); + mockFetchBlob(blob); + + const result = await getHomeworkSubmissionFileBlob("hw1", "f1"); + expect(result.type).toBe("text/plain"); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework/hw1/submission/files/f1"); + expect(init?.credentials).toBe("same-origin"); + }); + + it("getHomeworkSubmissionFileUrl returns encoded URL", () => { + expect(getHomeworkSubmissionFileUrl("hw/1", "f?1")).toBe("/api/homework/hw%2F1/submission/files/f%3F1"); + }); + + it("deleteHomeworkSubmissionFile calls /homework/:id/submission/files/:fid", async () => { + mockFetch204(); + + await deleteHomeworkSubmissionFile("hw1", "f1"); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework/hw1/submission/files/f1"); + expect(init?.method).toBe("DELETE"); + }); + + it("postHomeworkResult calls /homework/:id/results", async () => { + const mockResult = { status: "done", mark: 95 }; + mockFetchSuccess(mockResult); + + const body = { user: "u1", status: "done", mark: 95 }; + const result = await postHomeworkResult("hw1", body); + expect(result).toEqual(mockResult); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework/hw1/results"); + expect(init?.method).toBe("POST"); + expect(init?.body).toBe(JSON.stringify(body)); + }); + + it("deleteHomeworkResultByUserId calls /homework/:id/results/:user", async () => { + mockFetch204(); + + await deleteHomeworkResultByUserId("hw1", "u1"); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework/hw1/results/u1"); + expect(init?.method).toBe("DELETE"); + }); + + it("getHomeworkResult calls /homework/:id/result", async () => { + const mockResult = { status: "done" }; + mockFetchSuccess(mockResult); + + const result = await getHomeworkResult("hw1"); + expect(result).toEqual(mockResult); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework/hw1/result"); + expect(init?.method).toBe("GET"); + }); + + it("getHomeworkSubmissions calls /homework/:id/submissions", async () => { + const mockPage = { items: [{ user: "u1" }], total: 1 }; + mockFetchSuccess(mockPage); + + const result = await getHomeworkSubmissions("hw1", { limit: 20 }); + expect(result).toEqual({ ...mockPage, limit: null, offset: 0 }); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework/hw1/submissions?limit=20"); + expect(init?.method).toBe("GET"); + }); + + it("getHomeworkReport calls /homework/report/:user", async () => { + const mockPage = { items: [{ homework: "hw1" }], total: 1 }; + mockFetchSuccess(mockPage); + + const result = await getHomeworkReport("u1", { offset: 10 }); + expect(result).toEqual({ ...mockPage, limit: null, offset: 0 }); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/homework/report/u1?offset=10"); + expect(init?.method).toBe("GET"); + }); +}); diff --git a/src/api/__tests__/notes/notes.test.ts b/src/api/__tests__/notes/notes.test.ts index 1763a4c..e797db8 100644 --- a/src/api/__tests__/notes/notes.test.ts +++ b/src/api/__tests__/notes/notes.test.ts @@ -1,5 +1,6 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import { getNotes } from "../../notes"; +import { getNoteById } from "../../notes"; import { postNote } from "../../notes"; import { patchNoteById } from "../../notes"; import { deleteNoteById } from "../../notes"; @@ -41,6 +42,18 @@ describe("notes API", () => { expect(init?.body).toBe(JSON.stringify(data)); }); + it("getNoteById calls /notes/:id", async () => { + const mockNote = { id: "n1", title: "Note", content: "Content" }; + mockFetchSuccess(mockNote); + + const result = await getNoteById("n1"); + expect(result).toEqual(mockNote); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/notes/n1"); + expect(init?.method).toBe("GET"); + }); + it("patchNoteById calls /notes/:id with updates", async () => { const mockNote = { id: "n1", title: "Updated", content: "Content" }; mockFetchSuccess(mockNote); diff --git a/src/api/__tests__/sessions/sessions.test.ts b/src/api/__tests__/sessions/sessions.test.ts index d30ec0b..dddbb71 100644 --- a/src/api/__tests__/sessions/sessions.test.ts +++ b/src/api/__tests__/sessions/sessions.test.ts @@ -1,8 +1,10 @@ import { afterEach, describe, expect, it, vi } from "vitest"; +import { getSessionById } from "../../sessions"; import { patchSessionById } from "../../sessions"; import { deleteSessionById } from "../../sessions"; import { getSessionAttendance } from "../../sessions"; import { postSessionAttendance } from "../../sessions"; +import { deleteSessionAttendanceByUserId } from "../../sessions"; import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; describe("sessions API", () => { @@ -10,6 +12,18 @@ describe("sessions API", () => { vi.restoreAllMocks(); }); + it("getSessionById calls /sessions/:id", async () => { + const mockSession = { id: "s1", topic: "Topic" }; + mockFetchSuccess(mockSession); + + const result = await getSessionById("s1"); + expect(result).toEqual(mockSession); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/sessions/s1"); + expect(init?.method).toBe("GET"); + }); + it("patchSessionById calls /sessions/:id with updates", async () => { const mockSession = { id: "s1", topic: "Updated" }; mockFetchSuccess(mockSession); @@ -59,4 +73,14 @@ describe("sessions API", () => { expect(init?.method).toBe("POST"); expect(init?.body).toBe(JSON.stringify(data)); }); + + it("deleteSessionAttendanceByUserId calls /sessions/:id/attendance/:user", async () => { + mockFetch204(); + + await deleteSessionAttendanceByUserId("s1", "u1"); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/sessions/s1/attendance/u1"); + expect(init?.method).toBe("DELETE"); + }); }); diff --git a/src/api/__tests__/subjects/subjects.test.ts b/src/api/__tests__/subjects/subjects.test.ts index 7b1784c..de8451e 100644 --- a/src/api/__tests__/subjects/subjects.test.ts +++ b/src/api/__tests__/subjects/subjects.test.ts @@ -1,4 +1,5 @@ import { afterEach, describe, expect, it, vi } from "vitest"; +import { getSubjectById } from "../../subjects"; import { patchSubjectById } from "../../subjects"; import { deleteSubjectById } from "../../subjects"; import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; @@ -8,6 +9,18 @@ describe("subjects API", () => { vi.restoreAllMocks(); }); + it("getSubjectById calls /subjects/:id", async () => { + const mockSubject = { id: "sub1", name: "Subject" }; + mockFetchSuccess(mockSubject); + + const result = await getSubjectById("sub1"); + expect(result).toEqual(mockSubject); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/subjects/sub1"); + expect(init?.method).toBe("GET"); + }); + it("patchSubjectById calls /subjects/:id with updates", async () => { const mockSubject = { id: "sub1", name: "Updated" }; mockFetchSuccess(mockSubject); diff --git a/src/api/__tests__/terms/terms.test.ts b/src/api/__tests__/terms/terms.test.ts index 7e15892..6c72f29 100644 --- a/src/api/__tests__/terms/terms.test.ts +++ b/src/api/__tests__/terms/terms.test.ts @@ -1,5 +1,6 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import { getTerms } from "../../terms"; +import { getTermById } from "../../terms"; import { postTerm } from "../../terms"; import { patchTermById } from "../../terms"; import { deleteTermById } from "../../terms"; @@ -36,6 +37,18 @@ describe("terms API", () => { expect(init?.body).toBe(JSON.stringify(data)); }); + it("getTermById calls /terms/:id", async () => { + const mockTerm = { id: "t1", name: "Term 1" }; + mockFetchSuccess(mockTerm); + + const result = await getTermById("t1"); + expect(result).toEqual(mockTerm); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/terms/t1"); + expect(init?.method).toBe("GET"); + }); + it("patchTermById calls /terms/:id with updates", async () => { const mockTerm = { id: "t1", name: "Updated" }; mockFetchSuccess(mockTerm); diff --git a/src/api/__tests__/users/users.test.ts b/src/api/__tests__/users/users.test.ts index 8599637..773d432 100644 --- a/src/api/__tests__/users/users.test.ts +++ b/src/api/__tests__/users/users.test.ts @@ -2,10 +2,12 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import { getMe } from "../../users"; import { patchMe } from "../../users"; import { getUsers } from "../../users"; +import { getUserById } from "../../users"; import { getUserSearch } from "../../users"; import { patchUserProfile } from "../../users"; import { patchUserRole } from "../../users"; import { patchMyPreferences } from "../../users"; +import { patchUserPreferences } from "../../users"; import { lastFetchCall, mockFetchSuccess } from "../helpers/mock-fetch"; describe("users API", () => { @@ -63,6 +65,18 @@ describe("users API", () => { expect(init?.method).toBe("GET"); }); + it("getUserById calls /users/:id", async () => { + const mockUser = { id: "u1", username: "test" }; + mockFetchSuccess(mockUser); + + const result = await getUserById("u1"); + expect(result).toEqual(mockUser); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/users/u1"); + expect(init?.method).toBe("GET"); + }); + it("patchUserProfile calls /users/:id/profile", async () => { const mockUser = { id: "u1", name: "Updated" }; mockFetchSuccess(mockUser); @@ -103,4 +117,18 @@ describe("users API", () => { expect(init?.method).toBe("PATCH"); expect(init?.body).toBe(JSON.stringify(updates)); }); + + it("patchUserPreferences calls /users/:id/preferences", async () => { + const mockUser = { id: "u1", language: "tr" }; + mockFetchSuccess(mockUser); + + const updates = { language: "tr" as const }; + const result = await patchUserPreferences("u1", updates); + expect(result).toEqual(mockUser); + + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/users/u1/preferences"); + expect(init?.method).toBe("PATCH"); + expect(init?.body).toBe(JSON.stringify(updates)); + }); }); diff --git a/src/api/client/types.ts b/src/api/client/types.ts index 91d7d49..1d6b9eb 100644 --- a/src/api/client/types.ts +++ b/src/api/client/types.ts @@ -390,3 +390,64 @@ export type Message = { folder: MessageFolder; label: string | null; }; + +export type Homework = { + id: string; + course: string; + subject: string; + title: string; + description: string | null; + due_at: number; + assigned: string[] | null; + created_by: string; + created_at: number; +}; + +export type HomeworkFile = { + id: string; + name: string; + content_type: string; + size: number; +}; + +export type HomeworkResultStatus = "done" | "incomplete" | "missing" | string; + +export type HomeworkResult = { + status: HomeworkResultStatus; + mark: number | null; + graded_by: string; + created_at: number; +}; + +export type HomeworkSubmission = { + user: string; + homework: string; + text: string | null; + submitted_at: number; + updated_at: number; + late: boolean; + files: HomeworkFile[]; + result: HomeworkResult | null; +}; + +export type HomeworkRosterSubmission = Omit; + +export type HomeworkRosterEntry = { + user: string; + submission: HomeworkRosterSubmission | null; + result: HomeworkResult | null; + missing: boolean; + unenrolled: boolean; +}; + +export type HomeworkReportEntry = { + course: string; + homework: string; + title: string; + subject: string; + due_at: number; + submitted: boolean; + late: boolean; + missing: boolean; + result: HomeworkResult | null; +}; diff --git a/src/api/courses/getCourseHomework.ts b/src/api/courses/getCourseHomework.ts new file mode 100644 index 0000000..5cfdc28 --- /dev/null +++ b/src/api/courses/getCourseHomework.ts @@ -0,0 +1,12 @@ +import { client } from "../client"; +import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; +import type { Homework } from "../client"; + +export async function getCourseHomework( + courseId: string, + params?: PageParams, + signal?: AbortSignal, +): Promise> { + const data = await client(`/courses/${courseId}/homework${pageQuery(params)}`, { signal }); + return normalizePage(data); +} diff --git a/src/api/courses/index.ts b/src/api/courses/index.ts index 6b335fb..f3aa9d8 100644 --- a/src/api/courses/index.ts +++ b/src/api/courses/index.ts @@ -14,4 +14,6 @@ export * from "./getCourseExams"; export * from "./postCourseExam"; export * from "./postCourseTeacher"; export * from "./deleteCourseTeacherByUserId"; +export * from "./getCourseHomework"; +export * from "./postCourseHomework"; diff --git a/src/api/courses/postCourseHomework.ts b/src/api/courses/postCourseHomework.ts new file mode 100644 index 0000000..73d235e --- /dev/null +++ b/src/api/courses/postCourseHomework.ts @@ -0,0 +1,14 @@ +import { client } from "../client"; +import type { Homework } from "../client"; + +export type PostCourseHomeworkBody = { + title: string; + description?: string | null; + subject_id: string; + due_at: number; + assigned?: string[] | null; +}; + +export function postCourseHomework(courseId: string, body: PostCourseHomeworkBody): Promise { + return client(`/courses/${courseId}/homework`, { method: "POST", body }); +} diff --git a/src/api/homework/deleteHomeworkById.ts b/src/api/homework/deleteHomeworkById.ts new file mode 100644 index 0000000..ab1012f --- /dev/null +++ b/src/api/homework/deleteHomeworkById.ts @@ -0,0 +1,5 @@ +import { client } from "../client"; + +export function deleteHomeworkById(id: string): Promise { + return client(`/homework/${id}`, { method: "DELETE" }); +} diff --git a/src/api/homework/deleteHomeworkResultByUserId.ts b/src/api/homework/deleteHomeworkResultByUserId.ts new file mode 100644 index 0000000..c95754e --- /dev/null +++ b/src/api/homework/deleteHomeworkResultByUserId.ts @@ -0,0 +1,5 @@ +import { client } from "../client"; + +export function deleteHomeworkResultByUserId(id: string, userId: string): Promise { + return client(`/homework/${id}/results/${userId}`, { method: "DELETE" }); +} diff --git a/src/api/homework/deleteHomeworkSubmission.ts b/src/api/homework/deleteHomeworkSubmission.ts new file mode 100644 index 0000000..c0db151 --- /dev/null +++ b/src/api/homework/deleteHomeworkSubmission.ts @@ -0,0 +1,5 @@ +import { client } from "../client"; + +export function deleteHomeworkSubmission(id: string): Promise { + return client(`/homework/${id}/submission`, { method: "DELETE" }); +} diff --git a/src/api/homework/deleteHomeworkSubmissionFile.ts b/src/api/homework/deleteHomeworkSubmissionFile.ts new file mode 100644 index 0000000..8706233 --- /dev/null +++ b/src/api/homework/deleteHomeworkSubmissionFile.ts @@ -0,0 +1,5 @@ +import { client } from "../client"; + +export function deleteHomeworkSubmissionFile(id: string, fileId: string): Promise { + return client(`/homework/${id}/submission/files/${fileId}`, { method: "DELETE" }); +} diff --git a/src/api/homework/getHomework.ts b/src/api/homework/getHomework.ts new file mode 100644 index 0000000..b24c64f --- /dev/null +++ b/src/api/homework/getHomework.ts @@ -0,0 +1,8 @@ +import { client } from "../client"; +import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; +import type { Homework } from "../client"; + +export async function getHomework(params?: PageParams, signal?: AbortSignal): Promise> { + const data = await client(`/homework${pageQuery(params)}`, { signal }); + return normalizePage(data); +} diff --git a/src/api/homework/getHomeworkById.ts b/src/api/homework/getHomeworkById.ts new file mode 100644 index 0000000..1c10105 --- /dev/null +++ b/src/api/homework/getHomeworkById.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { Homework } from "../client"; + +export function getHomeworkById(id: string, signal?: AbortSignal): Promise { + return client(`/homework/${id}`, { signal }); +} diff --git a/src/api/homework/getHomeworkReport.ts b/src/api/homework/getHomeworkReport.ts new file mode 100644 index 0000000..a3b62de --- /dev/null +++ b/src/api/homework/getHomeworkReport.ts @@ -0,0 +1,12 @@ +import { client } from "../client"; +import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; +import type { HomeworkReportEntry } from "../client"; + +export async function getHomeworkReport( + userId: string, + params?: PageParams, + signal?: AbortSignal, +): Promise> { + const data = await client(`/homework/report/${userId}${pageQuery(params)}`, { signal }); + return normalizePage(data); +} diff --git a/src/api/homework/getHomeworkResult.ts b/src/api/homework/getHomeworkResult.ts new file mode 100644 index 0000000..5589cdc --- /dev/null +++ b/src/api/homework/getHomeworkResult.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { HomeworkResult } from "../client"; + +export function getHomeworkResult(id: string, signal?: AbortSignal): Promise { + return client(`/homework/${id}/result`, { signal }); +} diff --git a/src/api/homework/getHomeworkSubmission.ts b/src/api/homework/getHomeworkSubmission.ts new file mode 100644 index 0000000..3128c70 --- /dev/null +++ b/src/api/homework/getHomeworkSubmission.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { HomeworkSubmission } from "../client"; + +export function getHomeworkSubmission(id: string, signal?: AbortSignal): Promise { + return client(`/homework/${id}/submission`, { signal }); +} diff --git a/src/api/homework/getHomeworkSubmissionFileBlob.ts b/src/api/homework/getHomeworkSubmissionFileBlob.ts new file mode 100644 index 0000000..3584d71 --- /dev/null +++ b/src/api/homework/getHomeworkSubmissionFileBlob.ts @@ -0,0 +1,5 @@ +import { blobClient } from "../client"; + +export function getHomeworkSubmissionFileBlob(id: string, fileId: string, signal?: AbortSignal): Promise { + return blobClient(`/homework/${id}/submission/files/${fileId}`, signal); +} diff --git a/src/api/homework/getHomeworkSubmissionFileUrl.ts b/src/api/homework/getHomeworkSubmissionFileUrl.ts new file mode 100644 index 0000000..9f19af2 --- /dev/null +++ b/src/api/homework/getHomeworkSubmissionFileUrl.ts @@ -0,0 +1,3 @@ +export function getHomeworkSubmissionFileUrl(id: string, fileId: string): string { + return `/api/homework/${encodeURIComponent(id)}/submission/files/${encodeURIComponent(fileId)}`; +} diff --git a/src/api/homework/getHomeworkSubmissions.ts b/src/api/homework/getHomeworkSubmissions.ts new file mode 100644 index 0000000..67e57e1 --- /dev/null +++ b/src/api/homework/getHomeworkSubmissions.ts @@ -0,0 +1,12 @@ +import { client } from "../client"; +import { normalizePage, pageQuery, type Page, type PageParams } from "../client"; +import type { HomeworkRosterEntry } from "../client"; + +export async function getHomeworkSubmissions( + id: string, + params?: PageParams, + signal?: AbortSignal, +): Promise> { + const data = await client(`/homework/${id}/submissions${pageQuery(params)}`, { signal }); + return normalizePage(data); +} diff --git a/src/api/homework/index.ts b/src/api/homework/index.ts new file mode 100644 index 0000000..fe90506 --- /dev/null +++ b/src/api/homework/index.ts @@ -0,0 +1,16 @@ +export * from "./getHomework"; +export * from "./getHomeworkById"; +export * from "./patchHomeworkById"; +export * from "./deleteHomeworkById"; +export * from "./postHomeworkSubmission"; +export * from "./getHomeworkSubmission"; +export * from "./deleteHomeworkSubmission"; +export * from "./postHomeworkSubmissionFile"; +export * from "./getHomeworkSubmissionFileBlob"; +export * from "./getHomeworkSubmissionFileUrl"; +export * from "./deleteHomeworkSubmissionFile"; +export * from "./postHomeworkResult"; +export * from "./deleteHomeworkResultByUserId"; +export * from "./getHomeworkResult"; +export * from "./getHomeworkSubmissions"; +export * from "./getHomeworkReport"; diff --git a/src/api/homework/patchHomeworkById.ts b/src/api/homework/patchHomeworkById.ts new file mode 100644 index 0000000..0dfc073 --- /dev/null +++ b/src/api/homework/patchHomeworkById.ts @@ -0,0 +1,14 @@ +import { client } from "../client"; +import type { Homework } from "../client"; + +export type PatchHomeworkBody = { + title?: string; + description?: string | null; + due_at?: number; + subject_id?: string; + assigned?: string[] | null; +}; + +export function patchHomeworkById(id: string, body: PatchHomeworkBody): Promise { + return client(`/homework/${id}`, { method: "PATCH", body }); +} diff --git a/src/api/homework/postHomeworkResult.ts b/src/api/homework/postHomeworkResult.ts new file mode 100644 index 0000000..50faf8b --- /dev/null +++ b/src/api/homework/postHomeworkResult.ts @@ -0,0 +1,12 @@ +import { client } from "../client"; +import type { HomeworkResult } from "../client"; + +export type PostHomeworkResultBody = { + user: string; + status: string; + mark?: number | null; +}; + +export function postHomeworkResult(id: string, body: PostHomeworkResultBody): Promise { + return client(`/homework/${id}/results`, { method: "POST", body }); +} diff --git a/src/api/homework/postHomeworkSubmission.ts b/src/api/homework/postHomeworkSubmission.ts new file mode 100644 index 0000000..9ce1d62 --- /dev/null +++ b/src/api/homework/postHomeworkSubmission.ts @@ -0,0 +1,10 @@ +import { client } from "../client"; +import type { HomeworkSubmission } from "../client"; + +export type PostHomeworkSubmissionBody = { + text?: string | null; +}; + +export function postHomeworkSubmission(id: string, body: PostHomeworkSubmissionBody): Promise { + return client(`/homework/${id}/submission`, { method: "POST", body }); +} diff --git a/src/api/homework/postHomeworkSubmissionFile.ts b/src/api/homework/postHomeworkSubmissionFile.ts new file mode 100644 index 0000000..9319cac --- /dev/null +++ b/src/api/homework/postHomeworkSubmissionFile.ts @@ -0,0 +1,8 @@ +import { formClient } from "../client"; +import type { HomeworkFile } from "../client"; + +export function postHomeworkSubmissionFile(id: string, file: File, signal?: AbortSignal): Promise { + const body = new FormData(); + body.append("file", file); + return formClient(`/homework/${id}/submission/files`, body, signal); +} diff --git a/src/api/notes/getNoteById.ts b/src/api/notes/getNoteById.ts new file mode 100644 index 0000000..daa9e34 --- /dev/null +++ b/src/api/notes/getNoteById.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { Note } from "../client"; + +export function getNoteById(id: string, signal?: AbortSignal): Promise { + return client(`/notes/${id}`, { signal }); +} diff --git a/src/api/notes/index.ts b/src/api/notes/index.ts index a0bd567..e33e3bb 100644 --- a/src/api/notes/index.ts +++ b/src/api/notes/index.ts @@ -1,4 +1,5 @@ export * from "./getNotes"; +export * from "./getNoteById"; export * from "./postNote"; export * from "./patchNoteById"; export * from "./deleteNoteById"; diff --git a/src/api/sessions/deleteSessionAttendanceByUserId.ts b/src/api/sessions/deleteSessionAttendanceByUserId.ts new file mode 100644 index 0000000..85a0788 --- /dev/null +++ b/src/api/sessions/deleteSessionAttendanceByUserId.ts @@ -0,0 +1,5 @@ +import { client } from "../client"; + +export function deleteSessionAttendanceByUserId(id: string, userId: string): Promise { + return client(`/sessions/${id}/attendance/${userId}`, { method: "DELETE" }); +} diff --git a/src/api/sessions/getSessionById.ts b/src/api/sessions/getSessionById.ts new file mode 100644 index 0000000..2032660 --- /dev/null +++ b/src/api/sessions/getSessionById.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { CourseSession } from "../client"; + +export function getSessionById(id: string, signal?: AbortSignal): Promise { + return client(`/sessions/${id}`, { signal }); +} diff --git a/src/api/sessions/index.ts b/src/api/sessions/index.ts index af9c0fa..e04fbce 100644 --- a/src/api/sessions/index.ts +++ b/src/api/sessions/index.ts @@ -1,4 +1,6 @@ +export * from "./getSessionById"; export * from "./patchSessionById"; export * from "./deleteSessionById"; export * from "./getSessionAttendance"; export * from "./postSessionAttendance"; +export * from "./deleteSessionAttendanceByUserId"; diff --git a/src/api/subjects/getSubjectById.ts b/src/api/subjects/getSubjectById.ts new file mode 100644 index 0000000..4e7bf32 --- /dev/null +++ b/src/api/subjects/getSubjectById.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { Subject } from "../client"; + +export function getSubjectById(subjectId: string, signal?: AbortSignal): Promise { + return client(`/subjects/${subjectId}`, { signal }); +} diff --git a/src/api/subjects/index.ts b/src/api/subjects/index.ts index 859d78c..8e9c1f2 100644 --- a/src/api/subjects/index.ts +++ b/src/api/subjects/index.ts @@ -1,2 +1,3 @@ +export * from "./getSubjectById"; export * from "./patchSubjectById"; export * from "./deleteSubjectById"; diff --git a/src/api/terms/getTermById.ts b/src/api/terms/getTermById.ts new file mode 100644 index 0000000..cabd37c --- /dev/null +++ b/src/api/terms/getTermById.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { Term } from "../client"; + +export function getTermById(id: string, signal?: AbortSignal): Promise { + return client(`/terms/${id}`, { signal }); +} diff --git a/src/api/terms/index.ts b/src/api/terms/index.ts index d83d13b..9be7e09 100644 --- a/src/api/terms/index.ts +++ b/src/api/terms/index.ts @@ -1,4 +1,5 @@ export * from "./getTerms"; +export * from "./getTermById"; export * from "./postTerm"; export * from "./patchTermById"; export * from "./deleteTermById"; diff --git a/src/api/users/getUserById.ts b/src/api/users/getUserById.ts new file mode 100644 index 0000000..797d5c6 --- /dev/null +++ b/src/api/users/getUserById.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { User } from "../client"; + +export function getUserById(id: string, signal?: AbortSignal): Promise { + return client(`/users/${id}`, { signal }); +} diff --git a/src/api/users/index.ts b/src/api/users/index.ts index 1c5e8a6..9e40afe 100644 --- a/src/api/users/index.ts +++ b/src/api/users/index.ts @@ -1,7 +1,9 @@ export * from "./getMe"; export * from "./patchMe"; export * from "./getUsers"; +export * from "./getUserById"; export * from "./getUserSearch"; export * from "./patchUserProfile"; export * from "./patchUserRole"; export * from "./patchMyPreferences"; +export * from "./patchUserPreferences"; diff --git a/src/api/users/patchUserPreferences.ts b/src/api/users/patchUserPreferences.ts new file mode 100644 index 0000000..1caa128 --- /dev/null +++ b/src/api/users/patchUserPreferences.ts @@ -0,0 +1,7 @@ +import { client } from "../client"; +import type { PatchMyPreferencesBody } from "./patchMyPreferences"; +import type { User } from "../client"; + +export function patchUserPreferences(id: string, body: PatchMyPreferencesBody): Promise { + return client(`/users/${id}/preferences`, { method: "PATCH", body }); +}