From 5ac94d72745123ea5594d7d42fe50aa2bcb159f1 Mon Sep 17 00:00:00 2001 From: Bilal Date: Fri, 4 Sep 2020 08:44:06 +0300 Subject: [PATCH] add API namespace --- client/src/cash/Cash.js | 2 +- client/src/cash/MakeMoneyMove.js | 4 ++-- client/src/chips/AddChip.js | 2 +- client/src/chips/ListChips.js | 10 +++++----- config/routes.rb | 14 ++++++++------ 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/client/src/cash/Cash.js b/client/src/cash/Cash.js index 4d938f2..617a21c 100644 --- a/client/src/cash/Cash.js +++ b/client/src/cash/Cash.js @@ -12,7 +12,7 @@ const Cash = (props) => { useEffect( () => { const getCashForHomies = async () => { try { - const cash = await axios.get(`/homies/cash`); + const cash = await axios.get(`/api/homies/cash`); setHomiesCash(cash.data); } catch (e) { console.log("Error fetching", e); diff --git a/client/src/cash/MakeMoneyMove.js b/client/src/cash/MakeMoneyMove.js index 66f4848..4220a5d 100644 --- a/client/src/cash/MakeMoneyMove.js +++ b/client/src/cash/MakeMoneyMove.js @@ -16,7 +16,7 @@ const MakeMoneyMove = (props) => { useEffect(() => { const getCashForHomies = async () => { try { - const cash = await axios.get(`/homies/cash`); + const cash = await axios.get(`/api/homies/cash`); setHomiesCash(cash.data); } catch (e) { console.log("Error fetching", e); @@ -72,7 +72,7 @@ const MakeMoneyMove = (props) => { } } - const submitResponse = await axios.post('/money_moves', moneyMoveRequest); + const submitResponse = await axios.post('/api/money_moves', moneyMoveRequest); if (submitResponse && submitResponse.status === 200 && submitResponse.data === true) { M.toast({html: "Money lounde...moved"}); diff --git a/client/src/chips/AddChip.js b/client/src/chips/AddChip.js index b2c7218..8e067a9 100644 --- a/client/src/chips/AddChip.js +++ b/client/src/chips/AddChip.js @@ -43,7 +43,7 @@ const AddChip = (props) => { } try{ - const submitResponse = await axios.post('/chips', chipRequest); + const submitResponse = await axios.post('/api/chips', chipRequest); if (submitResponse && submitResponse.status === 200 && submitResponse.data) { M.toast({ html: "Chipped In" }); diff --git a/client/src/chips/ListChips.js b/client/src/chips/ListChips.js index d912efa..8eb92b3 100644 --- a/client/src/chips/ListChips.js +++ b/client/src/chips/ListChips.js @@ -14,7 +14,7 @@ const ListChips = (props) => { const reloadChipsListEffect = () => { (async() => { try { - const chipsResponse = await axios.get(`/chips`); + const chipsResponse = await axios.get(`/api/chips`); if (chipsResponse && chipsResponse.status === 200 && Array.isArray(chipsResponse.data)) { setChipsList(chipsResponse.data); @@ -45,7 +45,7 @@ const ListChips = (props) => { const deleteChip = async (chipId) => { try { - const chipsResponse = await axios.delete(`/chips/${chipId}`); + const chipsResponse = await axios.delete(`/api/chips/${chipId}`); if (chipsResponse && chipsResponse.status === 200 && Array.isArray(chipsResponse.data)){ setChipsList(chipsResponse.data); @@ -66,7 +66,7 @@ const ListChips = (props) => { value: editingChipValue } } - const chipsResponse = await axios.post(`/chip_values`, newChipValueObject); + const chipsResponse = await axios.post(`/api/chip_values`, newChipValueObject); if (chipsResponse && chipsResponse.status === 200){ setChipsList(chipsResponse.data); @@ -88,7 +88,7 @@ const ListChips = (props) => { value: editingChipValue } } - const chipsResponse = await axios.put(`/chip_values/${chipValueId}`, updatedChipValue); + const chipsResponse = await axios.put(`/api/chip_values/${chipValueId}`, updatedChipValue); if (chipsResponse && chipsResponse.status === 200){ setChipsList(chipsResponse.data); @@ -102,7 +102,7 @@ const ListChips = (props) => { const deleteChipValue = async (chipValueId) => { try { - const chipsResponse = await axios.delete(`/chip_values/${chipValueId}`); + const chipsResponse = await axios.delete(`/api/chip_values/${chipValueId}`); if (chipsResponse && chipsResponse.status === 200){ setChipsList(chipsResponse.data); diff --git a/config/routes.rb b/config/routes.rb index 1a60905..77af911 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,13 @@ Rails.application.routes.draw do constraints format: :json do - resources :money_moves - resources :chips, only: %i[index create destroy] - resources :chip_values, only: %i[create update destroy] - resources :homies do - collection do - get 'cash' + namespace :api do + resources :money_moves + resources :chips, only: %i[index create destroy] + resources :chip_values, only: %i[create update destroy] + resources :homies do + collection do + get 'cash' + end end end end