feat: question answer frontend controller en queries

This commit is contained in:
Gabriellvl 2025-04-07 16:30:52 +02:00
parent 7f7a4fe936
commit 09a11589d2
6 changed files with 229 additions and 8 deletions

View file

@ -1,5 +1,38 @@
import type { QuestionDTO, QuestionId } from "@dwengo-1/interfaces/question";
import type {QuestionData, QuestionDTO, QuestionId} from "@dwengo-1/common/interfaces/question";
import {BaseController} from "@/controllers/base-controller.ts";
import type {LearningObjectIdentifierDTO} from "@dwengo-1/common/interfaces/learning-content";
export interface QuestionsResponse {
questions: QuestionDTO[] | QuestionId[];
}
export interface QuestionResponse {
question: QuestionDTO;
}
export class QuestionController extends BaseController {
constructor(loId: LearningObjectIdentifierDTO) {
this.loId = loId;
super(`learningObject/${loId.hruid}/:${loId.version}/questions`);
}
async getAll(full = true): Promise<QuestionsResponse> {
return this.get<QuestionsResponse>("/", {lang: this.loId.lang, full});
}
async getBy(sequenceNumber: number): Promise<QuestionResponse> {
return this.get<QuestionResponse>(`/${sequenceNumber}`, {lang: this.loId.lang});
}
async create(questionData: QuestionData): Promise<QuestionResponse> {
return this.post<QuestionResponse>("/", questionData, {lang: this.loId.lang})
}
async remove(sequenceNumber: number) {
return this.delete<QuestionResponse>(`/${sequenceNumber}`, {lang: this.loId.lang});
}
async update(sequenceNumber: number, questionData: QuestionData) {
return this.put<QuestionResponse>(`/${sequenceNumber}`, questionData, {lang: this.loId.lang});
}
}