initial
This commit is contained in:
64
frontend/src/api/marathons.ts
Normal file
64
frontend/src/api/marathons.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import client from './client'
|
||||
import type { Marathon, MarathonListItem, LeaderboardEntry, ParticipantInfo, User } from '@/types'
|
||||
|
||||
export interface CreateMarathonData {
|
||||
title: string
|
||||
description?: string
|
||||
start_date: string
|
||||
duration_days?: number
|
||||
}
|
||||
|
||||
export interface ParticipantWithUser extends ParticipantInfo {
|
||||
user: User
|
||||
}
|
||||
|
||||
export const marathonsApi = {
|
||||
list: async (): Promise<MarathonListItem[]> => {
|
||||
const response = await client.get<MarathonListItem[]>('/marathons')
|
||||
return response.data
|
||||
},
|
||||
|
||||
get: async (id: number): Promise<Marathon> => {
|
||||
const response = await client.get<Marathon>(`/marathons/${id}`)
|
||||
return response.data
|
||||
},
|
||||
|
||||
create: async (data: CreateMarathonData): Promise<Marathon> => {
|
||||
const response = await client.post<Marathon>('/marathons', data)
|
||||
return response.data
|
||||
},
|
||||
|
||||
update: async (id: number, data: Partial<CreateMarathonData>): Promise<Marathon> => {
|
||||
const response = await client.patch<Marathon>(`/marathons/${id}`, data)
|
||||
return response.data
|
||||
},
|
||||
|
||||
delete: async (id: number): Promise<void> => {
|
||||
await client.delete(`/marathons/${id}`)
|
||||
},
|
||||
|
||||
start: async (id: number): Promise<Marathon> => {
|
||||
const response = await client.post<Marathon>(`/marathons/${id}/start`)
|
||||
return response.data
|
||||
},
|
||||
|
||||
finish: async (id: number): Promise<Marathon> => {
|
||||
const response = await client.post<Marathon>(`/marathons/${id}/finish`)
|
||||
return response.data
|
||||
},
|
||||
|
||||
join: async (inviteCode: string): Promise<Marathon> => {
|
||||
const response = await client.post<Marathon>('/marathons/join', { invite_code: inviteCode })
|
||||
return response.data
|
||||
},
|
||||
|
||||
getParticipants: async (id: number): Promise<ParticipantWithUser[]> => {
|
||||
const response = await client.get<ParticipantWithUser[]>(`/marathons/${id}/participants`)
|
||||
return response.data
|
||||
},
|
||||
|
||||
getLeaderboard: async (id: number): Promise<LeaderboardEntry[]> => {
|
||||
const response = await client.get<LeaderboardEntry[]>(`/marathons/${id}/leaderboard`)
|
||||
return response.data
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user