refactor: update pet action handling and restructure pet types for better clarity

This commit is contained in:
2025-02-01 15:33:42 -03:00
parent 8875eb75af
commit a85a80938b
11 changed files with 226 additions and 216 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ export async function createPet(data: PetCreationRequest): Promise<Pet> {
export async function updatePetAction(petId: string, data: PetUpdateActionRequest): Promise<Pet> {
try {
const response = await api.put<Pet>(`/api/v1/pet/${petId}/action/gather`, data);
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);
-45
View File
@@ -1,45 +0,0 @@
// Example usage of the API service
import { ApiService } from './index';
import { Pet } from '../../types/Pet';
// Get API service instance
const api = ApiService.getInstance();
// Example functions using the API service
export async function getPet(id: string) {
try {
const response = await api.get<Pet>(`/pets/${id}`);
return response.data;
} catch (error: any) {
if (api.isNetworkError(error)) {
console.error('Network error occurred');
} else if (api.isTimeoutError(error)) {
console.error('Request timed out');
} else if (api.isServerError(error)) {
console.error('Server error occurred');
}
throw error;
}
}
export async function updatePet(id: string, data: Partial<Pet>) {
try {
const response = await api.put<Pet>(`/pets/${id}`, data);
return response.data;
} catch (error: any) {
console.error('Failed to update pet:', error.message);
throw error;
}
}
export async function gatherResources(id: string, resourceType: string) {
try {
const response = await api.post<{ success: boolean }>(`/pets/${id}/gather`, {
resourceType,
});
return response.data;
} catch (error: any) {
console.error('Failed to gather resources:', error.message);
throw error;
}
}