mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-19 05:54:07 +01:00
Add funtion fetch tasks by ID and all tags
This commit is contained in:
parent
dbb70d8af6
commit
45dcfba95b
@ -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 => {
|
||||||
|
console.log("apiUserLogin error: ", error);
|
||||||
return 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
|
// Function for Google login
|
||||||
const googleLogin = async (token) => {
|
const googleLogin = async token => {
|
||||||
axios.defaults.withCredentials = true
|
axios.defaults.withCredentials = true;
|
||||||
let res = await axios.post(
|
let res = await axios.post("http://localhost:8000/api/auth/google/", {
|
||||||
"http://localhost:8000/api/auth/google/",
|
|
||||||
{
|
|
||||||
code: token,
|
code: token,
|
||||||
}
|
});
|
||||||
);
|
|
||||||
// console.log('service google login res: ', res);
|
// console.log('service google login res: ', res);
|
||||||
return await 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 => {
|
})
|
||||||
|
.catch(error => {
|
||||||
return 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,
|
||||||
};
|
};
|
||||||
|
|||||||
12
frontend/src/api/TagApi.jsx
Normal file
12
frontend/src/api/TagApi.jsx
Normal 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;
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -1,10 +1,20 @@
|
|||||||
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;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fetchTodoTasksID = id => {
|
||||||
|
return axiosInstance
|
||||||
|
.get(`todo/${id}/`)
|
||||||
|
.then(response => {
|
||||||
return response.data;
|
return response.data;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user