feat(countries): implement CRUD operations and UI for country management, including dialogs and data table with infinite scroll

This commit is contained in:
2025-11-02 15:40:26 -06:00
parent 39365f4e83
commit 27b5880524
10 changed files with 1072 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
/**
* API Client para Countries
* Gestiona las operaciones CRUD para los países
*/
import { api } from '$lib/api';
export interface Country {
m3_key: string;
mex_key: string;
ame_key: string;
description_es: string;
description_en: string;
}
export interface CountryListResponse {
items: Country[];
total: number;
page: number;
page_size: number;
}
export interface CreateCountryData {
m3_key: string;
mex_key: string;
ame_key: string;
description_es: string;
description_en: string;
}
export interface UpdateCountryData {
m3_key?: string;
mex_key?: string;
ame_key?: string;
description_es?: string;
description_en?: string;
}
/**
* API para Countries
*/
export const countriesApi = {
/**
* Lista todos los países con paginación
* @param page - Número de página (por defecto 1)
* @param pageSize - Tamaño de página (por defecto 50)
*/
list: (page = 1, pageSize = 50) =>
api.get<CountryListResponse>(
`/v1/countries?page=${page}&page_size=${pageSize}`
),
/**
* Obtiene un país por su clave M3
* @param m3_key - Clave M3 del país
*/
get: (m3_key: string) => api.get<Country>(`/v1/countries/${m3_key}`),
/**
* Crea un nuevo país
* @param data - Datos del país a crear
*/
create: (data: CreateCountryData) =>
api.post<Country>('/v1/countries', data),
/**
* Actualiza un país existente
* @param m3_key - Clave M3 del país a actualizar
* @param data - Datos a actualizar
*/
update: (m3_key: string, data: UpdateCountryData) =>
api.put<Country>(`/v1/countries/${m3_key}`, data),
/**
* Elimina un país
* @param m3_key - Clave M3 del país a eliminar
*/
delete: (m3_key: string) => api.delete(`/v1/countries/${m3_key}`)
};