Skip to content

Commit 2c85ea0

Browse files
committed
update TaskApiService.js APIS
1 parent 51240c8 commit 2c85ea0

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import axios from "axios";
2+
import { getBasicAuth } from "./AuthApiService";
3+
4+
const API_BASE_URL = 'http://localhost:8080/api/v1/tasks';
5+
6+
axios.interceptors.response.use(
7+
response => response,
8+
error => {
9+
10+
console.error('API request error:', error);
11+
return Promise.reject(error);
12+
}
13+
14+
);
15+
16+
export const retrieveAllTasks = (userId) =>
17+
axios.get(`${API_BASE_URL}/user/${userId}`, {
18+
headers: {
19+
'Authorization': getBasicAuth()
20+
}
21+
});
22+
23+
export const createTask = (task, userId) =>
24+
axios.post(`${API_BASE_URL}/user/${userId}`, task, {
25+
headers: {
26+
'Authorization': getBasicAuth()
27+
}
28+
});
29+
30+
export const retrieveTaskById = (taskId) =>
31+
axios.get(`${API_BASE_URL}/${taskId}`, {
32+
headers: {
33+
'Authorization': getBasicAuth()
34+
}
35+
});
36+
37+
export const updateTask = (task, id) =>
38+
axios.put(`${API_BASE_URL}/${id}`, task, {
39+
headers: {
40+
'Authorization': getBasicAuth()
41+
}
42+
});
43+
44+
export const deleteTask = (id) =>
45+
axios.delete(`${API_BASE_URL}/${id}`, {
46+
headers: {
47+
'Authorization': getBasicAuth()
48+
}
49+
});
50+
51+
export const markDone = (id) =>
52+
axios.patch(`${API_BASE_URL}/${id}/task-done`, null, {
53+
headers: {
54+
'Authorization': getBasicAuth()
55+
}
56+
});
57+
58+
export const markPending = (id) =>
59+
axios.patch(`${API_BASE_URL}/${id}/task-pending`, null, {
60+
headers: {
61+
'Authorization': getBasicAuth()
62+
}
63+
});

0 commit comments

Comments
 (0)