feat: update user model + update profile picture

This commit is contained in:
2025-05-24 17:17:45 +02:00
parent 24c72800ad
commit 64faa4ca5f
2 changed files with 33 additions and 12 deletions

View File

@ -19,4 +19,5 @@ type User struct {
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"`
} }

View File

@ -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
}