feat: update user model + update profile picture
This commit is contained in:
@ -10,13 +10,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID uuid.UUID `json:"id"`
|
ID uuid.UUID `json:"id"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
PasswordHash string `json:"password_hash"`
|
PasswordHash string `json:"password_hash"`
|
||||||
IsAdmin bool `json:"is_admin"`
|
IsAdmin bool `json:"is_admin"`
|
||||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||||
LastLogin pgtype.Timestamptz `json:"last_login"`
|
LastLogin pgtype.Timestamptz `json:"last_login"`
|
||||||
PhoneNumber pgtype.Text `json:"phone_number"`
|
PhoneNumber pgtype.Text `json:"phone_number"`
|
||||||
|
ProfilePicture pgtype.Text `json:"profile_picture"`
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
)
|
)
|
||||||
|
|
||||||
const findAllUsers = `-- name: FindAllUsers :many
|
const findAllUsers = `-- name: FindAllUsers :many
|
||||||
SELECT id, email, full_name, password_hash, is_admin, created_at, updated_at, last_login, phone_number FROM users
|
SELECT id, email, full_name, password_hash, is_admin, created_at, updated_at, last_login, phone_number, profile_picture FROM users
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) FindAllUsers(ctx context.Context) ([]User, error) {
|
func (q *Queries) FindAllUsers(ctx context.Context) ([]User, error) {
|
||||||
@ -34,6 +35,7 @@ func (q *Queries) FindAllUsers(ctx context.Context) ([]User, error) {
|
|||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
&i.LastLogin,
|
&i.LastLogin,
|
||||||
&i.PhoneNumber,
|
&i.PhoneNumber,
|
||||||
|
&i.ProfilePicture,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -46,7 +48,7 @@ func (q *Queries) FindAllUsers(ctx context.Context) ([]User, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const findUserEmail = `-- name: FindUserEmail :one
|
const findUserEmail = `-- name: FindUserEmail :one
|
||||||
SELECT id, email, full_name, password_hash, is_admin, created_at, updated_at, last_login, phone_number FROM users WHERE email = $1 LIMIT 1
|
SELECT id, email, full_name, password_hash, is_admin, created_at, updated_at, last_login, phone_number, profile_picture FROM users WHERE email = $1 LIMIT 1
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) FindUserEmail(ctx context.Context, email string) (User, error) {
|
func (q *Queries) FindUserEmail(ctx context.Context, email string) (User, error) {
|
||||||
@ -62,12 +64,13 @@ func (q *Queries) FindUserEmail(ctx context.Context, email string) (User, error)
|
|||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
&i.LastLogin,
|
&i.LastLogin,
|
||||||
&i.PhoneNumber,
|
&i.PhoneNumber,
|
||||||
|
&i.ProfilePicture,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
const findUserId = `-- name: FindUserId :one
|
const findUserId = `-- name: FindUserId :one
|
||||||
SELECT id, email, full_name, password_hash, is_admin, created_at, updated_at, last_login, phone_number FROM users WHERE id = $1 LIMIT 1
|
SELECT id, email, full_name, password_hash, is_admin, created_at, updated_at, last_login, phone_number, profile_picture FROM users WHERE id = $1 LIMIT 1
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) FindUserId(ctx context.Context, id uuid.UUID) (User, error) {
|
func (q *Queries) FindUserId(ctx context.Context, id uuid.UUID) (User, error) {
|
||||||
@ -83,6 +86,7 @@ func (q *Queries) FindUserId(ctx context.Context, id uuid.UUID) (User, error) {
|
|||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
&i.LastLogin,
|
&i.LastLogin,
|
||||||
&i.PhoneNumber,
|
&i.PhoneNumber,
|
||||||
|
&i.ProfilePicture,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
@ -114,3 +118,19 @@ func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (uuid.UU
|
|||||||
err := row.Scan(&id)
|
err := row.Scan(&id)
|
||||||
return id, err
|
return id, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updateProfilePicture = `-- name: UpdateProfilePicture :exec
|
||||||
|
UPDATE users
|
||||||
|
SET profile_picture = $1
|
||||||
|
WHERE id = $2
|
||||||
|
`
|
||||||
|
|
||||||
|
type UpdateProfilePictureParams struct {
|
||||||
|
ProfilePicture pgtype.Text `json:"profile_picture"`
|
||||||
|
ID uuid.UUID `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) UpdateProfilePicture(ctx context.Context, arg UpdateProfilePictureParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, updateProfilePicture, arg.ProfilePicture, arg.ID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user