notha99y's picture
init
c398d0b
Raw History Blame Contribute Delete
1.43 kB
import axios from 'axios';
const API_BASE_URL = process.env.REACT_APP_API_URL || (process.env.NODE_ENV === 'production' ? '' : 'http://localhost:8000');
const api = axios.create({
baseURL: API_BASE_URL,
headers: {
'Content-Type': 'application/json',
},
});
export const searchTimetable = async (searchRequest) => {
try {
console.log('Sending request to backend:', JSON.stringify(searchRequest, null, 2));
const response = await api.post('/api/search', searchRequest);
return response.data;
} catch (error) {
console.error('Error searching timetable:', error);
if (error.response) {
console.error('Response status:', error.response.status);
console.error('Response data:', error.response.data);
}
throw error;
}
};
export const uploadCSV = async (file) => {
try {
const formData = new FormData();
formData.append('file', file);
const response = await api.post('/api/upload-csv', formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
return response.data;
} catch (error) {
console.error('Error uploading CSV:', error);
throw error;
}
};
export const validateModule = async (module) => {
try {
const response = await api.post('/api/validate-module', module);
return response.data;
} catch (error) {
console.error('Error validating module:', error);
throw error;
}
};