add: shop capes and refactor cape card

This commit is contained in:
2025-07-19 01:36:33 +05:00
parent 26f601635b
commit 56da7c7543
4 changed files with 315 additions and 62 deletions

View File

@ -30,6 +30,16 @@ export interface Cape {
export type CapesResponse = Cape[];
export interface StoreCape {
id: string;
name: string;
description: string;
price: number;
image_url: string;
}
export type StoreCapesResponse = StoreCape[];
export interface ApiError {
message: string;
details?: string;
@ -81,6 +91,50 @@ export async function fetchCapes(username: string): Promise<CapesResponse> {
}
}
export async function purchaseCape(
username: string,
cape_id: string,
): Promise<void> {
// Создаем URL с query-параметрами
const url = new URL(`${API_BASE_URL}/store/purchase/cape`);
url.searchParams.append('username', username);
url.searchParams.append('cape_id', cape_id);
const response = await fetch(url.toString(), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
// Не нужно отправлять тело запроса
// body: JSON.stringify({
// username: username,
// cape_id: cape_id,
// }),
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(
errorData.message ||
errorData.detail?.toString() ||
'Не удалось купить плащ',
);
}
}
export async function fetchCapesStore(): Promise<StoreCape[]> {
try {
const response = await fetch(`${API_BASE_URL}/store/capes`);
if (!response.ok) {
return [];
}
return await response.json();
} catch (error) {
console.error('API ошибка:', error);
return [];
}
}
export async function activateCape(
username: string,
cape_id: string,