import apiClient from './apiClient'; import type { PlantaDto } from '../models/dtos/Impresion/PlantaDto'; import type { CreatePlantaDto } from '../models/dtos/Impresion/CreatePlantaDto'; import type { UpdatePlantaDto } from '../models/dtos/Impresion/UpdatePlantaDto'; const getAllPlantas = async (nombreFilter?: string, detalleFilter?: string): Promise => { const params: Record = {}; if (nombreFilter) params.nombre = nombreFilter; if (detalleFilter) params.detalle = detalleFilter; // La API debe soportar esto // Llama a GET /api/plantas const response = await apiClient.get('/plantas', { params }); return response.data; }; const getPlantaById = async (id: number): Promise => { // Llama a GET /api/plantas/{id} const response = await apiClient.get(`/plantas/${id}`); return response.data; }; const createPlanta = async (data: CreatePlantaDto): Promise => { // Llama a POST /api/plantas const response = await apiClient.post('/plantas', data); return response.data; // La API devuelve el objeto creado (201 Created) }; const updatePlanta = async (id: number, data: UpdatePlantaDto): Promise => { // Llama a PUT /api/plantas/{id} (204 No Content en éxito) await apiClient.put(`/plantas/${id}`, data); }; const deletePlanta = async (id: number): Promise => { // Llama a DELETE /api/plantas/{id} (204 No Content en éxito) await apiClient.delete(`/plantas/${id}`); }; const plantaService = { getAllPlantas, getPlantaById, createPlanta, updatePlanta, deletePlanta, }; export default plantaService;