webhooks and chirps by user id
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
const createUser = `-- name: CreateUser :one
|
||||
INSERT INTO users (id, created_at, updated_at, email, hashed_password)
|
||||
VALUES (gen_random_uuid(), NOW(), NOW(), $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 {
|
||||
@@ -29,6 +29,7 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e
|
||||
&i.UpdatedAt,
|
||||
&i.Email,
|
||||
&i.HashedPassword,
|
||||
&i.IsChirpyRed,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
45
internal/database/GetChirpsByUserID.sql.go
Normal file
45
internal/database/GetChirpsByUserID.sql.go
Normal file
@@ -0,0 +1,45 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// source: GetChirpsByUserID.sql
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const getChirpsByUserID = `-- name: GetChirpsByUserID :many
|
||||
SELECT id, created_at, updated_at, body, user_id FROM chirps WHERE user_id = $1 ORDER BY created_at
|
||||
`
|
||||
|
||||
func (q *Queries) GetChirpsByUserID(ctx context.Context, userID uuid.UUID) ([]Chirp, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getChirpsByUserID, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Chirp
|
||||
for rows.Next() {
|
||||
var i Chirp
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Body,
|
||||
&i.UserID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
const getUserByEmail = `-- name: GetUserByEmail :one
|
||||
SELECT id, created_at, updated_at, email, hashed_password FROM users WHERE email = $1
|
||||
SELECT id, created_at, updated_at, email, hashed_password, is_chirpy_red FROM users WHERE email = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error) {
|
||||
@@ -22,6 +22,7 @@ func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error
|
||||
&i.UpdatedAt,
|
||||
&i.Email,
|
||||
&i.HashedPassword,
|
||||
&i.IsChirpyRed,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
const getUserByID = `-- name: GetUserByID :one
|
||||
SELECT id, created_at, updated_at, email, hashed_password FROM users WHERE id = $1
|
||||
SELECT id, created_at, updated_at, email, hashed_password, is_chirpy_red FROM users WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByID(ctx context.Context, id uuid.UUID) (User, error) {
|
||||
@@ -24,6 +24,7 @@ func (q *Queries) GetUserByID(ctx context.Context, id uuid.UUID) (User, error) {
|
||||
&i.UpdatedAt,
|
||||
&i.Email,
|
||||
&i.HashedPassword,
|
||||
&i.IsChirpyRed,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
const updateUserEmailAndPassword = `-- name: UpdateUserEmailAndPassword :one
|
||||
UPDATE users SET email = $1, hashed_password = $2, updated_at = CURRENT_TIMESTAMP WHERE id = $3
|
||||
RETURNING id, created_at, updated_at, email, hashed_password
|
||||
RETURNING id, created_at, updated_at, email, hashed_password, is_chirpy_red
|
||||
`
|
||||
|
||||
type UpdateUserEmailAndPasswordParams struct {
|
||||
@@ -31,6 +31,7 @@ func (q *Queries) UpdateUserEmailAndPassword(ctx context.Context, arg UpdateUser
|
||||
&i.UpdatedAt,
|
||||
&i.Email,
|
||||
&i.HashedPassword,
|
||||
&i.IsChirpyRed,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
22
internal/database/UpgradeUserToChirpyRed.sql.go
Normal file
22
internal/database/UpgradeUserToChirpyRed.sql.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// source: UpgradeUserToChirpyRed.sql
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const upgradeUserToChirpyRed = `-- name: UpgradeUserToChirpyRed :exec
|
||||
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) UpgradeUserToChirpyRed(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := q.db.ExecContext(ctx, upgradeUserToChirpyRed, id)
|
||||
return err
|
||||
}
|
||||
@@ -34,4 +34,5 @@ type User struct {
|
||||
UpdatedAt time.Time
|
||||
Email string
|
||||
HashedPassword string
|
||||
IsChirpyRed bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user