forge
Explore
Log in

Don't you dare go Hollow

🔌 sync with the latest backend contract

Browse files at this commit

2c19dff2e78f0c31ff658b5525d64c404fb78f51Burak BoduroğluParent: 211d704
  • feat
    • 🔌 sync with the latest backend contract
Show full message
feat: 🔌 sync with the latest backend contract

- POST /users: admin creates an account directly (postUser, CreateUserInput)
- profiles carry a branş: shown beside the role badge, and a teacher+ picks it
  from settings.branches in the profile form
- class members expose their stint (joined_at, left_at) and the şube a
  rollover copied them from
- limits gain academic-year name length, the ders_saati bounds and the rag
  rate tier
- chatbotStreamUrl joins the api layer; the çelebi panel stops building the
  SSE path inline
src/api/__tests__/chatbot/chatbot.test.tsmodified+4 -1
@@ -1,5 +1,5 @@
11 import { afterEach, describe, expect, it, vi } from "vitest";
2-import { deleteChatbotThreadById, getChatbotMessageById, getChatbotThreadMessages, getChatbotThreads, patchChatbotThreadById, postChatbotMessage, postChatbotThread } from "../../chatbot";
2+import { chatbotStreamUrl, deleteChatbotThreadById, getChatbotMessageById, getChatbotThreadMessages, getChatbotThreads, patchChatbotThreadById, postChatbotMessage, postChatbotThread } from "../../chatbot";
33 import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";
44
55 describe("chatbot API", () => {
@@ -38,4 +38,7 @@ describe("chatbot API", () => {
3838 expect(url).toBe("/api/chatbot/threads/thread-1/messages/answer-1");
3939 expect(init?.method).toBe("GET");
4040 });
41+ it("chatbotStreamUrl builds the SSE path for an EventSource", () => {
42+ expect(chatbotStreamUrl("t 1", "m1")).toBe("/api/chatbot/threads/t%201/messages/m1/stream");
43+ });
4144 });
src/api/__tests__/users/users.test.tsmodified+14 -0
@@ -14,6 +14,7 @@ import { postMyAvatar } from "../../users";
1414 import { deleteMyAvatar } from "../../users";
1515 import { deleteUserAvatar } from "../../users";
1616 import { getUserAvatarUrl } from "../../users";
17+import { postUser } from "../../users";
1718 import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";
1819
1920 describe("users API", () => {
@@ -214,4 +215,17 @@ describe("users API", () => {
214215 expect(getUserAvatarUrl("u1", 3)).toBe("/api/users/u1/avatar?v=3");
215216 expect(getUserAvatarUrl("u/1")).toBe("/api/users/u%2F1/avatar");
216217 });
218+ it("postUser posts the new account to /users", async () => {
219+ const mockUser = { id: "u9", username: "ayse", role: "teacher" };
220+ mockFetchSuccess(mockUser);
221+
222+ const body = { username: "ayse", password: "secret123", role: "teacher" as const };
223+ const result = await postUser(body);
224+ expect(result).toEqual(mockUser);
225+
226+ const [url, init] = lastFetchCall();
227+ expect(url).toBe("/api/users");
228+ expect(init?.method).toBe("POST");
229+ expect(JSON.parse(init?.body as string)).toEqual(body);
230+ });
217231 });
src/api/chatbot/chatbotStreamUrl.tsadded+7 -0
@@ -0,0 +1,7 @@
1+/**
2+ * The SSE URL for one pending turn: `delta` chunks, then one `done` or
3+ * `error`. Not a request — hand it to an `EventSource` (`withCredentials: true`).
4+ */
5+export function chatbotStreamUrl(threadId: string, messageId: string): string {
6+ return `/api/chatbot/threads/${encodeURIComponent(threadId)}/messages/${encodeURIComponent(messageId)}/stream`;
7+}
src/api/chatbot/index.tsmodified+1 -0
@@ -5,4 +5,5 @@ export * from "./patchChatbotThreadById";
55 export * from "./deleteChatbotThreadById";
66 export * from "./postChatbotMessage";
77 export * from "./postChatbotThread";
8+export * from "./chatbotStreamUrl";
89 export * from "./types";
src/api/client/types.tsmodified+23 -1
@@ -38,6 +38,17 @@ export type ProfileUpdate = {
3838 birth_date?: string | null;
3939 display_name?: string | null;
4040 bio?: string | null;
41+ // The teacher's branş, by name from settings.branches.
42+ branch?: string | null;
43+};
44+
45+// POST /users (admin): the school office opens an account directly. `role`
46+// defaults to student on the server; an existing person joins this school only
47+// when the password matches their credential (409 otherwise).
48+export type CreateUserInput = {
49+ username: string;
50+ password: string;
51+ role?: Role;
4152 };
4253
4354 export type PersonRef = {
@@ -105,6 +116,8 @@ export type Profile = {
105116 display_name: string | null;
106117 role: Role;
107118 bio: string | null;
119+ // The teacher's branş, one of settings.branches; null when unset.
120+ branch: string | null;
108121 avatar: AvatarMeta | null;
109122 // Capped at limits.user.max_profile_classes; stats.classes holds the true total.
110123 classes: ProfileClassRef[];
@@ -395,6 +408,12 @@ export type ClassMember = {
395408 class: string;
396409 user: PersonRef;
397410 added_by: PersonRef;
411+ // One stint: a leave-and-rejoin is a fresh row with a fresh id.
412+ joined_at: number;
413+ // Null while the stint is live; the roster routes only list live rows.
414+ left_at: number | null;
415+ // The şube a year rollover copied this member out of; null when placed by hand.
416+ source_class_group: string | null;
398417 };
399418
400419 // The instance as the class routes return it: an Instance plus who attached
@@ -833,6 +852,9 @@ export type Limits = {
833852 max_class_grade_len: number;
834853 max_class_members: number;
835854 max_class_courses: number;
855+ max_academic_year_name_len: number;
856+ min_ders_saati: number;
857+ max_ders_saati: number;
836858 };
837859 exam: {
838860 max_title_len: number;
@@ -934,7 +956,7 @@ export type Limits = {
934956 required_attendance_statuses: string[];
935957 };
936958 request: { max_page_limit: number; max_request_id_len: number; schedule_past_grace_ms: number; request_timeout_secs: number };
937- rate: { window_secs: number; auth_per_minute: number; api_per_minute: number; chatbot_per_minute: number };
959+ rate: { window_secs: number; auth_per_minute: number; api_per_minute: number; chatbot_per_minute: number; rag_per_minute: number };
938960 // The RAG nest. Message length, thread titles, history depth and the thread
939961 // cap are the chatbot's own knobs, republished so a RAG client need not read
940962 // the chatbot group to bound its input.
src/api/users/index.tsmodified+1 -0
@@ -13,3 +13,4 @@ export * from "./postMyAvatar";
1313 export * from "./deleteMyAvatar";
1414 export * from "./deleteUserAvatar";
1515 export * from "./getUserAvatarUrl";
16+export * from "./postUser";
src/api/users/postUser.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { CreateUserInput, User } from "../client";
3+
4+export function postUser(body: CreateUserInput): Promise<User> {
5+ return client<User>("/users", { method: "POST", body });
6+}
src/components/layout/celebi-panel.tsxmodified+2 -2
@@ -1,6 +1,6 @@
11 import { For, Match, Show, Switch, createEffect, createSignal, on, onCleanup, untrack } from "solid-js";
22 import { useNavigate } from "@tanstack/solid-router";
3-import { deleteChatbotThreadById, getChatbotMessageById, getChatbotThreadMessages, getChatbotThreads, patchChatbotThreadById, postChatbotMessage, postChatbotThread, type ChatbotMessage, type ChatbotThread } from "@/api/chatbot";
3+import { chatbotStreamUrl, deleteChatbotThreadById, getChatbotMessageById, getChatbotThreadMessages, getChatbotThreads, patchChatbotThreadById, postChatbotMessage, postChatbotThread, type ChatbotMessage, type ChatbotThread } from "@/api/chatbot";
44 import { formatApiError } from "@/api/client";
55 import { CelebiComposer } from "@/components/layout/celebi-composer";
66 import { CelebiMarkdown } from "@/components/layout/celebi-markdown";
@@ -217,7 +217,7 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean
217217
218218 const streamAnswer = (activeThreadId: string, messageId: string) => {
219219 stopStream();
220- const source = new EventSource(`/api/chatbot/threads/${encodeURIComponent(activeThreadId)}/messages/${encodeURIComponent(messageId)}/stream`, { withCredentials: true });
220+ const source = new EventSource(chatbotStreamUrl(activeThreadId, messageId), { withCredentials: true });
221221 stream = source;
222222 source.addEventListener("delta", (event) => { try { const data = JSON.parse((event as MessageEvent).data) as { text?: unknown }; if (typeof data.text === "string") setMessages((items) => items.map((item) => item.id === messageId ? { ...item, content: item.content + data.text } : item)); } catch { /* ignore malformed chunk */ } });
223223 source.addEventListener("done", (event) => { try { updateAssistant((JSON.parse((event as MessageEvent).data) as { message: ChatbotMessage }).message); } catch { poll(activeThreadId, messageId); } finally { stopStream(); void loadThreads(); } });
src/components/users/profile-form.tsxmodified+25 -2
@@ -1,4 +1,4 @@
1-import { Show, createSignal } from "solid-js";
1+import { For, Show, createSignal } from "solid-js";
22 import { patchMe } from "@/api/users";
33 import type { ProfileUpdate, User } from "@/api/client";
44 import { formatApiError } from "@/api/client";
@@ -7,8 +7,10 @@ import { Button } from "@/components/ui/button";
77 import { DatePicker } from "@/components/ui/date-picker";
88 import { Input } from "@/components/ui/input";
99 import { Label } from "@/components/ui/label";
10+import { Select } from "@/components/ui/select";
1011 import { Textarea } from "@/components/ui/textarea";
1112 import { createFlash } from "@/lib/flash";
13+import { hasMinRole } from "@/lib/roles";
1214 import { useT } from "@/stores/preferences-context";
1315
1416 const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
@@ -47,7 +49,9 @@ export function ProfileForm(props: {
4749 * them where a profile is in hand; omit them and the fields stay hidden
4850 * rather than silently offering to clear values they cannot see.
4951 */
50- profile?: { display_name: string | null; bio: string | null };
52+ profile?: { display_name: string | null; bio: string | null; branch?: string | null };
53+ /** The school's branş vocabulary (settings.branches); the picker hides when empty. */
54+ branches?: string[];
5155 maxDisplayNameLen?: number;
5256 maxBioLen?: number;
5357 onSaved: () => void;
@@ -61,6 +65,15 @@ export function ProfileForm(props: {
6165 const [birthDate, setBirthDate] = createSignal(dateInputFromIso(props.user.birth_date));
6266 const [displayName, setDisplayName] = createSignal(props.profile?.display_name ?? "");
6367 const [bio, setBio] = createSignal(props.profile?.bio ?? "");
68+ const [branch, setBranch] = createSignal(props.profile?.branch ?? "");
69+ // Branş is a teacher's field; a stored value outside the list still shows so
70+ // saving the form never silently drops it.
71+ const branchOptions = () => {
72+ const list = props.branches ?? [];
73+ const stored = props.profile?.branch;
74+ return stored && !list.includes(stored) ? [stored, ...list] : list;
75+ };
76+ const showBranch = () => !!props.profile && hasMinRole(props.user.role, "teacher") && branchOptions().length > 0;
6477 const [error, setError] = createSignal("");
6578 const [flash, setFlash] = createFlash();
6679 const [pending, setPending] = createSignal(false);
@@ -93,6 +106,7 @@ export function ProfileForm(props: {
93106 const bi = bio().trim();
94107 if (dn !== (props.profile.display_name ?? "")) b.display_name = dn;
95108 if (bi !== (props.profile.bio ?? "")) b.bio = bi;
109+ if (showBranch() && branch() !== (props.profile.branch ?? "")) b.branch = branch();
96110 }
97111 return b;
98112 };
@@ -160,6 +174,15 @@ export function ProfileForm(props: {
160174 </p>
161175 </div>
162176 </Show>
177+ <Show when={showBranch()}>
178+ <div class="space-y-1.5">
179+ <Label for="pf-branch">{t("profile.branch")}</Label>
180+ <Select id="pf-branch" class="h-10" value={branch()} onChange={(e) => setBranch(e.currentTarget.value)}>
181+ <option value="">{t("profile.branchNone")}</option>
182+ <For each={branchOptions()}>{(name) => <option value={name}>{name}</option>}</For>
183+ </Select>
184+ </div>
185+ </Show>
163186 <div class="space-y-1.5">
164187 <Label for="pf-email">{t("profile.email")}</Label>
165188 <Input id="pf-email" class="h-10" type="email" value={email()} onInput={(e) => setEmail(e.currentTarget.value)} />
src/i18n/messages.tsmodified+6 -0
@@ -126,6 +126,8 @@ export type MessageKey =
126126 | "profile.displayNameHint"
127127 | "profile.bio"
128128 | "profile.bioHint"
129+ | "profile.branch"
130+ | "profile.branchNone"
129131 | "profile.bioEmpty"
130132 | "profile.classes"
131133 | "profile.noClasses"
@@ -2121,6 +2123,8 @@ const en: Dict = {
21212123 "profile.displayNameHint": "Shown to other people instead of your username.",
21222124 "profile.bio": "About",
21232125 "profile.bioHint": "A short line about yourself.",
2126+ "profile.branch": "Teaching subject (branş)",
2127+ "profile.branchNone": "Not set",
21242128 "profile.bioEmpty": "No bio yet.",
21252129 "profile.classes": "Classes",
21262130 "profile.noClasses": "Not in any class.",
@@ -4124,6 +4128,8 @@ const tr: Dict = {
41244128 "profile.displayNameHint": "Diğer kişilere kullanıcı adın yerine bu gösterilir.",
41254129 "profile.bio": "Hakkında",
41264130 "profile.bioHint": "Kendinle ilgili kısa bir not.",
4131+ "profile.branch": "Branş",
4132+ "profile.branchNone": "Belirtilmedi",
41274133 "profile.bioEmpty": "Henüz bir not yok.",
41284134 "profile.classes": "Şubeler",
41294135 "profile.noClasses": "Hiçbir şubede değil.",
src/pages/profile-page.tsxmodified+7 -1
@@ -3,6 +3,7 @@ import { createResource } from "@/lib/create-resource";
33 import { useLocation, useParams } from "@tanstack/solid-router";
44 import { getClassesByUserId, getMyClasses } from "@/api/classes";
55 import { getLimits } from "@/api/limits";
6+import { getSettings } from "@/api/settings";
67 import { getMyProfile, getUserProfile } from "@/api/users";
78 import { ApiError, formatApiError, type Profile } from "@/api/client";
89 import { RouteGuard } from "@/components/layout/route-guard";
@@ -50,6 +51,7 @@ function ProfileContent() {
5051 id === "me" ? getMyProfile() : getUserProfile(id),
5152 );
5253 const [limits] = createResource(() => getLimits());
54+ const [settings] = createResource(() => getSettings().catch(() => null));
5355 const [editing, setEditing] = createSignal(false);
5456
5557 // The five counters that fit the profile owner's role: a student's own
@@ -160,6 +162,9 @@ function ProfileContent() {
160162 <div class="flex flex-wrap items-center gap-2">
161163 <span class="text-sm text-muted-foreground">@{p().username}</span>
162164 <RoleBadge role={p().role} />
165+ <Show when={p().branch}>
166+ {(b) => <Badge variant="secondary" class="rounded-md">{b()}</Badge>}
167+ </Show>
163168 </div>
164169 <p class="max-w-prose whitespace-pre-wrap text-sm text-muted-foreground">
165170 {p().bio || t("profile.bioEmpty")}
@@ -220,7 +225,8 @@ function ProfileContent() {
220225 {(u) => (
221226 <ProfileForm
222227 user={u()}
223- profile={{ display_name: p().display_name, bio: p().bio }}
228+ profile={{ display_name: p().display_name, bio: p().bio, branch: p().branch }}
229+ branches={settings.latest?.branches}
224230 maxDisplayNameLen={limits.latest?.user.max_display_name_len}
225231 maxBioLen={limits.latest?.user.max_bio_len}
226232 onSaved={() => {