Add 3 roles, settings for marathons

This commit is contained in:
2025-12-14 20:21:56 +07:00
parent bb9e9a6e1d
commit d0b8eca600
28 changed files with 1679 additions and 290 deletions

44
frontend/src/api/admin.ts Normal file
View File

@@ -0,0 +1,44 @@
import client from './client'
import type { AdminUser, AdminMarathon, UserRole, PlatformStats } from '@/types'
export const adminApi = {
// Users
listUsers: async (skip = 0, limit = 50, search?: string): Promise<AdminUser[]> => {
const params: Record<string, unknown> = { skip, limit }
if (search) params.search = search
const response = await client.get<AdminUser[]>('/admin/users', { params })
return response.data
},
getUser: async (id: number): Promise<AdminUser> => {
const response = await client.get<AdminUser>(`/admin/users/${id}`)
return response.data
},
setUserRole: async (id: number, role: UserRole): Promise<AdminUser> => {
const response = await client.patch<AdminUser>(`/admin/users/${id}/role`, { role })
return response.data
},
deleteUser: async (id: number): Promise<void> => {
await client.delete(`/admin/users/${id}`)
},
// Marathons
listMarathons: async (skip = 0, limit = 50, search?: string): Promise<AdminMarathon[]> => {
const params: Record<string, unknown> = { skip, limit }
if (search) params.search = search
const response = await client.get<AdminMarathon[]>('/admin/marathons', { params })
return response.data
},
deleteMarathon: async (id: number): Promise<void> => {
await client.delete(`/admin/marathons/${id}`)
},
// Stats
getStats: async (): Promise<PlatformStats> => {
const response = await client.get<PlatformStats>('/admin/stats')
return response.data
},
}

View File

@@ -1,5 +1,5 @@
import client from './client'
import type { Game, Challenge, ChallengePreview, ChallengesPreviewResponse } from '@/types'
import type { Game, GameStatus, Challenge, ChallengePreview, ChallengesPreviewResponse } from '@/types'
export interface CreateGameData {
title: string
@@ -20,8 +20,14 @@ export interface CreateChallengeData {
}
export const gamesApi = {
list: async (marathonId: number): Promise<Game[]> => {
const response = await client.get<Game[]>(`/marathons/${marathonId}/games`)
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`)
return response.data
},
@@ -39,6 +45,16 @@ export const gamesApi = {
await client.delete(`/games/${id}`)
},
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
},
uploadCover: async (id: number, file: File): Promise<Game> => {
const formData = new FormData()
formData.append('file', file)

View File

@@ -3,3 +3,4 @@ export { marathonsApi } from './marathons'
export { gamesApi } from './games'
export { wheelApi } from './wheel'
export { feedApi } from './feed'
export { adminApi } from './admin'

View File

@@ -1,15 +1,13 @@
import client from './client'
import type { Marathon, MarathonListItem, LeaderboardEntry, ParticipantInfo, User } from '@/types'
import type { Marathon, MarathonListItem, LeaderboardEntry, ParticipantWithUser, ParticipantRole, GameProposalMode } from '@/types'
export interface CreateMarathonData {
title: string
description?: string
start_date: string
duration_days?: number
}
export interface ParticipantWithUser extends ParticipantInfo {
user: User
is_public?: boolean
game_proposal_mode?: GameProposalMode
}
export const marathonsApi = {
@@ -52,11 +50,24 @@ export const marathonsApi = {
return response.data
},
joinPublic: async (id: number): Promise<Marathon> => {
const response = await client.post<Marathon>(`/marathons/${id}/join`)
return response.data
},
getParticipants: async (id: number): Promise<ParticipantWithUser[]> => {
const response = await client.get<ParticipantWithUser[]>(`/marathons/${id}/participants`)
return response.data
},
setParticipantRole: async (marathonId: number, userId: number, role: ParticipantRole): Promise<ParticipantWithUser> => {
const response = await client.patch<ParticipantWithUser>(
`/marathons/${marathonId}/participants/${userId}/role`,
{ role }
)
return response.data
},
getLeaderboard: async (id: number): Promise<LeaderboardEntry[]> => {
const response = await client.get<LeaderboardEntry[]>(`/marathons/${id}/leaderboard`)
return response.data