Add funtion fetch tasks by ID and all tags

This commit is contained in:
sosokker 2023-11-11 23:18:20 +07:00
parent dbb70d8af6
commit 45dcfba95b
3 changed files with 77 additions and 59 deletions

View File

@ -1,61 +1,59 @@
import axios from 'axios'; import axios from "axios";
import axiosInstance from './configs/AxiosConfig'; import axiosInstance from "./configs/AxiosConfig";
// Function for user login // Function for user login
const apiUserLogin = (data) => { const apiUserLogin = data => {
return axiosInstance return axiosInstance
.post('token/obtain/', data) .post("token/obtain/", data)
.then((response) => { .then(response => {
console.log(response.statusText); console.log(response.statusText);
return response; return response;
}).catch(error => { })
console.log('apiUserLogin error: ', error); .catch(error => {
return error; console.log("apiUserLogin error: ", error);
}); return error;
});
}; };
// Function for user logout // Function for user logout
const apiUserLogout = () => { const apiUserLogout = () => {
axiosInstance.defaults.headers['Authorization'] = ""; // Clear authorization header axiosInstance.defaults.headers["Authorization"] = ""; // Clear authorization header
localStorage.removeItem('access_token'); // Remove access token localStorage.removeItem("access_token"); // Remove access token
localStorage.removeItem('refresh_token'); // Remove refresh token localStorage.removeItem("refresh_token"); // Remove refresh token
}
// Function for Google login
const googleLogin = async (token) => {
axios.defaults.withCredentials = true
let res = await axios.post(
"http://localhost:8000/api/auth/google/",
{
code: token,
}
);
// console.log('service google login res: ', res);
return await res;
}; };
// Function for Google login
const googleLogin = async token => {
axios.defaults.withCredentials = true;
let res = await axios.post("http://localhost:8000/api/auth/google/", {
code: token,
});
// console.log('service google login res: ', res);
return await res;
};
// Function to get 'hello' data // Function to get 'hello' data
const getGreeting = () => { const getGreeting = () => {
return axiosInstance return axiosInstance
.get('hello') .get("hello")
.then((response) => { .then(response => {
return response; return response;
}).catch(error => { })
return error; .catch(error => {
}); return error;
} });
};
const config = { const config = {
headers: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json",
} },
}; };
// Function to register // Function to register
const createUser = async (formData) => { const createUser = async formData => {
try { try {
axios.defaults.withCredentials = true axios.defaults.withCredentials = true;
const resposne = axios.post("http://localhost:8000/api/user/create/", formData); const resposne = axios.post("http://localhost:8000/api/user/create/", formData);
// const response = await axiosInstance.post('/user/create/', formData); // const response = await axiosInstance.post('/user/create/', formData);
return response.data; return response.data;
@ -64,13 +62,11 @@ const createUser = async (formData) => {
} }
}; };
// Export the functions and Axios instance // Export the functions and Axios instance
export default { export default {
axiosInstance, apiUserLogin,
apiUserLogin, apiUserLogout,
apiUserLogout, getGreeting: getGreeting,
getGreeting: getGreeting, googleLogin,
googleLogin, createUser,
createUser
}; };

View File

@ -0,0 +1,12 @@
import axiosInstance from "./configs/AxiosConfig";
export const fetchTags = () => {
return axiosInstance
.get("tags/")
.then(response => {
return response.data;
})
.catch(error => {
throw error;
});
};

View File

@ -1,13 +1,23 @@
import axios from 'axios'; import axiosInstance from "./configs/AxiosConfig";
import axiosInstance from './configs/AxiosConfig';
export const fetchTodoTasks = () => { export const fetchTodoTasks = () => {
return axiosInstance return axiosInstance
.get('todo/') .get("todo/")
.then((response) => { .then(response => {
return response.data; return response.data;
}) })
.catch(error => { .catch(error => {
throw error; throw error;
}); });
};
export const fetchTodoTasksID = id => {
return axiosInstance
.get(`todo/${id}/`)
.then(response => {
return response.data;
})
.catch(error => {
throw error;
});
}; };