2025-12-14 02:38:35 +07:00
|
|
|
import client from './client'
|
2025-12-29 22:23:34 +03:00
|
|
|
import type { Game, GameStatus, GameType, ProofType, Challenge, ChallengePreview, ChallengesPreviewResponse, AvailableGamesCount } from '@/types'
|
2025-12-14 02:38:35 +07:00
|
|
|
|
|
|
|
|
export interface CreateGameData {
|
|
|
|
|
title: string
|
|
|
|
|
download_url: string
|
|
|
|
|
genre?: string
|
|
|
|
|
cover_url?: string
|
2025-12-29 22:23:34 +03:00
|
|
|
// Game type fields
|
|
|
|
|
game_type?: GameType
|
|
|
|
|
playthrough_points?: number
|
|
|
|
|
playthrough_description?: string
|
|
|
|
|
playthrough_proof_type?: ProofType
|
|
|
|
|
playthrough_proof_hint?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface UpdateGameData {
|
|
|
|
|
title?: string
|
|
|
|
|
download_url?: string
|
|
|
|
|
genre?: string
|
|
|
|
|
game_type?: GameType
|
|
|
|
|
playthrough_points?: number
|
|
|
|
|
playthrough_description?: string
|
|
|
|
|
playthrough_proof_type?: ProofType
|
|
|
|
|
playthrough_proof_hint?: string
|
2025-12-14 02:38:35 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CreateChallengeData {
|
|
|
|
|
title: string
|
|
|
|
|
description: string
|
|
|
|
|
type: string
|
|
|
|
|
difficulty: string
|
|
|
|
|
points: number
|
|
|
|
|
estimated_time?: number
|
|
|
|
|
proof_type: string
|
|
|
|
|
proof_hint?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const gamesApi = {
|
2025-12-14 20:21:56 +07:00
|
|
|
list: async (marathonId: number, status?: GameStatus): Promise<Game[]> => {
|
|
|
|
|
const params = status ? { status } : {}
|
|
|
|
|
const response = await client.get<Game[]>(`/marathons/${marathonId}/games`, { params })
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
listPending: async (marathonId: number): Promise<Game[]> => {
|
|
|
|
|
const response = await client.get<Game[]>(`/marathons/${marathonId}/games/pending`)
|
2025-12-14 02:38:35 +07:00
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
get: async (id: number): Promise<Game> => {
|
|
|
|
|
const response = await client.get<Game>(`/games/${id}`)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
create: async (marathonId: number, data: CreateGameData): Promise<Game> => {
|
|
|
|
|
const response = await client.post<Game>(`/marathons/${marathonId}/games`, data)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
delete: async (id: number): Promise<void> => {
|
|
|
|
|
await client.delete(`/games/${id}`)
|
|
|
|
|
},
|
|
|
|
|
|
2025-12-29 22:23:34 +03:00
|
|
|
update: async (id: number, data: UpdateGameData): Promise<Game> => {
|
|
|
|
|
const response = await client.patch<Game>(`/games/${id}`, data)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getAvailableGamesCount: async (marathonId: number): Promise<AvailableGamesCount> => {
|
|
|
|
|
const response = await client.get<AvailableGamesCount>(`/marathons/${marathonId}/available-games-count`)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getAvailableGames: async (marathonId: number): Promise<Game[]> => {
|
|
|
|
|
const response = await client.get<Game[]>(`/marathons/${marathonId}/available-games`)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
2025-12-14 20:21:56 +07:00
|
|
|
approve: async (id: number): Promise<Game> => {
|
|
|
|
|
const response = await client.post<Game>(`/games/${id}/approve`)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
reject: async (id: number): Promise<Game> => {
|
|
|
|
|
const response = await client.post<Game>(`/games/${id}/reject`)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
2025-12-14 02:38:35 +07:00
|
|
|
uploadCover: async (id: number, file: File): Promise<Game> => {
|
|
|
|
|
const formData = new FormData()
|
|
|
|
|
formData.append('file', file)
|
|
|
|
|
const response = await client.post<Game>(`/games/${id}/cover`, formData, {
|
|
|
|
|
headers: { 'Content-Type': 'multipart/form-data' },
|
|
|
|
|
})
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Challenges
|
|
|
|
|
getChallenges: async (gameId: number): Promise<Challenge[]> => {
|
|
|
|
|
const response = await client.get<Challenge[]>(`/games/${gameId}/challenges`)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
createChallenge: async (gameId: number, data: CreateChallengeData): Promise<Challenge> => {
|
|
|
|
|
const response = await client.post<Challenge>(`/games/${gameId}/challenges`, data)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
deleteChallenge: async (id: number): Promise<void> => {
|
|
|
|
|
await client.delete(`/challenges/${id}`)
|
|
|
|
|
},
|
|
|
|
|
|
2025-12-18 23:47:11 +07:00
|
|
|
updateChallenge: async (id: number, data: Partial<CreateChallengeData>): Promise<Challenge> => {
|
|
|
|
|
const response = await client.patch<Challenge>(`/challenges/${id}`, data)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
2025-12-17 20:19:26 +07:00
|
|
|
previewChallenges: async (marathonId: number, gameIds?: number[]): Promise<ChallengesPreviewResponse> => {
|
|
|
|
|
const data = gameIds?.length ? { game_ids: gameIds } : undefined
|
|
|
|
|
const response = await client.post<ChallengesPreviewResponse>(`/marathons/${marathonId}/preview-challenges`, data)
|
2025-12-14 03:23:50 +07:00
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
saveChallenges: async (marathonId: number, challenges: ChallengePreview[]): Promise<{ message: string }> => {
|
|
|
|
|
const response = await client.post<{ message: string }>(`/marathons/${marathonId}/save-challenges`, { challenges })
|
2025-12-14 02:38:35 +07:00
|
|
|
return response.data
|
|
|
|
|
},
|
2025-12-18 23:47:11 +07:00
|
|
|
|
|
|
|
|
// Proposed challenges
|
|
|
|
|
proposeChallenge: async (gameId: number, data: CreateChallengeData): Promise<Challenge> => {
|
|
|
|
|
const response = await client.post<Challenge>(`/games/${gameId}/propose-challenge`, data)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getProposedChallenges: async (marathonId: number): Promise<Challenge[]> => {
|
|
|
|
|
const response = await client.get<Challenge[]>(`/marathons/${marathonId}/proposed-challenges`)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getMyProposedChallenges: async (marathonId: number): Promise<Challenge[]> => {
|
|
|
|
|
const response = await client.get<Challenge[]>(`/marathons/${marathonId}/my-proposed-challenges`)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
approveChallenge: async (id: number): Promise<Challenge> => {
|
|
|
|
|
const response = await client.patch<Challenge>(`/challenges/${id}/approve`)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
rejectChallenge: async (id: number): Promise<Challenge> => {
|
|
|
|
|
const response = await client.patch<Challenge>(`/challenges/${id}/reject`)
|
|
|
|
|
return response.data
|
|
|
|
|
},
|
2025-12-14 02:38:35 +07:00
|
|
|
}
|