forge
Explore
Log in

Don't you dare go Hollow

✨ add homework API coverage

Browse files at this commit

6d0e29c80cd0c1640ea46d5511133df11509b039Burak BoduroğluParent: 9d29927
  • feat
    • ✨ add homework API coverage
Show full message
feat: ✨ add homework API coverage

- 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.mdmodified+6 -8
@@ -173,13 +173,11 @@ Rules:
173 agent shows the user the exact proposed commit message (title + all bullets)173 agent shows the user the exact proposed commit message (title + all bullets)
174 and asks for **explicit approval**. `git commit` never runs before approval174 and asks for **explicit approval**. `git commit` never runs before approval
175 is given. This applies to every commit, including small ones — no exceptions.175 is given. This applies to every commit, including small ones — no exceptions.
176-- **Mandatory pre-commit check, every time:** once approved, right before176+- **Mandatory pre-commit check:** once approved, right before running the commit,
177- running the commit:177+ run `bun run build` (`tsc --noEmit && vite build`) unless a build has already
178- 1. Run `bun run build` (`tsc --noEmit && vite build`) — the project already has178+ passed since the last code change. If the user explicitly says not to run a
179- `noUnusedLocals` / `noUnusedParameters` enabled, so any unused import or179+ build for the current action, do not run it. If the build fails, remove the
180- variable fails the build.180+ unused imports/variables and re-run until it passes. Only commit once the build
181- 2. If the build fails, remove the unused imports/variables and re-run until181+ is green or the user explicitly waived the build for that action.
182- it passes.
183- 3. Only commit once the build is green.
184 - This workflow (format + approval + pre-commit check) applies always, without182 - This workflow (format + approval + pre-commit check) applies always, without
185 exception, to every commit in this repo.183 exception, to every commit in this repo.
src/api/__tests__/courses/courses.test.tsmodified+28 -0
@@ -15,6 +15,8 @@ import { getCourseExams } from "../../courses";
15 import { postCourseExam } from "../../courses";15 import { postCourseExam } from "../../courses";
16 import { postCourseTeacher } from "../../courses";16 import { postCourseTeacher } from "../../courses";
17 import { deleteCourseTeacherByUserId } from "../../courses";17 import { deleteCourseTeacherByUserId } from "../../courses";
18+import { getCourseHomework } from "../../courses";
19+import { postCourseHomework } from "../../courses";
18 import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";20 import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";
19 21
20 describe("courses API", () => {22 describe("courses API", () => {
@@ -220,4 +222,30 @@ describe("courses API", () => {
220 expect(init?.method).toBe("POST");222 expect(init?.method).toBe("POST");
221 expect(init?.body).toBe(JSON.stringify(data));223 expect(init?.body).toBe(JSON.stringify(data));
222 });224 });
225+
226+ it("getCourseHomework calls /courses/:id/homework", async () => {
227+ const mockPage = { items: [{ id: "hw1" }], total: 1 };
228+ mockFetchSuccess(mockPage);
229+
230+ const result = await getCourseHomework("c1", { limit: 5 });
231+ expect(result).toEqual({ ...mockPage, limit: null, offset: 0 });
232+
233+ const [url, init] = lastFetchCall();
234+ expect(url).toBe("/api/courses/c1/homework?limit=5");
235+ expect(init?.method).toBe("GET");
236+ });
237+
238+ it("postCourseHomework calls /courses/:id/homework", async () => {
239+ const mockHomework = { id: "hw1", course: "c1" };
240+ mockFetchSuccess(mockHomework);
241+
242+ const data = { title: "HW", subject_id: "sub1", due_at: 1900000000000, assigned: ["u1"] };
243+ const result = await postCourseHomework("c1", data);
244+ expect(result).toEqual(mockHomework);
245+
246+ const [url, init] = lastFetchCall();
247+ expect(url).toBe("/api/courses/c1/homework");
248+ expect(init?.method).toBe("POST");
249+ expect(init?.body).toBe(JSON.stringify(data));
250+ });
223 });251 });
src/api/__tests__/homework/homework.test.tsadded+210 -0
@@ -0,0 +1,210 @@
1+import { afterEach, describe, expect, it, vi } from "vitest";
2+import {
3+ deleteHomeworkById,
4+ deleteHomeworkResultByUserId,
5+ deleteHomeworkSubmission,
6+ deleteHomeworkSubmissionFile,
7+ getHomework,
8+ getHomeworkById,
9+ getHomeworkReport,
10+ getHomeworkResult,
11+ getHomeworkSubmission,
12+ getHomeworkSubmissionFileBlob,
13+ getHomeworkSubmissionFileUrl,
14+ getHomeworkSubmissions,
15+ patchHomeworkById,
16+ postHomeworkResult,
17+ postHomeworkSubmission,
18+ postHomeworkSubmissionFile,
19+} from "../../homework";
20+import { lastFetchCall, mockFetch204, mockFetchBlob, mockFetchSuccess } from "../helpers/mock-fetch";
21+
22+describe("homework API", () => {
23+ afterEach(() => {
24+ vi.restoreAllMocks();
25+ });
26+
27+ it("getHomework calls /homework with pagination", async () => {
28+ const mockPage = { items: [{ id: "hw1" }], total: 1 };
29+ mockFetchSuccess(mockPage);
30+
31+ const result = await getHomework({ limit: 10, offset: 5 });
32+ expect(result).toEqual({ ...mockPage, limit: null, offset: 0 });
33+
34+ const [url, init] = lastFetchCall();
35+ expect(url).toBe("/api/homework?limit=10&offset=5");
36+ expect(init?.method).toBe("GET");
37+ });
38+
39+ it("getHomeworkById calls /homework/:id", async () => {
40+ const mockHomework = { id: "hw1" };
41+ mockFetchSuccess(mockHomework);
42+
43+ const result = await getHomeworkById("hw1");
44+ expect(result).toEqual(mockHomework);
45+
46+ const [url, init] = lastFetchCall();
47+ expect(url).toBe("/api/homework/hw1");
48+ expect(init?.method).toBe("GET");
49+ });
50+
51+ it("patchHomeworkById calls /homework/:id", async () => {
52+ const mockHomework = { id: "hw1", title: "New" };
53+ mockFetchSuccess(mockHomework);
54+
55+ const body = { title: "New", assigned: null };
56+ const result = await patchHomeworkById("hw1", body);
57+ expect(result).toEqual(mockHomework);
58+
59+ const [url, init] = lastFetchCall();
60+ expect(url).toBe("/api/homework/hw1");
61+ expect(init?.method).toBe("PATCH");
62+ expect(init?.body).toBe(JSON.stringify(body));
63+ });
64+
65+ it("deleteHomeworkById calls /homework/:id", async () => {
66+ mockFetch204();
67+
68+ await deleteHomeworkById("hw1");
69+
70+ const [url, init] = lastFetchCall();
71+ expect(url).toBe("/api/homework/hw1");
72+ expect(init?.method).toBe("DELETE");
73+ });
74+
75+ it("postHomeworkSubmission calls /homework/:id/submission", async () => {
76+ const mockSubmission = { homework: "hw1", text: "Done" };
77+ mockFetchSuccess(mockSubmission);
78+
79+ const body = { text: "Done" };
80+ const result = await postHomeworkSubmission("hw1", body);
81+ expect(result).toEqual(mockSubmission);
82+
83+ const [url, init] = lastFetchCall();
84+ expect(url).toBe("/api/homework/hw1/submission");
85+ expect(init?.method).toBe("POST");
86+ expect(init?.body).toBe(JSON.stringify(body));
87+ });
88+
89+ it("getHomeworkSubmission calls /homework/:id/submission", async () => {
90+ const mockSubmission = { homework: "hw1" };
91+ mockFetchSuccess(mockSubmission);
92+
93+ const result = await getHomeworkSubmission("hw1");
94+ expect(result).toEqual(mockSubmission);
95+
96+ const [url, init] = lastFetchCall();
97+ expect(url).toBe("/api/homework/hw1/submission");
98+ expect(init?.method).toBe("GET");
99+ });
100+
101+ it("deleteHomeworkSubmission calls /homework/:id/submission", async () => {
102+ mockFetch204();
103+
104+ await deleteHomeworkSubmission("hw1");
105+
106+ const [url, init] = lastFetchCall();
107+ expect(url).toBe("/api/homework/hw1/submission");
108+ expect(init?.method).toBe("DELETE");
109+ });
110+
111+ it("postHomeworkSubmissionFile calls /homework/:id/submission/files with FormData", async () => {
112+ const mockFile = { id: "f1", name: "a.txt" };
113+ mockFetchSuccess(mockFile, 201);
114+
115+ const file = new File(["x"], "a.txt", { type: "text/plain" });
116+ const result = await postHomeworkSubmissionFile("hw1", file);
117+ expect(result).toEqual(mockFile);
118+
119+ const [url, init] = lastFetchCall();
120+ expect(url).toBe("/api/homework/hw1/submission/files");
121+ expect(init?.method).toBe("POST");
122+ expect(init?.body).toBeInstanceOf(FormData);
123+ });
124+
125+ it("getHomeworkSubmissionFileBlob calls /homework/:id/submission/files/:fid", async () => {
126+ const blob = new Blob(["x"], { type: "text/plain" });
127+ mockFetchBlob(blob);
128+
129+ const result = await getHomeworkSubmissionFileBlob("hw1", "f1");
130+ expect(result.type).toBe("text/plain");
131+
132+ const [url, init] = lastFetchCall();
133+ expect(url).toBe("/api/homework/hw1/submission/files/f1");
134+ expect(init?.credentials).toBe("same-origin");
135+ });
136+
137+ it("getHomeworkSubmissionFileUrl returns encoded URL", () => {
138+ expect(getHomeworkSubmissionFileUrl("hw/1", "f?1")).toBe("/api/homework/hw%2F1/submission/files/f%3F1");
139+ });
140+
141+ it("deleteHomeworkSubmissionFile calls /homework/:id/submission/files/:fid", async () => {
142+ mockFetch204();
143+
144+ await deleteHomeworkSubmissionFile("hw1", "f1");
145+
146+ const [url, init] = lastFetchCall();
147+ expect(url).toBe("/api/homework/hw1/submission/files/f1");
148+ expect(init?.method).toBe("DELETE");
149+ });
150+
151+ it("postHomeworkResult calls /homework/:id/results", async () => {
152+ const mockResult = { status: "done", mark: 95 };
153+ mockFetchSuccess(mockResult);
154+
155+ const body = { user: "u1", status: "done", mark: 95 };
156+ const result = await postHomeworkResult("hw1", body);
157+ expect(result).toEqual(mockResult);
158+
159+ const [url, init] = lastFetchCall();
160+ expect(url).toBe("/api/homework/hw1/results");
161+ expect(init?.method).toBe("POST");
162+ expect(init?.body).toBe(JSON.stringify(body));
163+ });
164+
165+ it("deleteHomeworkResultByUserId calls /homework/:id/results/:user", async () => {
166+ mockFetch204();
167+
168+ await deleteHomeworkResultByUserId("hw1", "u1");
169+
170+ const [url, init] = lastFetchCall();
171+ expect(url).toBe("/api/homework/hw1/results/u1");
172+ expect(init?.method).toBe("DELETE");
173+ });
174+
175+ it("getHomeworkResult calls /homework/:id/result", async () => {
176+ const mockResult = { status: "done" };
177+ mockFetchSuccess(mockResult);
178+
179+ const result = await getHomeworkResult("hw1");
180+ expect(result).toEqual(mockResult);
181+
182+ const [url, init] = lastFetchCall();
183+ expect(url).toBe("/api/homework/hw1/result");
184+ expect(init?.method).toBe("GET");
185+ });
186+
187+ it("getHomeworkSubmissions calls /homework/:id/submissions", async () => {
188+ const mockPage = { items: [{ user: "u1" }], total: 1 };
189+ mockFetchSuccess(mockPage);
190+
191+ const result = await getHomeworkSubmissions("hw1", { limit: 20 });
192+ expect(result).toEqual({ ...mockPage, limit: null, offset: 0 });
193+
194+ const [url, init] = lastFetchCall();
195+ expect(url).toBe("/api/homework/hw1/submissions?limit=20");
196+ expect(init?.method).toBe("GET");
197+ });
198+
199+ it("getHomeworkReport calls /homework/report/:user", async () => {
200+ const mockPage = { items: [{ homework: "hw1" }], total: 1 };
201+ mockFetchSuccess(mockPage);
202+
203+ const result = await getHomeworkReport("u1", { offset: 10 });
204+ expect(result).toEqual({ ...mockPage, limit: null, offset: 0 });
205+
206+ const [url, init] = lastFetchCall();
207+ expect(url).toBe("/api/homework/report/u1?offset=10");
208+ expect(init?.method).toBe("GET");
209+ });
210+});
src/api/__tests__/notes/notes.test.tsmodified+13 -0
@@ -1,5 +1,6 @@
1 import { afterEach, describe, expect, it, vi } from "vitest";1 import { afterEach, describe, expect, it, vi } from "vitest";
2 import { getNotes } from "../../notes";2 import { getNotes } from "../../notes";
3+import { getNoteById } from "../../notes";
3 import { postNote } from "../../notes";4 import { postNote } from "../../notes";
4 import { patchNoteById } from "../../notes";5 import { patchNoteById } from "../../notes";
5 import { deleteNoteById } from "../../notes";6 import { deleteNoteById } from "../../notes";
@@ -41,6 +42,18 @@ describe("notes API", () => {
41 expect(init?.body).toBe(JSON.stringify(data));42 expect(init?.body).toBe(JSON.stringify(data));
42 });43 });
43 44
45+ it("getNoteById calls /notes/:id", async () => {
46+ const mockNote = { id: "n1", title: "Note", content: "Content" };
47+ mockFetchSuccess(mockNote);
48+
49+ const result = await getNoteById("n1");
50+ expect(result).toEqual(mockNote);
51+
52+ const [url, init] = lastFetchCall();
53+ expect(url).toBe("/api/notes/n1");
54+ expect(init?.method).toBe("GET");
55+ });
56+
44 it("patchNoteById calls /notes/:id with updates", async () => {57 it("patchNoteById calls /notes/:id with updates", async () => {
45 const mockNote = { id: "n1", title: "Updated", content: "Content" };58 const mockNote = { id: "n1", title: "Updated", content: "Content" };
46 mockFetchSuccess(mockNote);59 mockFetchSuccess(mockNote);
src/api/__tests__/sessions/sessions.test.tsmodified+24 -0
@@ -1,8 +1,10 @@
1 import { afterEach, describe, expect, it, vi } from "vitest";1 import { afterEach, describe, expect, it, vi } from "vitest";
2+import { getSessionById } from "../../sessions";
2 import { patchSessionById } from "../../sessions";3 import { patchSessionById } from "../../sessions";
3 import { deleteSessionById } from "../../sessions";4 import { deleteSessionById } from "../../sessions";
4 import { getSessionAttendance } from "../../sessions";5 import { getSessionAttendance } from "../../sessions";
5 import { postSessionAttendance } from "../../sessions";6 import { postSessionAttendance } from "../../sessions";
7+import { deleteSessionAttendanceByUserId } from "../../sessions";
6 import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";8 import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";
7 9
8 describe("sessions API", () => {10 describe("sessions API", () => {
@@ -10,6 +12,18 @@ describe("sessions API", () => {
10 vi.restoreAllMocks();12 vi.restoreAllMocks();
11 });13 });
12 14
15+ it("getSessionById calls /sessions/:id", async () => {
16+ const mockSession = { id: "s1", topic: "Topic" };
17+ mockFetchSuccess(mockSession);
18+
19+ const result = await getSessionById("s1");
20+ expect(result).toEqual(mockSession);
21+
22+ const [url, init] = lastFetchCall();
23+ expect(url).toBe("/api/sessions/s1");
24+ expect(init?.method).toBe("GET");
25+ });
26+
13 it("patchSessionById calls /sessions/:id with updates", async () => {27 it("patchSessionById calls /sessions/:id with updates", async () => {
14 const mockSession = { id: "s1", topic: "Updated" };28 const mockSession = { id: "s1", topic: "Updated" };
15 mockFetchSuccess(mockSession);29 mockFetchSuccess(mockSession);
@@ -59,4 +73,14 @@ describe("sessions API", () => {
59 expect(init?.method).toBe("POST");73 expect(init?.method).toBe("POST");
60 expect(init?.body).toBe(JSON.stringify(data));74 expect(init?.body).toBe(JSON.stringify(data));
61 });75 });
76+
77+ it("deleteSessionAttendanceByUserId calls /sessions/:id/attendance/:user", async () => {
78+ mockFetch204();
79+
80+ await deleteSessionAttendanceByUserId("s1", "u1");
81+
82+ const [url, init] = lastFetchCall();
83+ expect(url).toBe("/api/sessions/s1/attendance/u1");
84+ expect(init?.method).toBe("DELETE");
85+ });
62 });86 });
src/api/__tests__/subjects/subjects.test.tsmodified+13 -0
@@ -1,4 +1,5 @@
1 import { afterEach, describe, expect, it, vi } from "vitest";1 import { afterEach, describe, expect, it, vi } from "vitest";
2+import { getSubjectById } from "../../subjects";
2 import { patchSubjectById } from "../../subjects";3 import { patchSubjectById } from "../../subjects";
3 import { deleteSubjectById } from "../../subjects";4 import { deleteSubjectById } from "../../subjects";
4 import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";5 import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";
@@ -8,6 +9,18 @@ describe("subjects API", () => {
8 vi.restoreAllMocks();9 vi.restoreAllMocks();
9 });10 });
10 11
12+ it("getSubjectById calls /subjects/:id", async () => {
13+ const mockSubject = { id: "sub1", name: "Subject" };
14+ mockFetchSuccess(mockSubject);
15+
16+ const result = await getSubjectById("sub1");
17+ expect(result).toEqual(mockSubject);
18+
19+ const [url, init] = lastFetchCall();
20+ expect(url).toBe("/api/subjects/sub1");
21+ expect(init?.method).toBe("GET");
22+ });
23+
11 it("patchSubjectById calls /subjects/:id with updates", async () => {24 it("patchSubjectById calls /subjects/:id with updates", async () => {
12 const mockSubject = { id: "sub1", name: "Updated" };25 const mockSubject = { id: "sub1", name: "Updated" };
13 mockFetchSuccess(mockSubject);26 mockFetchSuccess(mockSubject);
src/api/__tests__/terms/terms.test.tsmodified+13 -0
@@ -1,5 +1,6 @@
1 import { afterEach, describe, expect, it, vi } from "vitest";1 import { afterEach, describe, expect, it, vi } from "vitest";
2 import { getTerms } from "../../terms";2 import { getTerms } from "../../terms";
3+import { getTermById } from "../../terms";
3 import { postTerm } from "../../terms";4 import { postTerm } from "../../terms";
4 import { patchTermById } from "../../terms";5 import { patchTermById } from "../../terms";
5 import { deleteTermById } from "../../terms";6 import { deleteTermById } from "../../terms";
@@ -36,6 +37,18 @@ describe("terms API", () => {
36 expect(init?.body).toBe(JSON.stringify(data));37 expect(init?.body).toBe(JSON.stringify(data));
37 });38 });
38 39
40+ it("getTermById calls /terms/:id", async () => {
41+ const mockTerm = { id: "t1", name: "Term 1" };
42+ mockFetchSuccess(mockTerm);
43+
44+ const result = await getTermById("t1");
45+ expect(result).toEqual(mockTerm);
46+
47+ const [url, init] = lastFetchCall();
48+ expect(url).toBe("/api/terms/t1");
49+ expect(init?.method).toBe("GET");
50+ });
51+
39 it("patchTermById calls /terms/:id with updates", async () => {52 it("patchTermById calls /terms/:id with updates", async () => {
40 const mockTerm = { id: "t1", name: "Updated" };53 const mockTerm = { id: "t1", name: "Updated" };
41 mockFetchSuccess(mockTerm);54 mockFetchSuccess(mockTerm);
src/api/__tests__/users/users.test.tsmodified+28 -0
@@ -2,10 +2,12 @@ import { afterEach, describe, expect, it, vi } from "vitest";
2 import { getMe } from "../../users";2 import { getMe } from "../../users";
3 import { patchMe } from "../../users";3 import { patchMe } from "../../users";
4 import { getUsers } from "../../users";4 import { getUsers } from "../../users";
5+import { getUserById } from "../../users";
5 import { getUserSearch } from "../../users";6 import { getUserSearch } from "../../users";
6 import { patchUserProfile } from "../../users";7 import { patchUserProfile } from "../../users";
7 import { patchUserRole } from "../../users";8 import { patchUserRole } from "../../users";
8 import { patchMyPreferences } from "../../users";9 import { patchMyPreferences } from "../../users";
10+import { patchUserPreferences } from "../../users";
9 import { lastFetchCall, mockFetchSuccess } from "../helpers/mock-fetch";11 import { lastFetchCall, mockFetchSuccess } from "../helpers/mock-fetch";
10 12
11 describe("users API", () => {13 describe("users API", () => {
@@ -63,6 +65,18 @@ describe("users API", () => {
63 expect(init?.method).toBe("GET");65 expect(init?.method).toBe("GET");
64 });66 });
65 67
68+ it("getUserById calls /users/:id", async () => {
69+ const mockUser = { id: "u1", username: "test" };
70+ mockFetchSuccess(mockUser);
71+
72+ const result = await getUserById("u1");
73+ expect(result).toEqual(mockUser);
74+
75+ const [url, init] = lastFetchCall();
76+ expect(url).toBe("/api/users/u1");
77+ expect(init?.method).toBe("GET");
78+ });
79+
66 it("patchUserProfile calls /users/:id/profile", async () => {80 it("patchUserProfile calls /users/:id/profile", async () => {
67 const mockUser = { id: "u1", name: "Updated" };81 const mockUser = { id: "u1", name: "Updated" };
68 mockFetchSuccess(mockUser);82 mockFetchSuccess(mockUser);
@@ -103,4 +117,18 @@ describe("users API", () => {
103 expect(init?.method).toBe("PATCH");117 expect(init?.method).toBe("PATCH");
104 expect(init?.body).toBe(JSON.stringify(updates));118 expect(init?.body).toBe(JSON.stringify(updates));
105 });119 });
120+
121+ it("patchUserPreferences calls /users/:id/preferences", async () => {
122+ const mockUser = { id: "u1", language: "tr" };
123+ mockFetchSuccess(mockUser);
124+
125+ const updates = { language: "tr" as const };
126+ const result = await patchUserPreferences("u1", updates);
127+ expect(result).toEqual(mockUser);
128+
129+ const [url, init] = lastFetchCall();
130+ expect(url).toBe("/api/users/u1/preferences");
131+ expect(init?.method).toBe("PATCH");
132+ expect(init?.body).toBe(JSON.stringify(updates));
133+ });
106 });134 });
src/api/client/types.tsmodified+61 -0
@@ -390,3 +390,64 @@ export type Message = {
390 folder: MessageFolder;390 folder: MessageFolder;
391 label: string | null;391 label: string | null;
392 };392 };
393+
394+export type Homework = {
395+ id: string;
396+ course: string;
397+ subject: string;
398+ title: string;
399+ description: string | null;
400+ due_at: number;
401+ assigned: string[] | null;
402+ created_by: string;
403+ created_at: number;
404+};
405+
406+export type HomeworkFile = {
407+ id: string;
408+ name: string;
409+ content_type: string;
410+ size: number;
411+};
412+
413+export type HomeworkResultStatus = "done" | "incomplete" | "missing" | string;
414+
415+export type HomeworkResult = {
416+ status: HomeworkResultStatus;
417+ mark: number | null;
418+ graded_by: string;
419+ created_at: number;
420+};
421+
422+export type HomeworkSubmission = {
423+ user: string;
424+ homework: string;
425+ text: string | null;
426+ submitted_at: number;
427+ updated_at: number;
428+ late: boolean;
429+ files: HomeworkFile[];
430+ result: HomeworkResult | null;
431+};
432+
433+export type HomeworkRosterSubmission = Omit<HomeworkSubmission, "user" | "homework" | "result">;
434+
435+export type HomeworkRosterEntry = {
436+ user: string;
437+ submission: HomeworkRosterSubmission | null;
438+ result: HomeworkResult | null;
439+ missing: boolean;
440+ unenrolled: boolean;
441+};
442+
443+export type HomeworkReportEntry = {
444+ course: string;
445+ homework: string;
446+ title: string;
447+ subject: string;
448+ due_at: number;
449+ submitted: boolean;
450+ late: boolean;
451+ missing: boolean;
452+ result: HomeworkResult | null;
453+};
src/api/courses/getCourseHomework.tsadded+12 -0
@@ -0,0 +1,12 @@
1+import { client } from "../client";
2+import { normalizePage, pageQuery, type Page, type PageParams } from "../client";
3+import type { Homework } from "../client";
4+
5+export async function getCourseHomework(
6+ courseId: string,
7+ params?: PageParams,
8+ signal?: AbortSignal,
9+): Promise<Page<Homework>> {
10+ const data = await client<unknown>(`/courses/${courseId}/homework${pageQuery(params)}`, { signal });
11+ return normalizePage<Homework>(data);
12+}
src/api/courses/index.tsmodified+2 -0
@@ -14,4 +14,6 @@ export * from "./getCourseExams";
14 export * from "./postCourseExam";14 export * from "./postCourseExam";
15 export * from "./postCourseTeacher";15 export * from "./postCourseTeacher";
16 export * from "./deleteCourseTeacherByUserId";16 export * from "./deleteCourseTeacherByUserId";
17+export * from "./getCourseHomework";
18+export * from "./postCourseHomework";
17 19
src/api/courses/postCourseHomework.tsadded+14 -0
@@ -0,0 +1,14 @@
1+import { client } from "../client";
2+import type { Homework } from "../client";
3+
4+export type PostCourseHomeworkBody = {
5+ title: string;
6+ description?: string | null;
7+ subject_id: string;
8+ due_at: number;
9+ assigned?: string[] | null;
10+};
11+
12+export function postCourseHomework(courseId: string, body: PostCourseHomeworkBody): Promise<Homework> {
13+ return client<Homework>(`/courses/${courseId}/homework`, { method: "POST", body });
14+}
src/api/homework/deleteHomeworkById.tsadded+5 -0
@@ -0,0 +1,5 @@
1+import { client } from "../client";
2+
3+export function deleteHomeworkById(id: string): Promise<void> {
4+ return client<void>(`/homework/${id}`, { method: "DELETE" });
5+}
src/api/homework/deleteHomeworkResultByUserId.tsadded+5 -0
@@ -0,0 +1,5 @@
1+import { client } from "../client";
2+
3+export function deleteHomeworkResultByUserId(id: string, userId: string): Promise<void> {
4+ return client<void>(`/homework/${id}/results/${userId}`, { method: "DELETE" });
5+}
src/api/homework/deleteHomeworkSubmission.tsadded+5 -0
@@ -0,0 +1,5 @@
1+import { client } from "../client";
2+
3+export function deleteHomeworkSubmission(id: string): Promise<void> {
4+ return client<void>(`/homework/${id}/submission`, { method: "DELETE" });
5+}
src/api/homework/deleteHomeworkSubmissionFile.tsadded+5 -0
@@ -0,0 +1,5 @@
1+import { client } from "../client";
2+
3+export function deleteHomeworkSubmissionFile(id: string, fileId: string): Promise<void> {
4+ return client<void>(`/homework/${id}/submission/files/${fileId}`, { method: "DELETE" });
5+}
src/api/homework/getHomework.tsadded+8 -0
@@ -0,0 +1,8 @@
1+import { client } from "../client";
2+import { normalizePage, pageQuery, type Page, type PageParams } from "../client";
3+import type { Homework } from "../client";
4+
5+export async function getHomework(params?: PageParams, signal?: AbortSignal): Promise<Page<Homework>> {
6+ const data = await client<unknown>(`/homework${pageQuery(params)}`, { signal });
7+ return normalizePage<Homework>(data);
8+}
src/api/homework/getHomeworkById.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { Homework } from "../client";
3+
4+export function getHomeworkById(id: string, signal?: AbortSignal): Promise<Homework> {
5+ return client<Homework>(`/homework/${id}`, { signal });
6+}
src/api/homework/getHomeworkReport.tsadded+12 -0
@@ -0,0 +1,12 @@
1+import { client } from "../client";
2+import { normalizePage, pageQuery, type Page, type PageParams } from "../client";
3+import type { HomeworkReportEntry } from "../client";
4+
5+export async function getHomeworkReport(
6+ userId: string,
7+ params?: PageParams,
8+ signal?: AbortSignal,
9+): Promise<Page<HomeworkReportEntry>> {
10+ const data = await client<unknown>(`/homework/report/${userId}${pageQuery(params)}`, { signal });
11+ return normalizePage<HomeworkReportEntry>(data);
12+}
src/api/homework/getHomeworkResult.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { HomeworkResult } from "../client";
3+
4+export function getHomeworkResult(id: string, signal?: AbortSignal): Promise<HomeworkResult> {
5+ return client<HomeworkResult>(`/homework/${id}/result`, { signal });
6+}
src/api/homework/getHomeworkSubmission.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { HomeworkSubmission } from "../client";
3+
4+export function getHomeworkSubmission(id: string, signal?: AbortSignal): Promise<HomeworkSubmission> {
5+ return client<HomeworkSubmission>(`/homework/${id}/submission`, { signal });
6+}
src/api/homework/getHomeworkSubmissionFileBlob.tsadded+5 -0
@@ -0,0 +1,5 @@
1+import { blobClient } from "../client";
2+
3+export function getHomeworkSubmissionFileBlob(id: string, fileId: string, signal?: AbortSignal): Promise<Blob> {
4+ return blobClient(`/homework/${id}/submission/files/${fileId}`, signal);
5+}
src/api/homework/getHomeworkSubmissionFileUrl.tsadded+3 -0
@@ -0,0 +1,3 @@
1+export function getHomeworkSubmissionFileUrl(id: string, fileId: string): string {
2+ return `/api/homework/${encodeURIComponent(id)}/submission/files/${encodeURIComponent(fileId)}`;
3+}
src/api/homework/getHomeworkSubmissions.tsadded+12 -0
@@ -0,0 +1,12 @@
1+import { client } from "../client";
2+import { normalizePage, pageQuery, type Page, type PageParams } from "../client";
3+import type { HomeworkRosterEntry } from "../client";
4+
5+export async function getHomeworkSubmissions(
6+ id: string,
7+ params?: PageParams,
8+ signal?: AbortSignal,
9+): Promise<Page<HomeworkRosterEntry>> {
10+ const data = await client<unknown>(`/homework/${id}/submissions${pageQuery(params)}`, { signal });
11+ return normalizePage<HomeworkRosterEntry>(data);
12+}
src/api/homework/index.tsadded+16 -0
@@ -0,0 +1,16 @@
1+export * from "./getHomework";
2+export * from "./getHomeworkById";
3+export * from "./patchHomeworkById";
4+export * from "./deleteHomeworkById";
5+export * from "./postHomeworkSubmission";
6+export * from "./getHomeworkSubmission";
7+export * from "./deleteHomeworkSubmission";
8+export * from "./postHomeworkSubmissionFile";
9+export * from "./getHomeworkSubmissionFileBlob";
10+export * from "./getHomeworkSubmissionFileUrl";
11+export * from "./deleteHomeworkSubmissionFile";
12+export * from "./postHomeworkResult";
13+export * from "./deleteHomeworkResultByUserId";
14+export * from "./getHomeworkResult";
15+export * from "./getHomeworkSubmissions";
16+export * from "./getHomeworkReport";
src/api/homework/patchHomeworkById.tsadded+14 -0
@@ -0,0 +1,14 @@
1+import { client } from "../client";
2+import type { Homework } from "../client";
3+
4+export type PatchHomeworkBody = {
5+ title?: string;
6+ description?: string | null;
7+ due_at?: number;
8+ subject_id?: string;
9+ assigned?: string[] | null;
10+};
11+
12+export function patchHomeworkById(id: string, body: PatchHomeworkBody): Promise<Homework> {
13+ return client<Homework>(`/homework/${id}`, { method: "PATCH", body });
14+}
src/api/homework/postHomeworkResult.tsadded+12 -0
@@ -0,0 +1,12 @@
1+import { client } from "../client";
2+import type { HomeworkResult } from "../client";
3+
4+export type PostHomeworkResultBody = {
5+ user: string;
6+ status: string;
7+ mark?: number | null;
8+};
9+
10+export function postHomeworkResult(id: string, body: PostHomeworkResultBody): Promise<HomeworkResult> {
11+ return client<HomeworkResult>(`/homework/${id}/results`, { method: "POST", body });
12+}
src/api/homework/postHomeworkSubmission.tsadded+10 -0
@@ -0,0 +1,10 @@
1+import { client } from "../client";
2+import type { HomeworkSubmission } from "../client";
3+
4+export type PostHomeworkSubmissionBody = {
5+ text?: string | null;
6+};
7+
8+export function postHomeworkSubmission(id: string, body: PostHomeworkSubmissionBody): Promise<HomeworkSubmission> {
9+ return client<HomeworkSubmission>(`/homework/${id}/submission`, { method: "POST", body });
10+}
src/api/homework/postHomeworkSubmissionFile.tsadded+8 -0
@@ -0,0 +1,8 @@
1+import { formClient } from "../client";
2+import type { HomeworkFile } from "../client";
3+
4+export function postHomeworkSubmissionFile(id: string, file: File, signal?: AbortSignal): Promise<HomeworkFile> {
5+ const body = new FormData();
6+ body.append("file", file);
7+ return formClient<HomeworkFile>(`/homework/${id}/submission/files`, body, signal);
8+}
src/api/notes/getNoteById.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { Note } from "../client";
3+
4+export function getNoteById(id: string, signal?: AbortSignal): Promise<Note> {
5+ return client<Note>(`/notes/${id}`, { signal });
6+}
src/api/notes/index.tsmodified+1 -0
@@ -1,4 +1,5 @@
1 export * from "./getNotes";1 export * from "./getNotes";
2+export * from "./getNoteById";
2 export * from "./postNote";3 export * from "./postNote";
3 export * from "./patchNoteById";4 export * from "./patchNoteById";
4 export * from "./deleteNoteById";5 export * from "./deleteNoteById";
src/api/sessions/deleteSessionAttendanceByUserId.tsadded+5 -0
@@ -0,0 +1,5 @@
1+import { client } from "../client";
2+
3+export function deleteSessionAttendanceByUserId(id: string, userId: string): Promise<void> {
4+ return client<void>(`/sessions/${id}/attendance/${userId}`, { method: "DELETE" });
5+}
src/api/sessions/getSessionById.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { CourseSession } from "../client";
3+
4+export function getSessionById(id: string, signal?: AbortSignal): Promise<CourseSession> {
5+ return client<CourseSession>(`/sessions/${id}`, { signal });
6+}
src/api/sessions/index.tsmodified+2 -0
@@ -1,4 +1,6 @@
1+export * from "./getSessionById";
1 export * from "./patchSessionById";2 export * from "./patchSessionById";
2 export * from "./deleteSessionById";3 export * from "./deleteSessionById";
3 export * from "./getSessionAttendance";4 export * from "./getSessionAttendance";
4 export * from "./postSessionAttendance";5 export * from "./postSessionAttendance";
6+export * from "./deleteSessionAttendanceByUserId";
src/api/subjects/getSubjectById.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { Subject } from "../client";
3+
4+export function getSubjectById(subjectId: string, signal?: AbortSignal): Promise<Subject> {
5+ return client<Subject>(`/subjects/${subjectId}`, { signal });
6+}
src/api/subjects/index.tsmodified+1 -0
@@ -1,2 +1,3 @@
1+export * from "./getSubjectById";
1 export * from "./patchSubjectById";2 export * from "./patchSubjectById";
2 export * from "./deleteSubjectById";3 export * from "./deleteSubjectById";
src/api/terms/getTermById.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { Term } from "../client";
3+
4+export function getTermById(id: string, signal?: AbortSignal): Promise<Term> {
5+ return client<Term>(`/terms/${id}`, { signal });
6+}
src/api/terms/index.tsmodified+1 -0
@@ -1,4 +1,5 @@
1 export * from "./getTerms";1 export * from "./getTerms";
2+export * from "./getTermById";
2 export * from "./postTerm";3 export * from "./postTerm";
3 export * from "./patchTermById";4 export * from "./patchTermById";
4 export * from "./deleteTermById";5 export * from "./deleteTermById";
src/api/users/getUserById.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { User } from "../client";
3+
4+export function getUserById(id: string, signal?: AbortSignal): Promise<User> {
5+ return client<User>(`/users/${id}`, { signal });
6+}
src/api/users/index.tsmodified+2 -0
@@ -1,7 +1,9 @@
1 export * from "./getMe";1 export * from "./getMe";
2 export * from "./patchMe";2 export * from "./patchMe";
3 export * from "./getUsers";3 export * from "./getUsers";
4+export * from "./getUserById";
4 export * from "./getUserSearch";5 export * from "./getUserSearch";
5 export * from "./patchUserProfile";6 export * from "./patchUserProfile";
6 export * from "./patchUserRole";7 export * from "./patchUserRole";
7 export * from "./patchMyPreferences";8 export * from "./patchMyPreferences";
9+export * from "./patchUserPreferences";
src/api/users/patchUserPreferences.tsadded+7 -0
@@ -0,0 +1,7 @@
1+import { client } from "../client";
2+import type { PatchMyPreferencesBody } from "./patchMyPreferences";
3+import type { User } from "../client";
4+
5+export function patchUserPreferences(id: string, body: PatchMyPreferencesBody): Promise<User> {
6+ return client<User>(`/users/${id}/preferences`, { method: "PATCH", body });
7+}