locate-the-news / frontend / src / api / events.js
events.js
Raw
import axios from 'axios';

const API_BASE_URL = process.env.REACT_APP_API_URL || 'https://locate-the-news.onrender.com/api/v1';

export const fetchEvents = async (bounds = null) => {
  try {
    const params = {};
    if (bounds) {
      params.min_lat = bounds.min_lat;
      params.max_lat = bounds.max_lat;
      params.min_lng = bounds.min_lng;
      params.max_lng = bounds.max_lng;
    }

    const response = await axios.get(`${API_BASE_URL}/events`, { params });
    return response.data;
  } catch (error) {
    console.error('Error fetching events:', error);
    throw error;
  }
};

export const fetchEvent = async (eventId) => {
  try {
    const response = await axios.get(`${API_BASE_URL}/events/${eventId}`);
    return response.data;
  } catch (error) {
    console.error('Error fetching event:', error);
    throw error;
  }
};