Files
game-marathon/frontend/src/api/shop.ts
2026-01-08 10:02:15 +07:00

110 lines
3.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import client from './client'
import type {
ShopItem,
ShopItemType,
InventoryItem,
PurchaseResponse,
UseConsumableRequest,
UseConsumableResponse,
CoinsBalance,
CoinTransaction,
ConsumablesStatus,
UserCosmetics,
SwapCandidate,
} from '@/types'
export const shopApi = {
// === Каталог товаров ===
// Получить список товаров
getItems: async (itemType?: ShopItemType): Promise<ShopItem[]> => {
const params = itemType ? { item_type: itemType } : {}
const response = await client.get<ShopItem[]>('/shop/items', { params })
return response.data
},
// Получить товар по ID
getItem: async (itemId: number): Promise<ShopItem> => {
const response = await client.get<ShopItem>(`/shop/items/${itemId}`)
return response.data
},
// === Покупки ===
// Купить товар
purchase: async (itemId: number, quantity: number = 1): Promise<PurchaseResponse> => {
const response = await client.post<PurchaseResponse>('/shop/purchase', {
item_id: itemId,
quantity,
})
return response.data
},
// === Инвентарь ===
// Получить инвентарь пользователя
getInventory: async (itemType?: ShopItemType): Promise<InventoryItem[]> => {
const params = itemType ? { item_type: itemType } : {}
const response = await client.get<InventoryItem[]>('/shop/inventory', { params })
return response.data
},
// === Экипировка ===
// Экипировать предмет
equip: async (inventoryId: number): Promise<{ success: boolean; message: string }> => {
const response = await client.post<{ success: boolean; message: string }>('/shop/equip', {
inventory_id: inventoryId,
})
return response.data
},
// Снять предмет
unequip: async (itemType: ShopItemType): Promise<{ success: boolean; message: string }> => {
const response = await client.post<{ success: boolean; message: string }>(`/shop/unequip/${itemType}`)
return response.data
},
// Получить экипированную косметику
getCosmetics: async (): Promise<UserCosmetics> => {
const response = await client.get<UserCosmetics>('/shop/cosmetics')
return response.data
},
// === Расходуемые ===
// Использовать расходуемый предмет
useConsumable: async (data: UseConsumableRequest): Promise<UseConsumableResponse> => {
const response = await client.post<UseConsumableResponse>('/shop/use', data)
return response.data
},
// Получить статус расходуемых в марафоне
getConsumablesStatus: async (marathonId: number): Promise<ConsumablesStatus> => {
const response = await client.get<ConsumablesStatus>(`/shop/consumables/${marathonId}`)
return response.data
},
// Получить кандидатов для Copycat (участники с активными заданиями)
getCopycatCandidates: async (marathonId: number): Promise<SwapCandidate[]> => {
const response = await client.get<SwapCandidate[]>(`/shop/copycat-candidates/${marathonId}`)
return response.data
},
// === Монеты ===
// Получить баланс и последние транзакции
getBalance: async (): Promise<CoinsBalance> => {
const response = await client.get<CoinsBalance>('/shop/balance')
return response.data
},
// Получить историю транзакций
getTransactions: async (limit: number = 50, offset: number = 0): Promise<CoinTransaction[]> => {
const response = await client.get<CoinTransaction[]>('/shop/transactions', {
params: { limit, offset },
})
return response.data
},
}