21 lines
661 B
TypeScript
21 lines
661 B
TypeScript
import type { Todo } from '../types/todo';
|
|
import { api } from './axios';
|
|
|
|
export const getTodos = async (): Promise<Todo[]> => {
|
|
const response = await api.get('/api/todos');
|
|
return response.data;
|
|
};
|
|
|
|
export const addTodo = async (title: string, priority: Todo['priority']): Promise<Todo> => {
|
|
const response = await api.post('/api/todos', { title, priority });
|
|
return response.data;
|
|
};
|
|
|
|
export const toggleTodo = async (id: number): Promise<Todo> => {
|
|
const response = await api.patch(`/api/todos/${id}/toggle`);
|
|
return response.data;
|
|
};
|
|
|
|
export const deleteTodo = async (id: number): Promise<void> => {
|
|
await api.delete(`/api/todos/${id}`);
|
|
};
|