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 } }; export const fetchFaculties = async () => { try { const response = await fetch(`${BASE_URL}/faculty`); if (!response.ok) { throw new Error(`Failed to fetch faculties: ${response.statusText}`); } const data = await response.json(); return data; } catch (error) { console.error("Error fetching faculties:", error.message); throw error; } }; export const fetchOptions = async () => { try { const response = await fetch(`${BASE_URL}/options`); if (!response.ok) { throw new Error(`Failed to fetch options: ${response.statusText}`); } const data = await response.json(); return data; } catch (error) { console.error("Error fetching options:", error.message); throw error; } };