Fase 2: Gestor de Taxonomía (Árbol de Categorías) - Backend CORS y Frontend CRUD Recursivo
This commit is contained in:
27
frontend/admin-panel/src/services/categoryService.ts
Normal file
27
frontend/admin-panel/src/services/categoryService.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import api from './api';
|
||||
import { Category } from '../types/Category';
|
||||
|
||||
export const categoryService = {
|
||||
getAll: async (): Promise<Category[]> => {
|
||||
const response = await api.get<Category[]>('/categories');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
getById: async (id: number): Promise<Category> => {
|
||||
const response = await api.get<Category>(`/categories/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
create: async (category: Partial<Category>): Promise<Category> => {
|
||||
const response = await api.post<Category>('/categories', category);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
update: async (id: number, category: Partial<Category>): Promise<void> => {
|
||||
await api.put(`/categories/${id}`, category);
|
||||
},
|
||||
|
||||
delete: async (id: number): Promise<void> => {
|
||||
await api.delete(`/categories/${id}`);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user