feat: enhance pet management with new skills and inventory system

This commit is contained in:
2025-02-05 20:10:38 -03:00
parent dd32327383
commit a624ba1e73
4 changed files with 65 additions and 40 deletions

View File

@@ -2,56 +2,47 @@ import { ApiService } from './index';
import { Pet, Resources } from '../../types/Pet';
import { PetCreationRequest } from '../../types/PetCreationRequest';
import { PetUpdateActionRequest } from '../../types/PetUpdateActionRequest';
import { PetSkill, Skill } from '../../types/Skills';
// 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;
}
const response = await api.get<Pet[]>('/api/v1/pet');
return response.data;
}
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;
}
const response = await api.post<Pet>('/api/v1/pet', data);
return response.data;
}
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;
}
const response = await api.put<Pet>(`/api/v1/pet/${petId}/action`, data);
return response.data;
}
export async function getPetGatheredResources(petId: string): Promise<Resources> {
try {
const response = await api.get<Resources>(`/api/v1/pet/${petId}/resources/gathered`);
return response.data;
} catch (error: any) {
console.error('Failed to fetch pet gathered resources:', error.message);
throw error;
}
const response = await api.get<Resources>(`/api/v1/pet/${petId}/resources/gathered`);
return response.data;
}
export async function putPetCollectResources(petId: string): Promise<Pet> {
try {
const response = await api.put<Pet>(`/api/v1/pet/${petId}/resources/collect`);
return response.data;
} catch (error: any) {
console.error('Failed to collect pet gathered resources:', error.message);
throw error;
}
const response = await api.put<Pet>(`/api/v1/pet/${petId}/resources/collect`);
return response.data;
}
export async function getAllSkills(): Promise<Skill[]> {
const response = await api.get<Skill[]>(`/api/v1/skill`);
return response.data;
}
export async function getPetSkills(petId: string): Promise<PetSkill[]> {
const response = await api.get<PetSkill[]>(`/api/v1/skill/${petId}/pet`);
return response.data;
}
export async function postAllocatePetSkill(petId: string, skillId: int): Promise<PetSkill> {
const response = await api.get<PetSkill>(`/api/v1/skill/${petId}/allocate/${skillId}`);
return response.data;
}