# Question Type Definition Groups — Admin Panel Integration Guide This guide explains how the admin panel should integrate **grouping for dynamic question type definitions**. Groups are named containers; each definition may belong to **zero or more** groups via nullable `group_ids`. > **Scope:** LMS dynamic question-type builder (`/api/v1/questions/type-definitions` and `/api/v1/questions/type-definition-groups`). > > **Backend migrations:** `000090_question_type_definition_groups`, then `000091_question_type_definition_group_members` (many-to-many junction table). > > **Related:** Existing type-definition create/list/update flows are unchanged except for the optional `group_ids` field and `group_id` list filter. --- ## Table of contents 1. [Summary](#summary) 2. [Concepts & data model](#concepts--data-model) 3. [When to use groups](#when-to-use-groups) 4. [End-to-end flows](#end-to-end-flows) 5. [Authentication & permissions](#authentication--permissions) 6. [Group API](#group-api) 7. [Definition API changes](#definition-api-changes) 8. [Response shapes & JSON field names](#response-shapes--json-field-names) 9. [Recommended admin UI](#recommended-admin-ui) 10. [TypeScript types & API client](#typescript-types--api-client) 11. [React examples](#react-examples) 12. [Error handling](#error-handling) 13. [Edge cases & constraints](#edge-cases--constraints) 14. [Integration checklist](#integration-checklist) 15. [Quick reference](#quick-reference) --- ## Summary | Topic | Behavior | |-------|----------| | Group entity | Named bucket with optional description, `display_order`, `status` | | Definition → group link | Many-to-many via `question_type_definition_group_members` | | Response field | `group_ids` — JSON **`null`** when ungrouped, or `[1, 2, …]` when linked | | Assign on create | Optional `group_ids` array in `POST /questions/type-definitions` | | Replace memberships on update | `PUT /questions/type-definitions/:id` with `group_ids` array or `null` | | List definitions in a group | `GET /questions/type-definitions?group_id=` (definitions in **any** matching membership) | | Group detail with definitions | `GET /questions/type-definition-groups/:id` → embeds `definitions[]` | | Delete group | Definitions are **not** deleted; only that group's memberships are removed | | Permissions | Reuses existing `questions.*` permissions (no new RBAC keys) | Groups help the admin panel organize the type-definition catalog (e.g. “Speaking”, “Reading”, “Grammar”) without changing how questions reference definitions (`question_type_definition_id` on questions is unchanged). --- ## Concepts & data model ```mermaid erDiagram question_type_definition_groups ||--o{ question_type_definition_group_members : has question_type_definitions ||--o{ question_type_definition_group_members : has question_type_definition_groups { bigint id PK varchar name text description int display_order varchar status } question_type_definition_group_members { bigint definition_id PK,FK bigint group_id PK,FK } question_type_definitions { bigint id PK varchar key UK varchar display_name } ``` ### Definition group memberships | Field | On create | On update | In responses | |-------|-----------|-----------|----------------| | `group_ids` | Optional array; omit or `[]` or `null` = ungrouped | Omit = no change; `null` or `[]` = detach from all groups; `[1,2]` = **replace** all memberships | Always `group_ids`; `null` when none, else sorted unique ids | **Cardinality:** Each definition can belong to **many** groups. The same definition may appear when listing multiple groups. Updating `group_ids` **replaces** the full membership set (same pattern as practice `parents`). --- ## When to use groups | Scenario | Approach | |----------|----------| | Organize builder catalog by subject/skill | Create groups; assign one or more `group_ids` on create or edit | | “Ungrouped” definitions | Omit `group_ids`, send `null`, or `[]` | | Definition in multiple sections | `group_ids: [1, 3, 5]` on create/update | | Group management screen | CRUD on `/questions/type-definition-groups` | | Group detail / drill-down | `GET /questions/type-definition-groups/:id` (includes definitions) | | Filtered definition picker | `GET /questions/type-definitions?group_id=:id` | | Add to another group without removing others | Read current ids, append, `PUT` with merged array | | Remove from one group only | Read current ids, filter out, `PUT` with remaining array | | Remove from all groups | `PUT` with `"group_ids": null` or `[]` | | Retire a group label | `DELETE /questions/type-definition-groups/:id` or set `status: INACTIVE` | --- ## End-to-end flows ### Flow A — Create group, then add definitions ```mermaid sequenceDiagram participant UI as Admin panel participant API as Yimaru API UI->>API: POST /questions/type-definition-groups { name } API-->>UI: 201 { id: 1, name, ... } UI->>API: POST /questions/type-definitions { key, display_name, group_ids: [1, 3], ... } API-->>UI: 201 { ID, group_ids: [1, 3], ... } UI->>API: GET /questions/type-definition-groups/1 API-->>UI: 200 { id, name, definitions: [...] } ``` ### Flow B — Add existing definition to more groups ```mermaid sequenceDiagram participant UI as Admin panel participant API as Yimaru API UI->>API: GET /questions/type-definitions/42 API-->>UI: 200 { ID: 42, group_ids: [1], ... } Note over UI,API: User selects groups 1 and 3 UI->>API: PUT /questions/type-definitions/42 { group_ids: [1, 3] } API-->>UI: 200 { id: 42 } ``` ### Flow C — Browse catalog grouped in UI (client-side) 1. `GET /questions/type-definition-groups?status=ACTIVE&limit=200` 2. For each group: `GET /questions/type-definitions?group_id=&include_system=true` 3. Optionally one call `GET /questions/type-definitions` without `group_id` and partition client-side where `group_ids == null` → “Ungrouped” **Prefer Flow A’s group detail endpoint** when you need group metadata + definitions in one round trip. --- ## Authentication & permissions All endpoints require: ```http Authorization: Bearer Content-Type: application/json ``` | Action | Permission | Endpoint | |--------|------------|----------| | List groups | `questions.list` | `GET /api/v1/questions/type-definition-groups` | | Get group (with definitions) | `questions.get` | `GET /api/v1/questions/type-definition-groups/:id` | | Create group | `questions.create` | `POST /api/v1/questions/type-definition-groups` | | Update group | `questions.update` | `PUT /api/v1/questions/type-definition-groups/:id` | | Delete group | `questions.delete` | `DELETE /api/v1/questions/type-definition-groups/:id` | | List definitions (incl. by group) | `questions.list` | `GET /api/v1/questions/type-definitions` | | Create definition (with `group_ids`) | `questions.create` | `POST /api/v1/questions/type-definitions` | | Update definition `group_ids` | `questions.update` | `PUT /api/v1/questions/type-definitions/:id` | --- ## Group API Base path: `/api/v1/questions/type-definition-groups` ### Create group ```http POST /api/v1/questions/type-definition-groups Authorization: Bearer Content-Type: application/json ``` **Request body** | Field | Required | Type | Notes | |-------|----------|------|-------| | `name` | Yes | string | Trimmed server-side | | `description` | No | string \| null | | | `display_order` | No | int | Default `0` | | `status` | No | `"ACTIVE"` \| `"INACTIVE"` | Default `ACTIVE` | **Example** ```json { "name": "Speaking & Listening", "description": "Oral production and comprehension task types", "display_order": 10, "status": "ACTIVE" } ``` **Success — `201 Created`** ```json { "success": true, "status_code": 201, "message": "Question type definition group created", "data": { "id": 1, "name": "Speaking & Listening", "description": "Oral production and comprehension task types", "display_order": 10, "status": "ACTIVE", "created_at": "2026-06-18T10:00:00Z" } } ``` --- ### List groups ```http GET /api/v1/questions/type-definition-groups?status=ACTIVE&limit=20&offset=0 ``` | Query param | Default | Notes | |-------------|---------|-------| | `status` | (all) | `ACTIVE` or `INACTIVE` | | `limit` | `20` | Max `200` | | `offset` | `0` | | **Success — `200 OK`** ```json { "success": true, "status_code": 200, "message": "Question type definition groups", "data": { "groups": [ { "id": 1, "name": "Speaking & Listening", "description": "Oral production and comprehension task types", "display_order": 10, "status": "ACTIVE", "created_at": "2026-06-18T10:00:00Z" } ], "total_count": 1, "limit": 20, "offset": 0 } } ``` --- ### Get group by ID (with definitions) ```http GET /api/v1/questions/type-definition-groups/1 ``` Returns the group row plus all definitions linked via the junction table (includes system definitions in that group). Definitions are ordered like the global list: system types first, then by display name. **Success — `200 OK`** ```json { "success": true, "status_code": 200, "message": "Question type definition group", "data": { "id": 1, "name": "Speaking & Listening", "description": "Oral production and comprehension task types", "display_order": 10, "status": "ACTIVE", "created_at": "2026-06-18T10:00:00Z", "definitions": [ { "ID": 42, "Key": "timed_speaking", "DisplayName": "Timed Speaking", "Description": null, "group_ids": [1, 3], "StimulusComponentKinds": ["AUDIO_PROMPT"], "ResponseComponentKinds": ["ANSWER_TIMER", "AUDIO_RESPONSE"], "StimulusSchema": [], "ResponseSchema": [], "IsSystem": false, "Status": "ACTIVE", "CreatedAt": "2026-06-18T10:05:00Z" } ] } } ``` **Error — `404 Not Found`** when group id does not exist. --- ### Update group ```http PUT /api/v1/questions/type-definition-groups/1 Content-Type: application/json ``` Partial update — only sent fields change. ```json { "name": "Speaking Tasks", "display_order": 5, "status": "ACTIVE" } ``` **Success — `200 OK`** ```json { "success": true, "status_code": 200, "message": "Question type definition group updated", "data": { "id": 1, "name": "Speaking Tasks", "display_order": 5, "status": "ACTIVE", "created_at": "2026-06-18T10:00:00Z", "updated_at": "2026-06-18T11:00:00Z" } } ``` --- ### Delete group ```http DELETE /api/v1/questions/type-definition-groups/1 ``` - Deletes the group row and its junction-table memberships only. - Definitions are **not** deleted. **Success — `200 OK`** ```json { "success": true, "status_code": 200, "message": "Question type definition group deleted", "data": { "id": 1 } } ``` --- ## Definition API changes Existing type-definition endpoints are extended; all prior fields and validation rules still apply (including optional empty stimulus/response shells and `ANSWER_TIMER`-only response configs). ### Create definition with groups ```http POST /api/v1/questions/type-definitions ``` Add optional `group_ids`: ```json { "key": "timed_speaking", "display_name": "Timed Speaking", "group_ids": [1, 3], "stimulus_component_kinds": ["AUDIO_PROMPT"], "response_component_kinds": ["ANSWER_TIMER", "AUDIO_RESPONSE"], "stimulus_schema": [], "response_schema": [], "status": "ACTIVE" } ``` | `group_ids` value | Effect | |-------------------|--------| | Omitted, `null`, or `[]` | Ungrouped (`group_ids: null` in response) | | `[1, 3]` | Linked to groups 1 and 3 (all ids must exist; duplicates deduped) | --- ### Update definition group memberships ```http PUT /api/v1/questions/type-definitions/42 ``` `group_ids` uses **replace** semantics on update: | Request body | Effect | |--------------|--------| | Field **omitted** | Keep current memberships | | `"group_ids": null` or `[]` | Detach from all groups | | `"group_ids": [1, 3]` | Replace memberships with groups 1 and 3 | **Clear all groups** ```json { "group_ids": null } ``` **Set multiple groups** ```json { "group_ids": [1, 2, 5] } ``` **Add one group without removing others (client-side merge)** ```typescript const current = definition.group_ids ?? []; await api.update(definition.id, { group_ids: [...new Set([...current, newGroupId])] }); ``` **Metadata-only update (memberships unchanged)** ```json { "display_name": "Timed speaking v2" } ``` --- ### List definitions filtered by group ```http GET /api/v1/questions/type-definitions?group_id=1&include_system=true&limit=50&offset=0 ``` | Query param | Default | Notes | |-------------|---------|-------| | `group_id` | (none) | When set, returns only definitions in that group | | `status` | (all) | `ACTIVE` / `INACTIVE` | | `include_system` | `true` | System seeded definitions included when `true` | | `limit` | `20` | Max `200` | | `offset` | `0` | | **Without `group_id`:** returns all definitions (existing behavior). **With `group_id`:** returns only matching definitions. If the group id does not exist → **`404`** with message `Question type definition group not found`. **Success — `200 OK`** ```json { "success": true, "status_code": 200, "message": "Question type definitions", "data": { "question_type_definitions": [ { "ID": 42, "Key": "timed_speaking", "DisplayName": "Timed Speaking", "group_ids": [1, 3], "StimulusComponentKinds": ["AUDIO_PROMPT"], "ResponseComponentKinds": ["ANSWER_TIMER", "AUDIO_RESPONSE"], "IsSystem": false, "Status": "ACTIVE" } ], "total_count": 1, "limit": 50, "offset": 0 } } ``` --- ## Response shapes & JSON field names **Important for the admin panel:** Group objects use **snake_case** JSON keys (`display_order`, `created_at`). Definition objects mostly use **PascalCase** keys from Go serialization (`ID`, `Key`, `DisplayName`, `StimulusComponentKinds`, …) except: | Field | JSON key | |-------|----------| | Group memberships on definition | `group_ids` (snake_case) | | Schema elements | `id`, `kind`, `label`, `required`, `config` (snake_case via struct tags) | Normalize in your API client if the UI prefers camelCase: ```typescript function normalizeDefinition(raw: ApiQuestionTypeDefinition): QuestionTypeDefinition { return { id: raw.ID, key: raw.Key, displayName: raw.DisplayName, groupIds: raw.group_ids ?? null, stimulusComponentKinds: raw.StimulusComponentKinds ?? [], responseComponentKinds: raw.ResponseComponentKinds ?? [], // ... }; } ``` `group_ids` in responses is **`null`** when the definition has no group memberships (not `undefined`). --- ## Recommended admin UI ### Information architecture ```mermaid flowchart LR subgraph Catalog["Question type catalog"] GL[Group list page] GD[Group detail page] DU[Definition editor] UL[Ungrouped definitions] end GL -->|click group| GD GD -->|edit definition| DU GL --> UL UL --> DU ``` ### Group list page - Table/cards: name, description snippet, definition count (from group detail or cached), `status`, `display_order` - Actions: Create, Edit, Delete (confirm: removes group memberships only; definitions remain) - Sort by `display_order`, then name (matches API) - Filter: `ACTIVE` / `INACTIVE` / all ### Group detail page - Load: `GET /questions/type-definition-groups/:id` - Show group metadata + `definitions` table - Actions: - **Add definition** → definition create form with `group_ids` including current group - **Remove from this group** → `PUT` with `group_ids` filtered to exclude this group id - **Edit memberships** → multi-select groups on definition edit form ### Definition create / edit form - Add **Groups** multi-select: 1. Load groups: `GET /questions/type-definition-groups?status=ACTIVE&limit=200` 2. Empty selection → omit `group_ids`, send `null`, or `[]` on create 3. On edit, send full desired `group_ids` array to replace memberships - When opened from group detail, pre-select that group (and allow adding more) ### Definition picker (e.g. when authoring questions) - Tabs or sidebar: one tab per group + “Ungrouped” - Per tab: `GET /questions/type-definitions?group_id=&status=ACTIVE` - Ungrouped: full list client-side filter where `group_ids == null`, or dedicated UX section ### Delete group confirmation copy > Deleting this group will not delete any question types. Definitions in this group will become ungrouped. --- ## TypeScript types & API client ```typescript const API_BASE = "/api/v1"; // --- Shared wrappers --- export interface ApiResponse { success: boolean; status_code: number; message: string; data: T; } export interface ApiError { message: string; error: string; } export interface Paginated { total_count: number; limit: number; offset: number; items: T; } // --- Groups --- export interface QuestionTypeDefinitionGroup { id: number; name: string; description: string | null; display_order: number; status: "ACTIVE" | "INACTIVE"; created_at: string; updated_at?: string; } export interface QuestionTypeDefinitionGroupDetail extends QuestionTypeDefinitionGroup { definitions: ApiQuestionTypeDefinition[]; } export interface CreateQuestionTypeDefinitionGroupBody { name: string; description?: string | null; display_order?: number; status?: "ACTIVE" | "INACTIVE"; } export interface UpdateQuestionTypeDefinitionGroupBody { name?: string; description?: string | null; display_order?: number; status?: "ACTIVE" | "INACTIVE"; } // --- Definitions (wire format from API) --- export interface ApiQuestionTypeDefinition { ID: number; Key: string; DisplayName: string; Description?: string | null; group_ids: number[] | null; StimulusComponentKinds: string[]; ResponseComponentKinds: string[]; StimulusSchema?: DynamicElementDefinition[]; ResponseSchema?: DynamicElementDefinition[]; IsSystem: boolean; Status: string; CreatedAt: string; UpdatedAt?: string; } export interface DynamicElementDefinition { id: string; kind: string; label?: string; required: boolean; config?: Record; } // --- Normalized app model --- export interface QuestionTypeDefinition { id: number; key: string; displayName: string; description: string | null; groupId: number | null; stimulusComponentKinds: string[]; responseComponentKinds: string[]; isSystem: boolean; status: string; } export function normalizeDefinition(raw: ApiQuestionTypeDefinition): QuestionTypeDefinition { return { id: raw.ID, key: raw.Key, displayName: raw.DisplayName, description: raw.Description ?? null, groupIds: raw.group_ids ?? null, stimulusComponentKinds: raw.StimulusComponentKinds ?? [], responseComponentKinds: raw.ResponseComponentKinds ?? [], isSystem: raw.IsSystem, status: raw.Status, }; } // --- API helpers --- async function api(path: string, init?: RequestInit): Promise { const res = await fetch(`${API_BASE}${path}`, { ...init, headers: { "Content-Type": "application/json", Authorization: `Bearer ${getAccessToken()}`, ...init?.headers, }, }); const body = await res.json(); if (!res.ok) throw body as ApiError; return (body as ApiResponse).data; } export const questionTypeDefinitionGroupsApi = { list(params?: { status?: string; limit?: number; offset?: number }) { const q = new URLSearchParams(); if (params?.status) q.set("status", params.status); if (params?.limit != null) q.set("limit", String(params.limit)); if (params?.offset != null) q.set("offset", String(params.offset)); const qs = q.toString(); return api<{ groups: QuestionTypeDefinitionGroup[]; total_count: number; limit: number; offset: number; }>(`/questions/type-definition-groups${qs ? `?${qs}` : ""}`); }, get(id: number) { return api(`/questions/type-definition-groups/${id}`); }, create(body: CreateQuestionTypeDefinitionGroupBody) { return api("/questions/type-definition-groups", { method: "POST", body: JSON.stringify(body), }); }, update(id: number, body: UpdateQuestionTypeDefinitionGroupBody) { return api(`/questions/type-definition-groups/${id}`, { method: "PUT", body: JSON.stringify(body), }); }, delete(id: number) { return api<{ id: number }>(`/questions/type-definition-groups/${id}`, { method: "DELETE" }); }, }; export const questionTypeDefinitionsApi = { list(params?: { group_id?: number; status?: string; include_system?: boolean; limit?: number; offset?: number; }) { const q = new URLSearchParams(); if (params?.group_id != null) q.set("group_id", String(params.group_id)); if (params?.status) q.set("status", params.status); if (params?.include_system != null) q.set("include_system", String(params.include_system)); if (params?.limit != null) q.set("limit", String(params.limit)); if (params?.offset != null) q.set("offset", String(params.offset)); const qs = q.toString(); return api<{ question_type_definitions: ApiQuestionTypeDefinition[]; total_count: number; limit: number; offset: number; }>(`/questions/type-definitions${qs ? `?${qs}` : ""}`); }, create(body: Record) { return api("/questions/type-definitions", { method: "POST", body: JSON.stringify(body), }); }, update(id: number, body: Record) { return api<{ id: number }>(`/questions/type-definitions/${id}`, { method: "PUT", body: JSON.stringify(body), }); }, assignGroups(definitionId: number, groupIds: number[] | null) { return this.update(definitionId, { group_ids: groupIds }); }, }; ``` --- ## React examples ### Load groups for a select input ```tsx import { useEffect, useState } from "react"; import { questionTypeDefinitionGroupsApi, type QuestionTypeDefinitionGroup, } from "@/api/questionTypeDefinitionGroups"; export function GroupSelect({ value, onChange, }: { value: number | null; onChange: (groupId: number | null) => void; }) { const [groups, setGroups] = useState([]); useEffect(() => { questionTypeDefinitionGroupsApi .list({ status: "ACTIVE", limit: 200 }) .then((data) => setGroups(data.groups)) .catch(console.error); }, []); return ( ); } ``` ### Group detail page with definitions ```tsx import { useEffect, useState } from "react"; import { questionTypeDefinitionGroupsApi, questionTypeDefinitionsApi, normalizeDefinition, type QuestionTypeDefinitionGroupDetail, } from "@/api/questionTypeDefinitionGroups"; export function GroupDetailPage({ groupId }: { groupId: number }) { const [group, setGroup] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { setLoading(true); questionTypeDefinitionGroupsApi .get(groupId) .then(setGroup) .catch((e) => setError(e.message ?? "Failed to load group")) .finally(() => setLoading(false)); }, [groupId]); async function handleRemoveFromGroup(definitionId: number) { await questionTypeDefinitionsApi.assignGroup(definitionId, null); const refreshed = await questionTypeDefinitionGroupsApi.get(groupId); setGroup(refreshed); } if (loading) return

