2025-10-28 11:45:51 -03:00
|
|
|
// frontend/src/services/apiService.ts
|
|
|
|
|
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
import type { Titular } from '../types';
|
|
|
|
|
|
2025-10-28 12:26:49 -03:00
|
|
|
const API_URL = 'http://localhost:5174/api';
|
2025-10-28 11:45:51 -03:00
|
|
|
|
|
|
|
|
const apiClient = axios.create({
|
|
|
|
|
baseURL: API_URL,
|
2025-10-28 11:54:36 -03:00
|
|
|
headers: { 'Content-Type': 'application/json' },
|
2025-10-28 11:45:51 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const obtenerTitulares = async (): Promise<Titular[]> => {
|
|
|
|
|
const response = await apiClient.get('/titulares');
|
|
|
|
|
return response.data;
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-28 11:54:36 -03:00
|
|
|
export const crearTitularManual = async (texto: string): Promise<void> => {
|
|
|
|
|
await apiClient.post('/titulares', { texto });
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-28 11:45:51 -03:00
|
|
|
export const eliminarTitular = async (id: number): Promise<void> => {
|
|
|
|
|
await apiClient.delete(`/titulares/${id}`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
interface ReordenarPayload {
|
|
|
|
|
id: number;
|
|
|
|
|
nuevoOrden: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const actualizarOrdenTitulares = async (payload: ReordenarPayload[]): Promise<void> => {
|
|
|
|
|
await apiClient.put('/titulares/reordenar', payload);
|
|
|
|
|
};
|