basic app implementation
This commit is contained in:
parent
b8d7a8c4cf
commit
04e302e7b0
@ -1,9 +1,21 @@
|
||||
-- name: CreateFlagsGame :exec
|
||||
INSERT INTO app_flags_games (uid, tags, question_amount) VALUES ($1, $2, $3) RETURNING (game_id, game_seed);
|
||||
INSERT INTO app_flags_games (uid, tags, question_amount)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING (game_id, game_seed);
|
||||
|
||||
-- name: GetFlagsGame :one
|
||||
SELECT * FROM app_flags_games WHERE game_id = $1 LIMIT 1;
|
||||
|
||||
-- name: UpdateFlagsGame :exec
|
||||
UPDATE app_flags_games SET question_current = $1,
|
||||
last_activity = CURRENT_TIMESTAMP;
|
||||
UPDATE app_flags_games
|
||||
SET question_current = $1, last_activity = CURRENT_TIMESTAMP
|
||||
WHERE game_id = $2;
|
||||
|
||||
-- name: UpdateQuestionCorrect :exec
|
||||
UPDATE app_flags_games
|
||||
SET questions_correct = (
|
||||
SELECT COUNT(*)
|
||||
FROM app_flags_games_answers
|
||||
WHERE game_id $1 AND correct = TRUE
|
||||
)
|
||||
WHERE game_id = $1;
|
||||
|
@ -14,7 +14,9 @@ import (
|
||||
)
|
||||
|
||||
const createFlagsGame = `-- name: CreateFlagsGame :exec
|
||||
INSERT INTO app_flags_games (uid, tags, question_amount) VALUES ($1, $2, $3) RETURNING (game_id, game_seed)
|
||||
INSERT INTO app_flags_games (uid, tags, question_amount)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING (game_id, game_seed)
|
||||
`
|
||||
|
||||
type CreateFlagsGameParams struct {
|
||||
@ -50,11 +52,32 @@ func (q *Queries) GetFlagsGame(ctx context.Context, gameID uuid.UUID) (AppFlagsG
|
||||
}
|
||||
|
||||
const updateFlagsGame = `-- name: UpdateFlagsGame :exec
|
||||
UPDATE app_flags_games SET question_current = $1,
|
||||
last_activity = CURRENT_TIMESTAMP
|
||||
UPDATE app_flags_games
|
||||
SET question_current = $1, last_activity = CURRENT_TIMESTAMP
|
||||
WHERE game_id = $2
|
||||
`
|
||||
|
||||
func (q *Queries) UpdateFlagsGame(ctx context.Context, questionCurrent int32) error {
|
||||
_, err := q.db.ExecContext(ctx, updateFlagsGame, questionCurrent)
|
||||
type UpdateFlagsGameParams struct {
|
||||
QuestionCurrent int32
|
||||
GameID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateFlagsGame(ctx context.Context, arg UpdateFlagsGameParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateFlagsGame, arg.QuestionCurrent, arg.GameID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateQuestionCorrect = `-- name: UpdateQuestionCorrect :exec
|
||||
UPDATE app_flags_games
|
||||
SET questions_correct = (
|
||||
SELECT COUNT(*)
|
||||
FROM app_flags_games_answers
|
||||
WHERE game_id $1 AND correct = TRUE
|
||||
)
|
||||
WHERE game_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) UpdateQuestionCorrect(ctx context.Context, dollar_1 interface{}) error {
|
||||
_, err := q.db.ExecContext(ctx, updateQuestionCorrect, dollar_1)
|
||||
return err
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ type AppFlagsGame struct {
|
||||
Tags []string
|
||||
QuestionAmount int32
|
||||
QuestionCurrent int32
|
||||
QuestionCorrect sql.NullInt32
|
||||
QuestionCorrect int32
|
||||
CreatedAt time.Time
|
||||
LastActivity time.Time
|
||||
}
|
||||
|
@ -5,9 +5,7 @@ CREATE TABLE app_flags_games (
|
||||
tags VARCHAR[] NOT NULL,
|
||||
question_amount INT NOT NULL,
|
||||
question_current INT DEFAULT 0 NOT NULL,
|
||||
question_correct INT GENERATED ALWAYS AS (
|
||||
(SELECT COUNT(*) FROM app_flags_games_answers a WHERE a.game_id = app_flags_games.game_id AND a.correct = TRUE)
|
||||
) STORED,
|
||||
question_correct INT DEFAULT 0 NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
last_activity TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
FOREIGN KEY (uid) REFERENCES users (uid)
|
||||
|
Loading…
Reference in New Issue
Block a user