Initial commit
This commit is contained in:
commit
b3a51a4115
10336 changed files with 2381973 additions and 0 deletions
70
frontend/src/services/api.ts
Normal file
70
frontend/src/services/api.ts
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
import axios from 'axios';
|
||||
import type { Game, Leg, Team, User, AuthResponse } from '../types';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: 'http://localhost:3001/api',
|
||||
});
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
export const authService = {
|
||||
register: (data: { email: string; password: string; name: string }) =>
|
||||
api.post<AuthResponse>('/auth/register', data),
|
||||
login: (data: { email: string; password: string }) =>
|
||||
api.post<AuthResponse>('/auth/login', data),
|
||||
me: () => api.get<User>('/auth/me'),
|
||||
};
|
||||
|
||||
export const gameService = {
|
||||
list: (params?: { search?: string; status?: string }) =>
|
||||
api.get<Game[]>('/games', { params }),
|
||||
myGames: () => api.get<Game[]>('/games/my-games'),
|
||||
get: (id: string) => api.get<Game>(`/games/${id}`),
|
||||
getByInvite: (code: string) => api.get<Game>(`/games/invite/${code}`),
|
||||
create: (data: Partial<Game>) => api.post<Game>('/games', data),
|
||||
update: (id: string, data: Partial<Game>) => api.put<Game>(`/games/${id}`, data),
|
||||
delete: (id: string) => api.delete(`/games/${id}`),
|
||||
publish: (id: string) => api.post<Game>(`/${id}/publish`),
|
||||
end: (id: string) => api.post<Game>(`/${id}/end`),
|
||||
getInvite: (id: string) => api.get<{ inviteCode: string }>(`/games/${id}/invite`),
|
||||
};
|
||||
|
||||
export const legService = {
|
||||
getByGame: (gameId: string) => api.get<Leg[]>(`/legs/game/${gameId}`),
|
||||
create: (gameId: string, data: Partial<Leg>) => api.post<Leg>(`/legs/game/${gameId}`, data),
|
||||
update: (legId: string, data: Partial<Leg>) => api.put<Leg>(`/legs/${legId}`, data),
|
||||
delete: (legId: string) => api.delete(`/legs/${legId}`),
|
||||
submitPhoto: (legId: string, data: { teamId: string; photoUrl: string }) =>
|
||||
api.post(`/legs/${legId}/photo`, data),
|
||||
};
|
||||
|
||||
export const teamService = {
|
||||
getByGame: (gameId: string) => api.get<Team[]>(`/teams/game/${gameId}`),
|
||||
create: (gameId: string, data: { name: string }) => api.post<Team>(`/teams/game/${gameId}`, data),
|
||||
get: (teamId: string) => api.get<Team>(`/teams/${teamId}`),
|
||||
join: (teamId: string) => api.post(`/teams/${teamId}/join`),
|
||||
leave: (teamId: string) => api.post(`/teams/${teamId}/leave`),
|
||||
advance: (teamId: string) => api.post<Team>(`/teams/${teamId}/advance`),
|
||||
deduct: (teamId: string, seconds: number) => api.post<Team>(`/teams/${teamId}/deduct`, { seconds }),
|
||||
disqualify: (teamId: string) => api.post<Team>(`/teams/${teamId}/disqualify`),
|
||||
updateLocation: (teamId: string, lat: number, lng: number) =>
|
||||
api.post(`/teams/${teamId}/location`, { lat, lng }),
|
||||
};
|
||||
|
||||
export const uploadService = {
|
||||
upload: (file: File) => {
|
||||
const formData = new FormData();
|
||||
formData.append('photo', file);
|
||||
return api.post<{ url: string }>('/upload/upload', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default api;
|
||||
Loading…
Add table
Add a link
Reference in a new issue