feat(frontend): alle leerpaden en klasses worden gefetched via de controllers

This commit is contained in:
Joyelle Ndagijimana 2025-04-08 01:29:42 +02:00
parent 23947ecd92
commit 1328771551
7 changed files with 113 additions and 83 deletions

View file

@ -1,17 +1,19 @@
import { BaseController } from "@/controllers/base-controller.ts";
import { LearningPath } from "@/data-objects/learning-paths/learning-path.ts";
import type { Language } from "@/data-objects/language.ts";
import { single } from "@/utils/response-assertions.ts";
import type { LearningPathDTO } from "@/data-objects/learning-paths/learning-path-dto.ts";
import {BaseController} from "@/controllers/base-controller.ts";
import {LearningPath} from "@/data-objects/learning-paths/learning-path.ts";
import type {Language} from "@/data-objects/language.ts";
import {single} from "@/utils/response-assertions.ts";
import type {LearningPathDTO} from "@/data-objects/learning-paths/learning-path-dto.ts";
export class LearningPathController extends BaseController {
constructor() {
super("learningPath");
}
async search(query: string): Promise<LearningPath[]> {
const dtos = await this.get<LearningPathDTO[]>("/", { search: query });
const dtos = await this.get<LearningPathDTO[]>("/", {search: query});
return dtos.map((dto) => LearningPath.fromDTO(dto));
}
async getBy(
hruid: string,
language: Language,
@ -25,8 +27,15 @@ export class LearningPathController extends BaseController {
});
return LearningPath.fromDTO(single(dtos));
}
async getAllByTheme(theme: string): Promise<LearningPath[]> {
const dtos = await this.get<LearningPathDTO[]>("/", { theme });
const dtos = await this.get<LearningPathDTO[]>("/", {theme});
return dtos.map((dto) => LearningPath.fromDTO(dto));
}
async getAllLearningPaths(language: string | null = null): Promise<LearningPath[]> {
const query = language ? { language } : undefined;
const dtos = await this.get<LearningPathDTO[]>("/", query);
return dtos.map((dto) => LearningPath.fromDTO(dto));
}
}