Skip to content

Commit 4deed4e

Browse files
committed
fix: schema issues
1 parent 33b30b8 commit 4deed4e

File tree

11 files changed

+126
-114
lines changed

11 files changed

+126
-114
lines changed

database/queries/user.sql

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ WHERE id = $1;
2222
SELECT *
2323
FROM users;
2424

25-
-- name: UpgradeUsersToRound :exec
25+
-- name: UpgradeUserToRound :exec
2626
UPDATE users
27-
SET round_qualified = $2
28-
WHERE id::TEXT = ANY($1::TEXT[]);
27+
SET round_qualified = round_qualified + 1
28+
WHERE id = $1;
2929

3030
-- name: BanUser :exec
31-
UPDATE users
32-
SET is_banned = TRUE
31+
UPDATE users SET is_banned = TRUE
3332
WHERE id = $1;
33+
3434
-- name: UnbanUser :exec
3535
UPDATE users
3636
SET is_banned = FALSE
@@ -42,4 +42,18 @@ order by score;
4242

4343
-- name: UpdateProfile :exec
4444
UPDATE users SET reg_no = $1, password = $2, name = $3
45-
WHERE id = $4;
45+
WHERE id = $4;
46+
47+
-- name: GetSubmissionByUser :many
48+
SELECT id, question_id, testcases_passed, testcases_failed, runtime,
49+
submission_time, source_code, language_id, description, memory,
50+
user_id, status
51+
FROM submissions
52+
WHERE user_id = $1;
53+
54+
-- name: GetUsersWithCursor :many
55+
SELECT id, email, reg_no, password, role, round_qualified, score, name, is_banned
56+
FROM users
57+
WHERE ($1::uuid IS NULL OR id > $1)
58+
ORDER BY id ASC
59+
LIMIT $2;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- +goose Up
2+
ALTER TABLE submissions
3+
ALTER COLUMN user_id SET NOT NULL;
4+
5+
-- +goose Down
6+
ALTER TABLE submissions
7+
ALTER COLUMN user_id DROP NOT NULL;

database/schema/007_drop_columns.sql

Lines changed: 0 additions & 3 deletions
This file was deleted.

pkg/controllers/users.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ func GetAllUsers(c echo.Context) error {
4444
}
4545
}
4646

47-
users, err := utils.Queries.GetUsersWithCursor(c.Request().Context(), cursor, limit)
47+
users, err := utils.Queries.GetUsersWithCursor(c.Request().Context(), db.GetUsersWithCursorParams{
48+
Column1: *cursor,
49+
Limit: limit,
50+
})
4851
if err != nil {
4952
return c.JSON(http.StatusInternalServerError, echo.Map{
5053
"status": "Could not get users",
@@ -174,4 +177,4 @@ func GetSubmissionByUser(c echo.Context) error {
174177
})
175178
}
176179
return c.JSON(http.StatusOK, echo.Map{"status": "success", "submissions": subs})
177-
}
180+
}

pkg/db/db.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/models.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/questions.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/submission.sql.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/testcases.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/user.sql.go

Lines changed: 83 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)