initialize Vite + React + TypeScript project with Tailwind CSS and API service setup

This commit is contained in:
2025-02-01 00:33:24 -03:00
commit f133e18302
31 changed files with 5317 additions and 0 deletions

37
src/services/api/api.ts Normal file
View File

@@ -0,0 +1,37 @@
import { ApiService } from './index';
import { Pet } from '../../types/Pet';
import { PetCreationRequest } from '../../types/PetCreationRequest';
import { PetUpdateActionRequest } from '../../types/PetUpdateActionRequest';
// Get API service instance
const api = ApiService.getInstance();
export async function fetchPets(): Promise<Pet[]> {
try {
const response = await api.get<Pet[]>('/api/v1/pet');
return response.data;
} catch (error: any) {
console.error('Failed to fetch pets:', error.message);
throw error;
}
}
export async function createPet(data: PetCreationRequest): Promise<Pet> {
try {
const response = await api.post<Pet>('/api/v1/pet', data);
return response.data;
} catch (error: any) {
console.error('Failed to create pet:', error.message);
throw error;
}
}
export async function updatePetAction(petId: string, data: PetUpdateActionRequest): Promise<Pet> {
try {
const response = await api.put<Pet>(`/api/v1/pet/${petId}/action`, data);
return response.data;
} catch (error: any) {
console.error('Failed to update pet action:', error.message);
throw error;
}
}