69 lines
2.5 KiB
TypeScript
69 lines
2.5 KiB
TypeScript
import { ApiService } from './index';
|
|
import { InvItemInteraction, Pet, Resources } from '../../types/Pet';
|
|
import { PetCreationRequest } from '../../types/PetCreationRequest';
|
|
import { PetActionGathered, PetUpdateActionRequest } from '../../types/PetAction';
|
|
import { PetSkill, Skill } from '../../types/Skills';
|
|
import { GameItem } from '../../types/GameItem';
|
|
|
|
// Get API service instance
|
|
const api = ApiService.getInstance();
|
|
|
|
export async function fetchPets(): Promise<Pet[]> {
|
|
const response = await api.get<Pet[]>('/api/v1/pet');
|
|
return response.data;
|
|
}
|
|
|
|
export async function createPet(data: PetCreationRequest): Promise<Pet> {
|
|
const response = await api.post<Pet>('/api/v1/pet', data);
|
|
return response.data;
|
|
}
|
|
|
|
export async function updatePetAction(petId: string, data: PetUpdateActionRequest): Promise<Pet> {
|
|
const response = await api.put<Pet>(`/api/v1/pet/${petId}/action`, data);
|
|
return response.data;
|
|
}
|
|
|
|
export async function getPetGatheredResources(petId: string): Promise<PetActionGathered[]> {
|
|
const response = await api.get<PetActionGathered[]>(`/api/v1/pet/${petId}/resources/gathered`);
|
|
return response.data;
|
|
}
|
|
|
|
export async function putPetCollectResources(petId: string): Promise<Pet> {
|
|
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}/skills`);
|
|
return response.data;
|
|
}
|
|
|
|
export async function postAllocatePetSkill(petId: string, skillId: number): Promise<PetSkill> {
|
|
const response = await api.post<PetSkill>(`/api/v1/skill/${petId}/allocate/${skillId}`);
|
|
return response.data;
|
|
}
|
|
|
|
export async function putPetItemInteract(petId: string, itemId: number, inter: InvItemInteraction): Promise<Pet> {
|
|
const response = await api.put<Pet>(`/api/v1/inventory/${petId}/${itemId}/${inter.toLowerCase()}`);
|
|
return response.data;
|
|
}
|
|
|
|
export async function getItemInfo(itemId: number): Promise<GameItem> {
|
|
const response = await api.get<GameItem>(`/api/v1/gamedata/item/${itemId}`);
|
|
return response.data;
|
|
}
|
|
|
|
export async function getItemIcon(itemId: number): Promise<Blob> {
|
|
const response = await api.get<Blob>(`/api/v1/gamedata/item/${itemId}/icon`, {
|
|
responseType: 'blob',
|
|
headers: {
|
|
Accept: 'image/png'
|
|
}
|
|
});
|
|
return response.data;
|
|
} |