diff --git a/src/App.js b/src/App.js index 2393a5e..d8b0484 100644 --- a/src/App.js +++ b/src/App.js @@ -40,24 +40,24 @@ function AppRoutes({ token, setToken }) { return ( <> - } /> + } /> : } + path="/api/v1/boxes" + element={token ? : } /> : } + path="/api/v1/items" + element={token ? : } /> : } + path="/api/v1/boxes/:id/items" + element={token ? : } /> : } + path="/api/v1/admin" + element={token ? : } /> - } /> + } /> ); diff --git a/src/components/Admin.js b/src/components/Admin.js index ed13972..58b82d7 100644 --- a/src/components/Admin.js +++ b/src/components/Admin.js @@ -32,7 +32,7 @@ export default function Admin() { useEffect(() => { - axios.get(`${process.env.REACT_APP_API_URL}/admin/user`, { + axios.get(`${process.env.REACT_APP_API_URL}/api/v1/admin/user`, { headers: { Authorization: `Bearer ${localStorage.getItem('token')}` } }) .then(response => { @@ -45,7 +45,7 @@ export default function Admin() { const fetchUsers = async () => { try { - const response = await axios.get(`${process.env.REACT_APP_API_URL}/admin/user`, { + const response = await axios.get(`${process.env.REACT_APP_API_URL}/api/v1/admin/user`, { headers: { Authorization: `Bearer ${localStorage.getItem('token')}` } }); setUsers(response.data); @@ -59,7 +59,7 @@ export default function Admin() { const handleCreateUser = async (e) => { e.preventDefault(); try { - const response = await axios.post(`${process.env.REACT_APP_API_URL}/admin/user`, { + const response = await axios.post(`${process.env.REACT_APP_API_URL}/api/v1/admin/user`, { username, password, email @@ -77,7 +77,7 @@ export default function Admin() { const handleDeleteUser = async (id) => { try { - await axios.delete(`${process.env.REACT_APP_API_URL}/admin/user/${id}`, { + await axios.delete(`${process.env.REACT_APP_API_URL}/api/v1/admin/user/${id}`, { headers: { Authorization: `Bearer ${localStorage.getItem('token')}` } }); setUsers(users.filter(user => user.id !== id)); @@ -91,7 +91,7 @@ export default function Admin() { const handleBackupDatabase = async () => { try { - const response = await axios.get(`${process.env.REACT_APP_API_URL}/admin/db`, { + const response = await axios.get(`${process.env.REACT_APP_API_URL}/api/v1/admin/db`, { headers: { Authorization: `Bearer ${localStorage.getItem('token')}` }, responseType: 'blob' }); @@ -119,7 +119,7 @@ export default function Admin() { throw new Error('No token found in local storage'); } - const response = await axios.post(`${process.env.REACT_APP_API_URL}/admin/db`, formData, { + const response = await axios.post(`${process.env.REACT_APP_API_URL}/api/v1/admin/db`, formData, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'multipart/form-data' diff --git a/src/components/Boxes.js b/src/components/Boxes.js index 48b65f8..f3dc573 100644 --- a/src/components/Boxes.js +++ b/src/components/Boxes.js @@ -20,7 +20,7 @@ export default function Boxes({ token }) { useEffect(() => { //console.log('Token:' + token); - axios.get(`${process.env.REACT_APP_API_URL}/boxes`, { + axios.get(`${process.env.REACT_APP_API_URL}/api/v1/boxes`, { headers: { Authorization: `Bearer ${token}` } }).then(response => { setBoxes(response.data); @@ -33,7 +33,7 @@ export default function Boxes({ token }) { }, [boxes]); const handleCreateBox = () => { - axios.post(`${process.env.REACT_APP_API_URL}/boxes`, { name: newBoxName }, { + axios.post(`${process.env.REACT_APP_API_URL}/api/v1/boxes`, { name: newBoxName }, { headers: { Authorization: `Bearer ${token}` } }).then(response => { setBoxes([...boxes, response.data]); @@ -42,7 +42,7 @@ export default function Boxes({ token }) { }; const handleDeleteBox = (id) => { - axios.delete(`${process.env.REACT_APP_API_URL}/boxes/${id}`, { + axios.delete(`${process.env.REACT_APP_API_URL}/api/v1/boxes/${id}`, { headers: { Authorization: `Bearer ${token}` } }).then(() => { setBoxes(boxes.filter(box => box.ID !== id)); @@ -64,7 +64,7 @@ export default function Boxes({ token }) { {boxes.map((box) => ( - + {box.name} diff --git a/src/components/ItemDetails.js b/src/components/ItemDetails.js index 2815ade..713d8cb 100644 --- a/src/components/ItemDetails.js +++ b/src/components/ItemDetails.js @@ -25,7 +25,7 @@ export default function ItemDetails({ item, token, onSave, onClose, boxId }) { useEffect(() => { const fetchBoxes = async () => { try { - const response = await axios.get(`${process.env.REACT_APP_API_URL}/boxes`, { + const response = await axios.get(`${process.env.REACT_APP_API_URL}/api/v1/boxes`, { headers: { Authorization: `Bearer ${token}` } }); setBoxes(response.data); @@ -52,7 +52,7 @@ export default function ItemDetails({ item, token, onSave, onClose, boxId }) { console.error('Invalid boxId:', boxId); return; } - const response = await axios.get(`${process.env.REACT_APP_API_URL}/boxes/${boxIdNumber}`, { + const response = await axios.get(`${process.env.REACT_APP_API_URL}/api/v1/boxes/${boxIdNumber}`, { headers: { Authorization: `Bearer ${token}` } }); setBoxName(response.data.name); @@ -73,7 +73,7 @@ export default function ItemDetails({ item, token, onSave, onClose, boxId }) { useEffect(() => { // Function to fetch image similar to getImageSrc in Items.js const getImageSrc = (itemId) => { - return axios.get(`${process.env.REACT_APP_API_URL}/items/${itemId}/image`, { + return axios.get(`${process.env.REACT_APP_API_URL}/api/v1/items/${itemId}/image`, { headers: { Authorization: `Bearer ${token}` }, responseType: 'blob' }) @@ -122,7 +122,7 @@ export default function ItemDetails({ item, token, onSave, onClose, boxId }) { formData.append('image', fileInputRef.current.files[0]); try { - const response = await axios.post(`${process.env.REACT_APP_API_URL}/items/${item.ID}/upload`, formData, { + const response = await axios.post(`${process.env.REACT_APP_API_URL}/api/v1/items/${item.ID}/upload`, formData, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'multipart/form-data' @@ -141,7 +141,7 @@ export default function ItemDetails({ item, token, onSave, onClose, boxId }) { const updateItemBoxId = async () => { try { // eslint-disable-next-line - const response = await axios.put(`${process.env.REACT_APP_API_URL}/items/${item.id}`, { + const response = await axios.put(`${process.env.REACT_APP_API_URL}/api/v1/items/${item.id}`, { box_id: selectedBoxId, }, { headers: { Authorization: `Bearer ${token}` } @@ -164,7 +164,7 @@ export default function ItemDetails({ item, token, onSave, onClose, boxId }) { // 2. Update item details (name, description, etc.) try { - await axios.put(`${process.env.REACT_APP_API_URL}/items/${item.ID}`, { + await axios.put(`${process.env.REACT_APP_API_URL}/api/v1/items/${item.ID}`, { name, description, box_id: +selectedBoxId, // Ensure the updated selected box is saved diff --git a/src/components/Items.js b/src/components/Items.js index 14cdafb..fed9ac1 100644 --- a/src/components/Items.js +++ b/src/components/Items.js @@ -45,7 +45,7 @@ export default function Items({ token }) { const [openAddItemDialog, setOpenAddItemDialog] = useState(false); // For Add Item dialog const { id } = useParams(); const boxID = id; - const url = boxId === undefined ? `${process.env.REACT_APP_API_URL}/items` : `${process.env.REACT_APP_API_URL}/boxes/${boxId}/items`; + const url = boxId === undefined ? `${process.env.REACT_APP_API_URL}/api/v1/items` : `${process.env.REACT_APP_API_URL}/api/v1/boxes/${boxId}/items`; const [searchQuery, setSearchQuery] = useState(''); const debugLog = (message) => { @@ -109,7 +109,7 @@ export default function Items({ token }) { }); try { - const response = await axios.post(`${process.env.REACT_APP_API_URL}/items/${itemId}/upload`, formData, { + const response = await axios.post(`${process.env.REACT_APP_API_URL}/api/v1/items/${itemId}/upload`, formData, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'multipart/form-data' @@ -137,7 +137,7 @@ export default function Items({ token }) { // This sends a request to the API to create a new item with the // name and description provided. The box_id is set to the selected // box ID. - const newItemResponse = await axios.post(`${process.env.REACT_APP_API_URL}/items`, { + const newItemResponse = await axios.post(`${process.env.REACT_APP_API_URL}/api/v1/items`, { name: newItemName, description: newItemDescription, box_id: parseInt(boxId, 10) // Ensure boxId is converted to an integer @@ -218,7 +218,7 @@ export default function Items({ token }) { }; const getImageSrc = useCallback((itemId) => { - return axios.get(`${process.env.REACT_APP_API_URL}/items/${itemId}/image`, { + return axios.get(`${process.env.REACT_APP_API_URL}/api/v1/items/${itemId}/image`, { headers: { Authorization: `Bearer ${token}` }, responseType: 'blob' }) @@ -302,7 +302,7 @@ export default function Items({ token }) { // }; const handleDeleteItem = (itemId) => { - axios.delete(`${process.env.REACT_APP_API_URL}/items/${itemId}`, { + axios.delete(`${process.env.REACT_APP_API_URL}/api/v1/items/${itemId}`, { headers: { Authorization: `Bearer ${token}` } }).then(() => { fetchItems(); diff --git a/src/components/Login.js b/src/components/Login.js index fdce747..3a1ca21 100644 --- a/src/components/Login.js +++ b/src/components/Login.js @@ -16,7 +16,7 @@ export default function Login({ setToken }) { setLoginError(false); // Reset error state on each login attempt try { // eslint-disable-next-line no-template-curly-in-string - const response = await axios.post(`${process.env.REACT_APP_API_URL}/login`, { username, password }); + const response = await axios.post(`${process.env.REACT_APP_API_URL}/api/v1/login`, { username, password }); setToken(response.data.token); navigate('/boxes'); } catch (error) { diff --git a/src/components/Navbar.js b/src/components/Navbar.js index 2a40079..8fcefab 100644 --- a/src/components/Navbar.js +++ b/src/components/Navbar.js @@ -33,10 +33,10 @@ export default function Navbar() { Boxes - - - - + + + +