mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-18 21:44: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 = () => {
|
||||
return axiosInstance
|
||||
.get("tags/")
|
||||
.then(response => {
|
||||
return response.data;
|
||||
})
|
||||
.catch(error => {
|
||||
throw error;
|
||||
});
|
||||
};
|
||||
// CRUD functions for "tags" endpoint
|
||||
export const createTag = data => createTask("tags", data);
|
||||
export const readTags = () => readTasks("tags");
|
||||
export const readTagByID = id => readTaskByID("tags", id);
|
||||
export const updateTag = (id, data) => updateTask("tags", id, data);
|
||||
export const deleteTag = id => deleteTask("tags", id);
|
||||
|
||||
@ -1,23 +1,73 @@
|
||||
import axiosInstance from "./configs/AxiosConfig";
|
||||
|
||||
export const fetchTodoTasks = () => {
|
||||
const baseURL = "";
|
||||
|
||||
export const createTask = (endpoint, data) => {
|
||||
return axiosInstance
|
||||
.get("todo/")
|
||||
.then(response => {
|
||||
return response.data;
|
||||
})
|
||||
.post(`${baseURL}${endpoint}/`, data)
|
||||
.then(response => response.data)
|
||||
.catch(error => {
|
||||
throw error;
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchTodoTasksID = id => {
|
||||
export const readTasks = endpoint => {
|
||||
return axiosInstance
|
||||
.get(`todo/${id}/`)
|
||||
.then(response => {
|
||||
return response.data;
|
||||
})
|
||||
.get(`${baseURL}${endpoint}/`)
|
||||
.then(response => response.data)
|
||||
.catch(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;
|
||||
|
||||
// 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 => {
|
||||
return response.map(item => ({
|
||||
id: createEventId(),
|
||||
@ -29,7 +13,7 @@ const mapResponseToEvents = response => {
|
||||
|
||||
export async function getEvents() {
|
||||
try {
|
||||
const response = await fetchTodoTasks();
|
||||
const response = await readTodoTasks();
|
||||
return mapResponseToEvents(response);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user