Move HTTP handler logic out of main into internal api and server packages, slimming main to a thin entrypoint. Bundles bug fixes: login nil-panic, empty-password validation, chirp sort ordering, duplicate-email 409, and restricting the file server to the assets directory.
34 lines
693 B
SQL
34 lines
693 B
SQL
-- name: CreateUser :one
|
|
INSERT INTO users (id, created_at, updated_at, email, hashed_password)
|
|
VALUES (
|
|
gen_random_uuid(),
|
|
NOW(),
|
|
NOW(),
|
|
$1,
|
|
$2
|
|
)
|
|
RETURNING *;
|
|
|
|
-- name: UpdateUser :one
|
|
UPDATE users
|
|
SET email = $2, hashed_password = $3, updated_at = NOW()
|
|
WHERE id = $1
|
|
RETURNING *;
|
|
|
|
-- name: DeleteAllUsers :exec
|
|
DELETE FROM users;
|
|
|
|
-- name: GetUserById :one
|
|
SELECT id, created_at, updated_at, email, hashed_password, is_chirpy_red FROM users
|
|
WHERE id = $1;
|
|
|
|
-- name: GetUserByEmail :one
|
|
SELECT id, created_at, updated_at, email, hashed_password, is_chirpy_red FROM users
|
|
WHERE email = $1;
|
|
|
|
-- name: UpgradeUser :one
|
|
UPDATE users
|
|
SET is_chirpy_red = TRUE
|
|
WHERE id = $1
|
|
RETURNING *;
|