71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
|
|
import client from './client'
|
||
|
|
import type { Game, Challenge } from '@/types'
|
||
|
|
|
||
|
|
export interface CreateGameData {
|
||
|
|
title: string
|
||
|
|
download_url: string
|
||
|
|
genre?: string
|
||
|
|
cover_url?: string
|
||
|
|
}
|
||
|
|
|
||
|
|
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 = {
|
||
|
|
list: async (marathonId: number): Promise<Game[]> => {
|
||
|
|
const response = await client.get<Game[]>(`/marathons/${marathonId}/games`)
|
||
|
|
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}`)
|
||
|
|
},
|
||
|
|
|
||
|
|
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}`)
|
||
|
|
},
|
||
|
|
|
||
|
|
generateChallenges: async (marathonId: number): Promise<{ message: string }> => {
|
||
|
|
const response = await client.post<{ message: string }>(`/marathons/${marathonId}/generate-challenges`)
|
||
|
|
return response.data
|
||
|
|
},
|
||
|
|
}
|