blob: ffc0c28ad42e427fad932b9efbda0a2a0eccbb65 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
import api from "./axios_config";
// findAll() on Back End.
export function get_todos_function() {
// Get a list of all to dos.
// GET "/todos"
return async (handler) => {
try {
const response = await api.get("/todos");
handler(response.data);
} catch (err) {
console.log(err);
}
};
}
// addToDo() on Back End.
export function new_todo_function() {
// Add a new to do on database.
// POST "/todos"
return async (data) => {
try {
await api.post("/todos", {
text: data.text,
dueDate: data.due_date,
priority: data.priority,
});
} catch (err) {
console.log(err);
}
};
}
// editToDo() on BE.
export function edit_todo_function() {
// Edit an existing to do.
// PUT "/todos/{id}"
return async (data) => {
try {
await api.put(`/todos/${data.id}`, {
text: data.text,
dueDate: data.due_date,
priority: data.priority,
});
} catch (err) {
console.log(err);
}
};
}
// removeToDo().
export function remove_todo_function() {
// Remove an existing to do by its id.
// DELETE "/todos/{id}"
return async (data) => {
try {
await api.delete(`/todos/${data.id}`);
} catch (err) {
console.log(err);
}
};
}
// setDone().
export function set_done_function() {
// Set a to do as done. If already done, don't do anything.
// POST "/todos/{id}/done"
return async (data) => {
try {
await api.post(`/todos/${data.id}/done`);
} catch (err) {
console.log(err);
}
};
}
// setUndone().
export function set_undone_function() {
// Set a to do as not done. If it's already not done, don't do anything.
// PUT "/todos/{id}/undone"
return async (data) => {
try {
await api.put(`/todos/${data.id}/undone`);
} catch (err) {
console.log(err);
}
};
}
|