aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/db/query.sql.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-09 23:30:10 +0900
committernsfisis <nsfisis@gmail.com>2024-08-09 23:30:10 +0900
commitaf36c59851399194bcbb77a3093d46c2757cb7b4 (patch)
tree72e1a3cc00044f9c00dc5f22ef9325124f272401 /backend/db/query.sql.go
parent93f2ffc18d1d86bd2999533e8d904c92cb29bc1a (diff)
downloadphperkaigi-2025-albatross-af36c59851399194bcbb77a3093d46c2757cb7b4.tar.gz
phperkaigi-2025-albatross-af36c59851399194bcbb77a3093d46c2757cb7b4.tar.zst
phperkaigi-2025-albatross-af36c59851399194bcbb77a3093d46c2757cb7b4.zip
feat: support authentication via fortee
Diffstat (limited to 'backend/db/query.sql.go')
-rw-r--r--backend/db/query.sql.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/backend/db/query.sql.go b/backend/db/query.sql.go
index dc87602..47140fc 100644
--- a/backend/db/query.sql.go
+++ b/backend/db/query.sql.go
@@ -106,6 +106,34 @@ func (q *Queries) CreateTestcaseResult(ctx context.Context, arg CreateTestcaseRe
return err
}
+const createUser = `-- name: CreateUser :one
+INSERT INTO users (username, display_name, is_admin)
+VALUES ($1, $1, false)
+RETURNING user_id
+`
+
+func (q *Queries) CreateUser(ctx context.Context, username string) (int32, error) {
+ row := q.db.QueryRow(ctx, createUser, username)
+ var user_id int32
+ err := row.Scan(&user_id)
+ return user_id, err
+}
+
+const createUserAuth = `-- name: CreateUserAuth :exec
+INSERT INTO user_auths (user_id, auth_type)
+VALUES ($1, $2)
+`
+
+type CreateUserAuthParams struct {
+ UserID int32
+ AuthType string
+}
+
+func (q *Queries) CreateUserAuth(ctx context.Context, arg CreateUserAuthParams) error {
+ _, err := q.db.Exec(ctx, createUserAuth, arg.UserID, arg.AuthType)
+ return err
+}
+
const getGameByID = `-- name: GetGameByID :one
SELECT game_id, game_type, state, display_name, duration_seconds, created_at, started_at, games.problem_id, problems.problem_id, title, description FROM games
LEFT JOIN problems ON games.problem_id = problems.problem_id
@@ -204,6 +232,20 @@ func (q *Queries) GetUserByID(ctx context.Context, userID int32) (User, error) {
return i, err
}
+const isRegistrationTokenValid = `-- name: IsRegistrationTokenValid :one
+SELECT EXISTS (
+ SELECT 1 FROM registration_tokens
+ WHERE token = $1
+)
+`
+
+func (q *Queries) IsRegistrationTokenValid(ctx context.Context, token string) (bool, error) {
+ row := q.db.QueryRow(ctx, isRegistrationTokenValid, token)
+ var exists bool
+ err := row.Scan(&exists)
+ return exists, err
+}
+
const listGamePlayers = `-- name: ListGamePlayers :many
SELECT game_id, game_players.user_id, users.user_id, username, display_name, icon_path, is_admin, created_at FROM game_players
LEFT JOIN users ON game_players.user_id = users.user_id