2026-01-05 07:15:50 +07:00
|
|
|
|
import client from './client'
|
|
|
|
|
|
import type {
|
|
|
|
|
|
ShopItem,
|
|
|
|
|
|
ShopItemType,
|
|
|
|
|
|
InventoryItem,
|
|
|
|
|
|
PurchaseResponse,
|
|
|
|
|
|
UseConsumableRequest,
|
|
|
|
|
|
UseConsumableResponse,
|
|
|
|
|
|
CoinsBalance,
|
|
|
|
|
|
CoinTransaction,
|
|
|
|
|
|
ConsumablesStatus,
|
|
|
|
|
|
UserCosmetics,
|
2026-01-08 10:02:15 +07:00
|
|
|
|
SwapCandidate,
|
2026-01-05 07:15:50 +07:00
|
|
|
|
} 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
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-08 10:02:15 +07:00
|
|
|
|
// Получить кандидатов для Copycat (участники с активными заданиями)
|
|
|
|
|
|
getCopycatCandidates: async (marathonId: number): Promise<SwapCandidate[]> => {
|
|
|
|
|
|
const response = await client.get<SwapCandidate[]>(`/shop/copycat-candidates/${marathonId}`)
|
|
|
|
|
|
return response.data
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2026-01-05 07:15:50 +07:00
|
|
|
|
// === Монеты ===
|
|
|
|
|
|
|
|
|
|
|
|
// Получить баланс и последние транзакции
|
|
|
|
|
|
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
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|