import axios from 'axios';
import {FETCH_MENUS, FETCH_MENU, DELETE_MENU, UPDATE_MENU, CREATE_MENU} from './types';
import {API_URL} from './index';

export function fetchMenus() {
  const request = axios.get(API_URL + '/api/menu');
  return {
    type: FETCH_MENUS,
    payload: request
  };
}

export function fetchMenu(id) {
  const request = axios.get(`${API_URL}/api/menu/${id}`);
  return {
    type: FETCH_MENU,
    payload: request
  };
}

export function deleteMenu(id) {
  const request = axios.delete(`${API_URL}/api/menu/${id}`);
  return {
    type: DELETE_MENU,
    payload: request
  };
}

export function updateMenu(props, id) {
  const request = axios.put(`${API_URL}/api/menu/${id}`, props);
  return {
    type: UPDATE_MENU,
    payload: request
  };
}

export function createMenu(props) {
  const request = axios.post(API_URL + '/api/menu', props);
  return {
    type: CREATE_MENU,
    payload: request
  };
}
