feat: implemented handling webhooks

This commit is contained in:
Stevan Freeborn
2026-08-15 20:18:21 -05:00
parent c3fded4492
commit d34c7b5822
6 changed files with 198 additions and 29 deletions
+1
View File
@@ -34,4 +34,5 @@ type User struct {
UpdatedAt time.Time
Email string
HashedPassword string
IsChirpyRed bool
}
+29 -4
View File
@@ -20,7 +20,7 @@ VALUES (
$1,
$2
)
RETURNING id, created_at, updated_at, email, hashed_password
RETURNING id, created_at, updated_at, email, hashed_password, is_chirpy_red
`
type CreateUserParams struct {
@@ -37,6 +37,7 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e
&i.UpdatedAt,
&i.Email,
&i.HashedPassword,
&i.IsChirpyRed,
)
return i, err
}
@@ -51,7 +52,7 @@ func (q *Queries) DeleteAllUsers(ctx context.Context) error {
}
const getUserByEmail = `-- name: GetUserByEmail :one
SELECT id, created_at, updated_at, email, hashed_password FROM users
SELECT id, created_at, updated_at, email, hashed_password, is_chirpy_red FROM users
WHERE email = $1
`
@@ -64,12 +65,13 @@ func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error
&i.UpdatedAt,
&i.Email,
&i.HashedPassword,
&i.IsChirpyRed,
)
return i, err
}
const getUserById = `-- name: GetUserById :one
SELECT id, created_at, updated_at, email, hashed_password FROM users
SELECT id, created_at, updated_at, email, hashed_password, is_chirpy_red FROM users
WHERE id = $1
`
@@ -82,6 +84,7 @@ func (q *Queries) GetUserById(ctx context.Context, id uuid.UUID) (User, error) {
&i.UpdatedAt,
&i.Email,
&i.HashedPassword,
&i.IsChirpyRed,
)
return i, err
}
@@ -90,7 +93,7 @@ const updateUser = `-- name: UpdateUser :one
UPDATE users
SET email = $2, hashed_password = $3, updated_at = NOW()
WHERE id = $1
RETURNING id, created_at, updated_at, email, hashed_password
RETURNING id, created_at, updated_at, email, hashed_password, is_chirpy_red
`
type UpdateUserParams struct {
@@ -108,6 +111,28 @@ func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, e
&i.UpdatedAt,
&i.Email,
&i.HashedPassword,
&i.IsChirpyRed,
)
return i, err
}
const upgradeUser = `-- name: UpgradeUser :one
UPDATE users
SET is_chirpy_red = TRUE
WHERE id = $1
RETURNING id, created_at, updated_at, email, hashed_password, is_chirpy_red
`
func (q *Queries) UpgradeUser(ctx context.Context, id uuid.UUID) (User, error) {
row := q.db.QueryRowContext(ctx, upgradeUser, id)
var i User
err := row.Scan(
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.Email,
&i.HashedPassword,
&i.IsChirpyRed,
)
return i, err
}