mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-25 22:09:15 +02:00
added frontend and updated backend with docker, wrote some initial instructions
This commit is contained in:
45
frontend/src/api/fetchCourse.ts
Normal file
45
frontend/src/api/fetchCourse.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
// function to fetch course data from the API
|
||||
|
||||
import { Module } from "../model/module.ts";
|
||||
|
||||
export async function fetchCourse(): Promise<string[]> {
|
||||
const courses: string[] = [];
|
||||
await fetch("/api/courses")
|
||||
.then((response) => {
|
||||
return response.json();
|
||||
})
|
||||
.then((coursesResponse) => {
|
||||
coursesResponse.forEach((course: string) => courses.push(course));
|
||||
});
|
||||
return courses;
|
||||
}
|
||||
|
||||
export async function fetchModulesByCourseAndSemester(
|
||||
course: string,
|
||||
semester: string,
|
||||
): Promise<Module[]> {
|
||||
const modules: Module[] = [];
|
||||
await fetch("/api/course/modules?course=" + course + "&semester=" + semester)
|
||||
.then((response) => {
|
||||
return response.json();
|
||||
})
|
||||
.then((modulesResponse) => {
|
||||
modulesResponse.forEach((module: string) =>
|
||||
modules.push(new Module(module, course)),
|
||||
);
|
||||
});
|
||||
return modules;
|
||||
}
|
||||
|
||||
export async function fetchAllModules(): Promise<Module[]> {
|
||||
let modules: Module[] = [];
|
||||
await fetch("/api/modules")
|
||||
.then((response) => {
|
||||
return response.json() as Promise<Module[]>;
|
||||
})
|
||||
.then((responseModules: Module[]) => {
|
||||
modules = responseModules as Module[];
|
||||
});
|
||||
|
||||
return modules;
|
||||
}
|
Reference in New Issue
Block a user