1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
import createClient from "openapi-fetch";
import type { paths } from "./schema";
const apiClient = createClient<paths>({
baseUrl:
process.env.NODE_ENV === "development"
? "http://localhost:8003/phperkaigi/2025/code-battle/api/"
: "http://api-server/phperkaigi/2025/code-battle/api/",
});
export async function apiPostLogin(username: string, password: string) {
const { data, error } = await apiClient.POST("/login", {
body: {
username,
password,
},
});
if (error) throw new Error(error.message);
return data;
}
export async function apiGetGames(token: string) {
const { data, error } = await apiClient.GET("/games", {
params: {
header: { Authorization: `Bearer ${token}` },
},
});
if (error) throw new Error(error.message);
return data;
}
export async function apiGetGame(token: string, gameId: number) {
const { data, error } = await apiClient.GET("/games/{game_id}", {
params: {
header: { Authorization: `Bearer ${token}` },
path: { game_id: gameId },
},
});
if (error) throw new Error(error.message);
return data;
}
export async function apiGetToken(token: string) {
const { data, error } = await apiClient.GET("/token", {
params: {
header: { Authorization: `Bearer ${token}` },
},
});
if (error) throw new Error(error.message);
return data;
}
|