aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/.server/api
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/.server/api')
-rw-r--r--frontend/app/.server/api/client.ts90
-rw-r--r--frontend/app/.server/api/schema.d.ts669
2 files changed, 385 insertions, 374 deletions
diff --git a/frontend/app/.server/api/client.ts b/frontend/app/.server/api/client.ts
index 8e50b7e..8f53b5b 100644
--- a/frontend/app/.server/api/client.ts
+++ b/frontend/app/.server/api/client.ts
@@ -1,9 +1,95 @@
import createClient from "openapi-fetch";
-import type { paths } from "./schema";
+import type { paths, operations } from "./schema";
-export const apiClient = createClient<paths>({
+const apiClient = createClient<paths>({
baseUrl:
process.env.NODE_ENV === "development"
? "http://localhost:8002/api/"
: "http://api-server/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;
+}
+
+export async function adminApiGetUsers(token: string) {
+ const { data, error } = await apiClient.GET("/admin/users", {
+ params: {
+ header: { Authorization: `Bearer ${token}` },
+ },
+ });
+ if (error) throw new Error(error.message);
+ return data;
+}
+
+export async function adminApiGetGames(token: string) {
+ const { data, error } = await apiClient.GET("/admin/games", {
+ params: {
+ header: { Authorization: `Bearer ${token}` },
+ },
+ });
+ if (error) throw new Error(error.message);
+ return data;
+}
+
+export async function adminApiGetGame(token: string, gameId: number) {
+ const { data, error } = await apiClient.GET("/admin/games/{game_id}", {
+ params: {
+ header: { Authorization: `Bearer ${token}` },
+ path: { game_id: gameId },
+ },
+ });
+ if (error) throw new Error(error.message);
+ return data;
+}
+
+export async function adminApiPutGame(
+ token: string,
+ gameId: number,
+ body: operations["adminPutGame"]["requestBody"]["content"]["application/json"],
+) {
+ const { data, error } = await apiClient.PUT("/admin/games/{game_id}", {
+ params: {
+ header: { Authorization: `Bearer ${token}` },
+ path: { game_id: gameId },
+ },
+ body,
+ });
+ if (error) throw new Error(error.message);
+ return data;
+}
diff --git a/frontend/app/.server/api/schema.d.ts b/frontend/app/.server/api/schema.d.ts
index 000c876..705380d 100644
--- a/frontend/app/.server/api/schema.d.ts
+++ b/frontend/app/.server/api/schema.d.ts
@@ -14,50 +14,7 @@ export interface paths {
get?: never;
put?: never;
/** User login */
- post: {
- parameters: {
- query?: never;
- header?: never;
- path?: never;
- cookie?: never;
- };
- requestBody: {
- content: {
- "application/json": {
- /** @example john */
- username: string;
- /** @example password123 */
- password: string;
- };
- };
- };
- responses: {
- /** @description Successfully authenticated */
- 200: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- /** @example xxxxx.xxxxx.xxxxx */
- token: string;
- };
- };
- };
- /** @description Invalid username or password */
- 401: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- /** @example Invalid credentials */
- message: string;
- };
- };
- };
- };
- };
+ post: operations["postLogin"];
delete?: never;
options?: never;
head?: never;
@@ -72,43 +29,7 @@ export interface paths {
cookie?: never;
};
/** Get a short-lived access token */
- get: {
- parameters: {
- query?: never;
- header: {
- Authorization: string;
- };
- path?: never;
- cookie?: never;
- };
- requestBody?: never;
- responses: {
- /** @description Successfully authenticated */
- 200: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- /** @example xxxxx.xxxxx.xxxxx */
- token: string;
- };
- };
- };
- /** @description Forbidden */
- 403: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- /** @example Forbidden operation */
- message: string;
- };
- };
- };
- };
- };
+ get: operations["getToken"];
put?: never;
post?: never;
delete?: never;
@@ -125,44 +46,7 @@ export interface paths {
cookie?: never;
};
/** List games */
- get: {
- parameters: {
- query?: {
- player_id?: number;
- };
- header: {
- Authorization: string;
- };
- path?: never;
- cookie?: never;
- };
- requestBody?: never;
- responses: {
- /** @description List of games */
- 200: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- games: components["schemas"]["Game"][];
- };
- };
- };
- /** @description Forbidden */
- 403: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- /** @example Forbidden operation */
- message: string;
- };
- };
- };
- };
- };
+ get: operations["getGames"];
put?: never;
post?: never;
delete?: never;
@@ -171,7 +55,7 @@ export interface paths {
patch?: never;
trace?: never;
};
- [path: `/games/${integer}`]: {
+ "/games/{game_id}": {
parameters: {
query?: never;
header?: never;
@@ -179,56 +63,7 @@ export interface paths {
cookie?: never;
};
/** Get a game */
- get: {
- parameters: {
- query?: never;
- header: {
- Authorization: string;
- };
- path: {
- game_id: number;
- };
- cookie?: never;
- };
- requestBody?: never;
- responses: {
- /** @description A game */
- 200: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- game: components["schemas"]["Game"];
- };
- };
- };
- /** @description Forbidden */
- 403: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- /** @example Forbidden operation */
- message: string;
- };
- };
- };
- /** @description Not found */
- 404: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- /** @example Not found */
- message: string;
- };
- };
- };
- };
- };
+ get: operations["getGame"];
put?: never;
post?: never;
delete?: never;
@@ -245,42 +80,7 @@ export interface paths {
cookie?: never;
};
/** List all users */
- get: {
- parameters: {
- query?: never;
- header: {
- Authorization: string;
- };
- path?: never;
- cookie?: never;
- };
- requestBody?: never;
- responses: {
- /** @description List of users */
- 200: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- users: components["schemas"]["User"][];
- };
- };
- };
- /** @description Forbidden */
- 403: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- /** @example Forbidden operation */
- message: string;
- };
- };
- };
- };
- };
+ get: operations["adminGetUsers"];
put?: never;
post?: never;
delete?: never;
@@ -297,42 +97,7 @@ export interface paths {
cookie?: never;
};
/** List games */
- get: {
- parameters: {
- query?: never;
- header: {
- Authorization: string;
- };
- path?: never;
- cookie?: never;
- };
- requestBody?: never;
- responses: {
- /** @description List of games */
- 200: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- games: components["schemas"]["Game"][];
- };
- };
- };
- /** @description Forbidden */
- 403: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- /** @example Forbidden operation */
- message: string;
- };
- };
- };
- };
- };
+ get: operations["adminGetGames"];
put?: never;
post?: never;
delete?: never;
@@ -341,7 +106,7 @@ export interface paths {
patch?: never;
trace?: never;
};
- [path: `/admin/games/${integer}`]: {
+ "/admin/games/{game_id}": {
parameters: {
query?: never;
header?: never;
@@ -349,133 +114,9 @@ export interface paths {
cookie?: never;
};
/** Get a game */
- get: {
- parameters: {
- query?: never;
- header: {
- Authorization: string;
- };
- path: {
- game_id: number;
- };
- cookie?: never;
- };
- requestBody?: never;
- responses: {
- /** @description A game */
- 200: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- game: components["schemas"]["Game"];
- };
- };
- };
- /** @description Forbidden */
- 403: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- /** @example Forbidden operation */
- message: string;
- };
- };
- };
- /** @description Not found */
- 404: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- /** @example Not found */
- message: string;
- };
- };
- };
- };
- };
+ get: operations["adminGetGame"];
/** Update a game */
- put: {
- parameters: {
- query?: never;
- header: {
- Authorization: string;
- };
- path: {
- game_id: number;
- };
- cookie?: never;
- };
- requestBody: {
- content: {
- "application/json": {
- /**
- * @example closed
- * @enum {string}
- */
- state?: "closed" | "waiting_entries" | "waiting_start" | "prepare" | "starting" | "gaming" | "finished";
- /** @example Game 1 */
- display_name?: string;
- /** @example 360 */
- duration_seconds?: number;
- /** @example 946684800 */
- started_at?: number | null;
- /** @example 1 */
- problem_id?: number | null;
- };
- };
- };
- responses: {
- /** @description Successfully updated */
- 204: {
- headers: {
- [name: string]: unknown;
- };
- content?: never;
- };
- /** @description Invalid request */
- 400: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- /** @example Invalid request */
- message: string;
- };
- };
- };
- /** @description Forbidden */
- 403: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- /** @example Forbidden operation */
- message: string;
- };
- };
- };
- /** @description Not found */
- 404: {
- headers: {
- [name: string]: unknown;
- };
- content: {
- "application/json": {
- /** @example Not found */
- message: string;
- };
- };
- };
- };
- };
+ put: operations["adminPutGame"];
post?: never;
delete?: never;
options?: never;
@@ -487,6 +128,10 @@ export interface paths {
export type webhooks = Record<string, never>;
export interface components {
schemas: {
+ Error: {
+ /** @example Invalid request */
+ message: string;
+ };
User: {
/** @example 123 */
user_id: number;
@@ -617,11 +262,291 @@ export interface components {
stderr: string;
};
};
- responses: never;
- parameters: never;
+ responses: {
+ /** @description Bad request */
+ BadRequest: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["Error"];
+ };
+ };
+ /** @description Unauthorized */
+ Unauthorized: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["Error"];
+ };
+ };
+ /** @description Forbidden */
+ Forbidden: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["Error"];
+ };
+ };
+ /** @description Not found */
+ NotFound: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": components["schemas"]["Error"];
+ };
+ };
+ };
+ parameters: {
+ header_authorization: string;
+ path_game_id: number;
+ };
requestBodies: never;
headers: never;
pathItems: never;
}
export type $defs = Record<string, never>;
-export type operations = Record<string, never>;
+export interface operations {
+ postLogin: {
+ parameters: {
+ query?: never;
+ header?: never;
+ path?: never;
+ cookie?: never;
+ };
+ requestBody: {
+ content: {
+ "application/json": {
+ /** @example john */
+ username: string;
+ /** @example password123 */
+ password: string;
+ };
+ };
+ };
+ responses: {
+ /** @description Successfully authenticated */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": {
+ /** @example xxxxx.xxxxx.xxxxx */
+ token: string;
+ };
+ };
+ };
+ 401: components["responses"]["Unauthorized"];
+ };
+ };
+ getToken: {
+ parameters: {
+ query?: never;
+ header: {
+ Authorization: components["parameters"]["header_authorization"];
+ };
+ path?: never;
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description Successfully authenticated */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": {
+ /** @example xxxxx.xxxxx.xxxxx */
+ token: string;
+ };
+ };
+ };
+ 401: components["responses"]["Unauthorized"];
+ };
+ };
+ getGames: {
+ parameters: {
+ query?: never;
+ header: {
+ Authorization: components["parameters"]["header_authorization"];
+ };
+ path?: never;
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description List of games */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": {
+ games: components["schemas"]["Game"][];
+ };
+ };
+ };
+ 401: components["responses"]["Unauthorized"];
+ 403: components["responses"]["Forbidden"];
+ };
+ };
+ getGame: {
+ parameters: {
+ query?: never;
+ header: {
+ Authorization: components["parameters"]["header_authorization"];
+ };
+ path: {
+ game_id: components["parameters"]["path_game_id"];
+ };
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description A game */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": {
+ game: components["schemas"]["Game"];
+ };
+ };
+ };
+ 401: components["responses"]["Unauthorized"];
+ 403: components["responses"]["Forbidden"];
+ 404: components["responses"]["NotFound"];
+ };
+ };
+ adminGetUsers: {
+ parameters: {
+ query?: never;
+ header: {
+ Authorization: components["parameters"]["header_authorization"];
+ };
+ path?: never;
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description List of users */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": {
+ users: components["schemas"]["User"][];
+ };
+ };
+ };
+ 401: components["responses"]["Unauthorized"];
+ 403: components["responses"]["Forbidden"];
+ };
+ };
+ adminGetGames: {
+ parameters: {
+ query?: never;
+ header: {
+ Authorization: components["parameters"]["header_authorization"];
+ };
+ path?: never;
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description List of games */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": {
+ games: components["schemas"]["Game"][];
+ };
+ };
+ };
+ 401: components["responses"]["Unauthorized"];
+ 403: components["responses"]["Forbidden"];
+ };
+ };
+ adminGetGame: {
+ parameters: {
+ query?: never;
+ header: {
+ Authorization: components["parameters"]["header_authorization"];
+ };
+ path: {
+ game_id: components["parameters"]["path_game_id"];
+ };
+ cookie?: never;
+ };
+ requestBody?: never;
+ responses: {
+ /** @description A game */
+ 200: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content: {
+ "application/json": {
+ game: components["schemas"]["Game"];
+ };
+ };
+ };
+ 401: components["responses"]["Unauthorized"];
+ 403: components["responses"]["Forbidden"];
+ 404: components["responses"]["NotFound"];
+ };
+ };
+ adminPutGame: {
+ parameters: {
+ query?: never;
+ header: {
+ Authorization: components["parameters"]["header_authorization"];
+ };
+ path: {
+ game_id: components["parameters"]["path_game_id"];
+ };
+ cookie?: never;
+ };
+ requestBody: {
+ content: {
+ "application/json": {
+ /**
+ * @example closed
+ * @enum {string}
+ */
+ state?: "closed" | "waiting_entries" | "waiting_start" | "prepare" | "starting" | "gaming" | "finished";
+ /** @example Game 1 */
+ display_name?: string;
+ /** @example 360 */
+ duration_seconds?: number;
+ /** @example 946684800 */
+ started_at?: number | null;
+ /** @example 1 */
+ problem_id?: number | null;
+ };
+ };
+ };
+ responses: {
+ /** @description Successfully updated */
+ 204: {
+ headers: {
+ [name: string]: unknown;
+ };
+ content?: never;
+ };
+ 400: components["responses"]["BadRequest"];
+ 401: components["responses"]["Unauthorized"];
+ 403: components["responses"]["Forbidden"];
+ 404: components["responses"]["NotFound"];
+ };
+ };
+}