initialize Vite + React + TypeScript project with Tailwind CSS and API service setup
This commit is contained in:
37
src/services/api/api.ts
Normal file
37
src/services/api/api.ts
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user