Something went wrong. Try again.
An Android app for exploring the marine life, featuring local names, detailed profiles, and easy search. One-stop-shop for researchers, hob…
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
import axios from 'axios';
// User Signup / Registrationexport const userRegister = async (user) => {
try { const res = await axios.post(`${import.meta.env.VITE_APP_API_BASE_URL}/auth/register`, user); return res.data; } catch (error) { console.log(error); }
};
// User Loginexport const userLogin = async (user) => {
try { const res = await axios.post(`${import.meta.env.VITE_APP_API_BASE_URL}/auth/login`, user); return res.data; } catch (error) { console.log(error); console.log(error.response.status); return error; }
};
// Get All suggestions
// export const getsuggestions = async (suggestions) => {
// try {// const res = await axios.get(`${import.meta.env.VITE_APP_API_BASE_URL}/v1/suggestions`, suggestions);// return res.data;// } catch (error) {// console.log(error);// console.log(error.response.status);// return error; // }
// };
//get suggestions
export const getsuggestions = async (suggestions) => { try { // Retrieve cookies and find the token const cookies = document.cookie.split(';'); const tokenCookie = cookies.find(cookie => cookie.trim().startsWith('token=')); if (!tokenCookie) { throw new Error('No token found in cookie'); } // Extract the token value from the cookie const token = tokenCookie.split('=')[1].trim(); // Ensure the token is not empty if (!token) { throw new Error('Token is empty'); } // Make the API call with the token in headers const res = await axios.get(`${import.meta.env.VITE_APP_API_BASE_URL}/api/v1/suggestions`, { headers: { Authorization: `Bearer ${token}`, }, params: suggestions // Use params to pass suggestions as query parameters }); // console.log(res); return res; } catch (error) { console.error('Error fetching suggestions:', error.response ? error.response.data : error.message); return error; } };
export const marksuggestions = async (suggestionId) => { try { // Retrieve cookies and find the token const cookies = document.cookie.split(';'); const tokenCookie = cookies.find(cookie => cookie.trim().startsWith('token=')); if (!tokenCookie) { throw new Error('session timeout try login again'); } // Extract the token value from the cookie const token = tokenCookie.split('=')[1].trim(); // Ensure the token is not empty if (!token) { throw new Error('session timeout try login again'); } const id =suggestionId.suggestionId; console.log(suggestionId.status); const status = suggestionId.status // Make the API call with the token in headers const res = await axios.patch(`${import.meta.env.VITE_APP_API_BASE_URL}/api/v1/suggestions/${id}`, {status} , { headers: { Authorization: `Bearer ${token}`, }, }); console.log(res); return res; } catch (error) { console.error('Error fetching suggestions:', error.response ? error.response.data : error.message); return error; } };
export const deletesuggestions = async (suggestionId) => { try { // Retrieve cookies and find the token const cookies = document.cookie.split(';'); const tokenCookie = cookies.find(cookie => cookie.trim().startsWith('token='));
if (!tokenCookie) { throw new Error('No token found in cookie'); }
// Extract the token value from the cookie const token = tokenCookie.split('=')[1].trim();
// Ensure the token is not empty if (!token) { throw new Error('Token is empty'); } console.log(suggestionId.suggestionId); const id =suggestionId.suggestionId; // Make the API call with the token in headers const res = await axios.delete(`${import.meta.env.VITE_APP_API_BASE_URL}/api/v1/suggestions/${id}`, { headers: { Authorization: `Bearer ${token}`, }, });
console.log(res); return res; } catch (error) { console.error('Error deleting suggestion:', error.response ? error.response.data : error.message); return error; }};
// get items
export const getitem = async (page) => { try { // Retrieve cookies and find the token const cookies = document.cookie.split(';'); const tokenCookie = cookies.find(cookie => cookie.trim().startsWith('token=')); if (!tokenCookie) { throw new Error('No token found in cookie'); } // Extract the token value from the cookie const token = tokenCookie.split('=')[1].trim(); // Ensure the token is not empty if (!token) { throw new Error('Token is empty'); } // Make the API call with the token in headers const res = await axios.get(`${import.meta.env.VITE_APP_API_BASE_URL}/api/v1/items`, { headers: { Authorization: `Bearer ${token}`, }, params: { page: page },
});
return res; } catch (error) { console.error('Error fetching suggestions:', error.response ? error.response.data : error.message); return error; } };
// delete item (not done) export const deleteitem = async (itemid) => { try { // Retrieve cookies and find the token const cookies = document.cookie.split(';'); const tokenCookie = cookies.find(cookie => cookie.trim().startsWith('token=')); if (!tokenCookie) { throw new Error('No token found in cookie'); } // Extract the token value from the cookie const token = tokenCookie.split('=')[1].trim(); // Ensure the token is not empty if (!token) { throw new Error('Token is empty'); } // Make the API call with the token in headers const res = await axios.delete(`${import.meta.env.VITE_APP_API_BASE_URL}/api/v1/items/${itemid}`, { headers: { Authorization: `Bearer ${token}`, },
}); // console.log(res); return res; } catch (error) { console.error('Error fetching suggestions:', error.response ? error.response.data : error.message); return error; } }; export const edititem = async (itemid , item) => { try { console.log(item); // Retrieve cookies and find the token const cookies = document.cookie.split(';'); const tokenCookie = cookies.find(cookie => cookie.trim().startsWith('token=')); if (!tokenCookie) { window.location.href = '/login'; throw new Error('No token found in cookie'); } // Extract the token value from the cookie const token = tokenCookie.split('=')[1].trim(); // Ensure the token is not empty if (!token) { throw new Error('Token is empty'); } // console.log("item editited ",item); // Make the API call with the token in headers const res = await axios.patch(`${import.meta.env.VITE_APP_API_BASE_URL}/api/v1/items/${itemid}`, item, { headers: { Authorization: `Bearer ${token}`, },
}); // console.log("response aney",res); return res; } catch (error) { console.error('Error fetching suggestions:', error.response ? error.response.data : error.message); return error; } };
// add item export const additem = async (item) => { try {
console.log(item); // Retrieve cookies and find the token const cookies = document.cookie.split(';'); const tokenCookie = cookies.find(cookie => cookie.trim().startsWith('token=')); if (!tokenCookie) { throw new Error('No token found in cookie'); } // Extract the token value from the cookie const token = tokenCookie.split('=')[1].trim(); // Ensure the token is not empty if (!token) { throw new Error('Token is empty'); } // Make the API call with the token in headers const res = await axios.post(`${import.meta.env.VITE_APP_API_BASE_URL}/api/v1/items` ,item, { headers: { Authorization: `Bearer ${token}`, },
}); // console.log(res); return res; } catch (error) { console.error('Error fetching suggestions:', error.response ? error.response.data : error.message); if(error.response.data){ console.log("data" , error.response.data.message ); alert(error.response.data.message); } return error; } };
export const imgtourl = async (item) => { try {
console.log(item); // Retrieve cookies and find the token const cookies = document.cookie.split(';'); const tokenCookie = cookies.find(cookie => cookie.trim().startsWith('token=')); if (!tokenCookie) { throw new Error('No token found in cookie'); } // Extract the token value from the cookie const token = tokenCookie.split('=')[1].trim(); // Ensure the token is not empty if (!token) { throw new Error('Token is empty'); } // Make the API call with the token in headers const res = await axios.post(`${import.meta.env.VITE_APP_API_BASE_URL}/api/v1/items/generateImage` ,item, { headers: { Authorization: `Bearer ${token}`, },
}); // console.log(res); return res; } catch (error) { console.error('Error fetching suggestions:', error.response ? error.response.data : error.message); return error; } };
export const getContact = async () => { try { // Retrieve cookies and find the token const cookies = document.cookie.split(';'); const tokenCookie = cookies.find(cookie => cookie.trim().startsWith('token=')); if (!tokenCookie) { throw new Error('No token found in cookie'); } // Extract the token value from the cookie const token = tokenCookie.split('=')[1].trim(); // Ensure the token is not empty if (!token) { throw new Error('Token is empty'); } // Make the API call with the token in headers const res = await axios.get(`${import.meta.env.VITE_APP_API_BASE_URL}/api/v1/messages`, { headers: { Authorization: `Bearer ${token}`, },
}); //console.log(res); return res; } catch (error) { console.error('Error fetching suggestions:', error.response ? error.response.data : error.message); return error; } }; export const deleteContact = async (message_id) => { try { // Retrieve cookies and find the token const cookies = document.cookie.split(';'); const tokenCookie = cookies.find(cookie => cookie.trim().startsWith('token=')); if (!tokenCookie) { throw new Error('No token found in cookie'); } // Extract the token value from the cookie const token = tokenCookie.split('=')[1].trim(); // Ensure the token is not empty if (!token) { throw new Error('Token is empty'); } console.log(message_id); const id =message_id; // Make the API call with the token in headers const res = await axios.delete(`${import.meta.env.VITE_APP_API_BASE_URL}/api/v1/messages/${id}`, { headers: { Authorization: `Bearer ${token}`, }, }); console.log("deleted contact keto") console.log(res); return res; } catch (error) { console.error('Error deleting suggestion:', error.response ? error.response.data : error.message); return error; } };