mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-19 22:14:07 +01:00
Add Tasks Api fetcher
This commit is contained in:
parent
4d96f8c94e
commit
4be0efc0bb
@ -1,12 +1,8 @@
|
|||||||
import axiosInstance from "./configs/AxiosConfig";
|
import { createTask, readTasks, readTaskByID, updateTask, deleteTask } from "./TaskApi";
|
||||||
|
|
||||||
export const fetchTags = () => {
|
// CRUD functions for "tags" endpoint
|
||||||
return axiosInstance
|
export const createTag = data => createTask("tags", data);
|
||||||
.get("tags/")
|
export const readTags = () => readTasks("tags");
|
||||||
.then(response => {
|
export const readTagByID = id => readTaskByID("tags", id);
|
||||||
return response.data;
|
export const updateTag = (id, data) => updateTask("tags", id, data);
|
||||||
})
|
export const deleteTag = id => deleteTask("tags", id);
|
||||||
.catch(error => {
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|||||||
@ -1,23 +1,73 @@
|
|||||||
import axiosInstance from "./configs/AxiosConfig";
|
import axiosInstance from "./configs/AxiosConfig";
|
||||||
|
|
||||||
export const fetchTodoTasks = () => {
|
const baseURL = "";
|
||||||
|
|
||||||
|
export const createTask = (endpoint, data) => {
|
||||||
return axiosInstance
|
return axiosInstance
|
||||||
.get("todo/")
|
.post(`${baseURL}${endpoint}/`, data)
|
||||||
.then(response => {
|
.then(response => response.data)
|
||||||
return response.data;
|
|
||||||
})
|
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fetchTodoTasksID = id => {
|
export const readTasks = endpoint => {
|
||||||
return axiosInstance
|
return axiosInstance
|
||||||
.get(`todo/${id}/`)
|
.get(`${baseURL}${endpoint}/`)
|
||||||
.then(response => {
|
.then(response => response.data)
|
||||||
return response.data;
|
|
||||||
})
|
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const readTaskByID = (endpoint, id) => {
|
||||||
|
return axiosInstance
|
||||||
|
.get(`${baseURL}${endpoint}/${id}/`)
|
||||||
|
.then(response => response.data)
|
||||||
|
.catch(error => {
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updateTask = (endpoint, id, data) => {
|
||||||
|
return axiosInstance
|
||||||
|
.put(`${baseURL}${endpoint}/${id}/`, data)
|
||||||
|
.then(response => response.data)
|
||||||
|
.catch(error => {
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteTask = (endpoint, id) => {
|
||||||
|
return axiosInstance
|
||||||
|
.delete(`${baseURL}${endpoint}/${id}/`)
|
||||||
|
.then(response => response.data)
|
||||||
|
.catch(error => {
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create
|
||||||
|
export const createTodoTask = data => createTask("todo", data);
|
||||||
|
export const createRecurrenceTask = data => createTask("daily", data);
|
||||||
|
export const createHabitTask = data => createTask("habit", data);
|
||||||
|
|
||||||
|
// Read
|
||||||
|
export const readTodoTasks = () => readTasks("todo");
|
||||||
|
export const readRecurrenceTasks = () => readTasks("daily");
|
||||||
|
export const readHabitTasks = () => readTasks("habit");
|
||||||
|
|
||||||
|
// Read by ID
|
||||||
|
export const readTodoTaskByID = id => readTaskByID("todo", id);
|
||||||
|
export const readRecurrenceTaskByID = id => readTaskByID("daily", id);
|
||||||
|
export const readHabitTaskByID = id => readTaskByID("habit", id);
|
||||||
|
|
||||||
|
// Update
|
||||||
|
export const updateTodoTask = (id, data) => updateTask("todo", id, data);
|
||||||
|
export const updateRecurrenceTask = (id, data) => updateTask("daily", id, data);
|
||||||
|
export const updateHabitTask = (id, data) => updateTask("habit", id, data);
|
||||||
|
|
||||||
|
// Delete
|
||||||
|
export const deleteTodoTask = id => deleteTask("todo", id);
|
||||||
|
export const deleteRecurrenceTask = id => deleteTask("daily", id);
|
||||||
|
export const deleteHabitTask = id => deleteTask("habit", id);
|
||||||
|
|||||||
@ -1,23 +1,7 @@
|
|||||||
import { fetchTodoTasks } from "../../api/TaskApi";
|
import { readTodoTasks } from "../../api/TaskApi";
|
||||||
|
|
||||||
let eventGuid = 0;
|
let eventGuid = 0;
|
||||||
|
|
||||||
// function getDateAndTime(dateString) {
|
|
||||||
// const dateObject = new Date(dateString);
|
|
||||||
|
|
||||||
// const year = dateObject.getFullYear();
|
|
||||||
// const month = (dateObject.getMonth() + 1).toString().padStart(2, '0');
|
|
||||||
// const day = dateObject.getDate().toString().padStart(2, '0');
|
|
||||||
// const dateFormatted = `${year}-${month}-${day}`;
|
|
||||||
|
|
||||||
// const hours = dateObject.getUTCHours().toString().padStart(2, '0');
|
|
||||||
// const minutes = dateObject.getUTCMinutes().toString().padStart(2, '0');
|
|
||||||
// const seconds = dateObject.getUTCSeconds().toString().padStart(2, '0');
|
|
||||||
// const timeFormatted = `T${hours}:${minutes}:${seconds}`;
|
|
||||||
|
|
||||||
// return dateFormatted + timeFormatted;
|
|
||||||
// }
|
|
||||||
|
|
||||||
const mapResponseToEvents = response => {
|
const mapResponseToEvents = response => {
|
||||||
return response.map(item => ({
|
return response.map(item => ({
|
||||||
id: createEventId(),
|
id: createEventId(),
|
||||||
@ -29,7 +13,7 @@ const mapResponseToEvents = response => {
|
|||||||
|
|
||||||
export async function getEvents() {
|
export async function getEvents() {
|
||||||
try {
|
try {
|
||||||
const response = await fetchTodoTasks();
|
const response = await readTodoTasks();
|
||||||
return mapResponseToEvents(response);
|
return mapResponseToEvents(response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user