Added backend and integration for FilterPage and CourseTable done
This commit is contained in:
28
client/src/api.js
Normal file
28
client/src/api.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const BASE_URL = "http://localhost:8080/api";
|
||||
|
||||
export const fetchCourses = async (filterData) => {
|
||||
try {
|
||||
|
||||
// Serialize filterData into query parameters
|
||||
const queryString = new URLSearchParams(filterData).toString();
|
||||
// console.log(queryString);
|
||||
const response = await fetch(`${BASE_URL}/courses?${queryString}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch courses");
|
||||
}
|
||||
|
||||
const filteredCourses = await response.json();
|
||||
console.log(filteredCourses);
|
||||
return filteredCourses;
|
||||
} catch (error) {
|
||||
console.error("Error fetching courses:", error);
|
||||
throw error; // Re-throw error to be handled by the caller
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user