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 axiosInstance from './configs/AxiosConfig';
|
||||
import axios from "axios";
|
||||
import axiosInstance from "./configs/AxiosConfig";
|
||||
|
||||
// Function for user login
|
||||
const apiUserLogin = (data) => {
|
||||
return axiosInstance
|
||||
.post('token/obtain/', data)
|
||||
.then((response) => {
|
||||
console.log(response.statusText);
|
||||
return response;
|
||||
}).catch(error => {
|
||||
console.log('apiUserLogin error: ', error);
|
||||
return error;
|
||||
});
|
||||
const apiUserLogin = data => {
|
||||
return axiosInstance
|
||||
.post("token/obtain/", data)
|
||||
.then(response => {
|
||||
console.log(response.statusText);
|
||||
return response;
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("apiUserLogin error: ", error);
|
||||
return error;
|
||||
});
|
||||
};
|
||||
|
||||
// Function for user logout
|
||||
const apiUserLogout = () => {
|
||||
axiosInstance.defaults.headers['Authorization'] = ""; // Clear authorization header
|
||||
localStorage.removeItem('access_token'); // Remove access 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;
|
||||
axiosInstance.defaults.headers["Authorization"] = ""; // Clear authorization header
|
||||
localStorage.removeItem("access_token"); // Remove access 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 to get 'hello' data
|
||||
const getGreeting = () => {
|
||||
return axiosInstance
|
||||
.get('hello')
|
||||
.then((response) => {
|
||||
return response;
|
||||
}).catch(error => {
|
||||
return error;
|
||||
});
|
||||
}
|
||||
return axiosInstance
|
||||
.get("hello")
|
||||
.then(response => {
|
||||
return response;
|
||||
})
|
||||
.catch(error => {
|
||||
return error;
|
||||
});
|
||||
};
|
||||
|
||||
const config = {
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
};
|
||||
|
||||
// Function to register
|
||||
const createUser = async (formData) => {
|
||||
const createUser = async formData => {
|
||||
try {
|
||||
axios.defaults.withCredentials = true
|
||||
axios.defaults.withCredentials = true;
|
||||
const resposne = axios.post("http://localhost:8000/api/user/create/", formData);
|
||||
// const response = await axiosInstance.post('/user/create/', formData);
|
||||
return response.data;
|
||||
@ -64,13 +62,11 @@ const createUser = async (formData) => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Export the functions and Axios instance
|
||||
export default {
|
||||
axiosInstance,
|
||||
apiUserLogin,
|
||||
apiUserLogout,
|
||||
getGreeting: getGreeting,
|
||||
googleLogin,
|
||||
createUser
|
||||
apiUserLogin,
|
||||
apiUserLogout,
|
||||
getGreeting: getGreeting,
|
||||
googleLogin,
|
||||
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,13 +1,23 @@
|
||||
import axios from 'axios';
|
||||
import axiosInstance from './configs/AxiosConfig';
|
||||
import axiosInstance from "./configs/AxiosConfig";
|
||||
|
||||
export const fetchTodoTasks = () => {
|
||||
return axiosInstance
|
||||
.get('todo/')
|
||||
.then((response) => {
|
||||
return response.data;
|
||||
})
|
||||
.catch(error => {
|
||||
throw error;
|
||||
});
|
||||
return axiosInstance
|
||||
.get("todo/")
|
||||
.then(response => {
|
||||
return response.data;
|
||||
})
|
||||
.catch(error => {
|
||||
throw error;
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchTodoTasksID = id => {
|
||||
return axiosInstance
|
||||
.get(`todo/${id}/`)
|
||||
.then(response => {
|
||||
return response.data;
|
||||
})
|
||||
.catch(error => {
|
||||
throw error;
|
||||
});
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user