feat: implemented handling webhooks
This commit is contained in:
@@ -70,6 +70,18 @@ func GetBearerToken(headers http.Header) (string, error) {
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func GetAPIKey(headers http.Header) (string, error) {
|
||||
authorizationHeader := headers.Get("Authorization")
|
||||
|
||||
if strings.TrimSpace(authorizationHeader) == "" {
|
||||
return "", errors.New("Missing Authorization header")
|
||||
}
|
||||
|
||||
apiKey := strings.TrimPrefix(authorizationHeader, "ApiKey ")
|
||||
|
||||
return apiKey, nil
|
||||
}
|
||||
|
||||
func MakeRefreshToken() string {
|
||||
bytes := make([]byte, 32)
|
||||
rand.Read(bytes)
|
||||
|
||||
@@ -34,4 +34,5 @@ type User struct {
|
||||
UpdatedAt time.Time
|
||||
Email string
|
||||
HashedPassword string
|
||||
IsChirpyRed bool
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user