49 lines
1.0 KiB
TypeScript
49 lines
1.0 KiB
TypeScript
import axios from 'axios'
|
|
import { getToken } from './keycloak'
|
|
|
|
const api = axios.create({
|
|
baseURL: 'http://localhost:5050/api'
|
|
})
|
|
|
|
api.interceptors.request.use(
|
|
(config) => {
|
|
const token = getToken()
|
|
if (token) {
|
|
config.headers.Authorization = `Bearer ${token}`
|
|
}
|
|
return config
|
|
},
|
|
(error) => {
|
|
return Promise.reject(error)
|
|
}
|
|
)
|
|
|
|
export interface Todo {
|
|
id: number
|
|
userId: string
|
|
title: string
|
|
description?: string
|
|
createdAt: string
|
|
completedAt?: string
|
|
isCompleted: boolean
|
|
}
|
|
|
|
export interface TodoCreateDto {
|
|
title: string
|
|
description?: string
|
|
}
|
|
|
|
export interface TodoUpdateDto {
|
|
title?: string
|
|
description?: string
|
|
isCompleted?: boolean
|
|
}
|
|
|
|
export const todoApi = {
|
|
getRecent: () => api.get<Todo[]>('/todos/recent'),
|
|
getAll: () => api.get<Todo[]>('/todos'),
|
|
create: (dto: TodoCreateDto) => api.post<Todo>('/todos', dto),
|
|
update: (id: number, dto: TodoUpdateDto) => api.put<Todo>(`/todos/${id}`, dto),
|
|
delete: (id: number) => api.delete(`/todos/${id}`)
|
|
}
|