Loading…

; if (error) return

{error}

; if (!group) return null; return (

{group.name}

{group.description &&

{group.description}

}

Definitions ({group.definitions.length})

    {group.definitions.map((raw) => { const def = normalizeDefinition(raw); return (
  • {def.displayName} {def.key}
  • ); })}
); } ``` ### Create definition inside a group ```tsx async function createDefinitionInGroup( groupId: number, payload: { key: string; display_name: string; stimulus_component_kinds: string[]; response_component_kinds: string[]; } ) { return questionTypeDefinitionsApi.create({ ...payload, group_ids: groupIds, status: "ACTIVE", }); } ``` --- ## Error handling ### Group endpoints | HTTP | `message` | Typical cause | |------|-----------|---------------| | 400 | `Invalid request body` | Malformed JSON | | 400 | `Validation failed` | Missing `name` on create | | 404 | `Question type definition group not found` | Invalid group id on GET/PUT/DELETE | | 403 | Permission denied | Missing `questions.*` permission | | 500 | `Failed to list…` / `Failed to get…` | Server error | ### Definition endpoints (group-related) | HTTP | `message` | Typical cause | |------|-----------|---------------| | 400 | `Invalid group_ids` | Malformed `group_ids` array on update | | 404 | `Question type definition group not found` | Unknown id in `group_ids` or `group_id` list filter | | 400 | `Unable to create question type definition` | Validation error (kinds, schemas, etc.) — unchanged | | 400 | `Unable to update question type definition` | Same | **Client guidance** - On `404` for `group_id` filter: show “Group not found” and redirect to group list. - On create/update with stale group id: refresh group dropdown from `GET /type-definition-groups`. - Surface `error` field from `ApiError` for toast details. --- ## Edge cases & constraints | Topic | Behavior | |-------|----------| | System definitions | Can be assigned to a group like any other definition (`include_system` affects list) | | Multiple groups per definition | **Supported** — `group_ids: [1, 2, 3]` | | Delete group | Definitions survive; only memberships for that group are removed | | Delete definition | Unchanged; group unaffected | | Questions referencing definitions | Unaffected by grouping (FK is `question_type_definition_id`, not group) | | Empty group | Valid — group with zero definitions returns `"definitions": []` | | Inactive group | Definitions may still reference it; consider UI warning or blocking new assignments | | `display_order` ties | Secondary sort is `name` ASC | | Pagination | Use `total_count`, `limit`, `offset` on both list endpoints | | No `ungrouped_only` query param | Filter client-side: `group_ids == null` from global definition list | --- ## Integration checklist - [ ] Run migrations `000090` and `000091` on target environments - [ ] Add **Groups** section to question-type admin navigation - [ ] Implement group list (CRUD) against `/questions/type-definition-groups` - [ ] Implement group detail using `GET .../type-definition-groups/:id` (definitions embedded) - [ ] Add **Groups** multi-select to definition create/edit (`group_ids`) - [ ] Support `group_ids: null` / `[]` on update to clear all memberships - [ ] Add optional `group_id` query filter to definition list / picker - [ ] Handle `404` when group id is invalid on filtered list - [ ] Normalize PascalCase definition fields + snake_case `group_ids` in API client - [ ] Show delete-group confirmation (memberships removed; definitions remain) - [ ] Verify permissions: `questions.list`, `.get`, `.create`, `.update`, `.delete` - [ ] QA: create groups → assign multiple `group_ids` → list by `group_id` → partial remove → clear all → delete group --- ## Quick reference ### Endpoints | Method | Path | Purpose | |--------|------|---------| | `POST` | `/api/v1/questions/type-definition-groups` | Create group | | `GET` | `/api/v1/questions/type-definition-groups` | List groups | | `GET` | `/api/v1/questions/type-definition-groups/:id` | Get group + definitions | | `PUT` | `/api/v1/questions/type-definition-groups/:id` | Update group | | `DELETE` | `/api/v1/questions/type-definition-groups/:id` | Delete group | | `GET` | `/api/v1/questions/type-definitions?group_id=:id` | List definitions in group | | `POST` | `/api/v1/questions/type-definitions` | Create definition (`group_ids` optional) | | `PUT` | `/api/v1/questions/type-definitions/:id` | Update definition (`group_ids` replace / null) | ### `group_ids` cheat sheet | Context | Value | Result | |---------|-------|--------| | Create | omitted / `null` / `[]` | Ungrouped | | Create | `[1, 3]` | Member of groups 1 and 3 | | Update | omitted | No membership change | | Update | `null` / `[]` | Detach from all groups | | Update | `[1, 2]` | Replace memberships with groups 1 and 2 | | Response | `null` | Not in any group | | Response | `[1, 3]` | Member of groups 1 and 3 | ### Minimal happy path ```bash # 1. Create groups POST /api/v1/questions/type-definition-groups { "name": "Reading" } POST /api/v1/questions/type-definition-groups { "name": "Exam prep" } # 2. Create definition in multiple groups POST /api/v1/questions/type-definitions { "key": "passage_mcq", "display_name": "Passage MCQ", "group_ids": [1, 2], ... } # 3. Verify GET /api/v1/questions/type-definition-groups/1 GET /api/v1/questions/type-definitions?group_id=1 GET /api/v1/questions/type-definitions?group_id=2 ```