diff --git a/internal/repository/models.go b/internal/repository/models.go index e5d5662..cb11c6c 100644 --- a/internal/repository/models.go +++ b/internal/repository/models.go @@ -10,13 +10,14 @@ import ( ) type User struct { - ID uuid.UUID `json:"id"` - Email string `json:"email"` - FullName string `json:"full_name"` - PasswordHash string `json:"password_hash"` - IsAdmin bool `json:"is_admin"` - CreatedAt pgtype.Timestamptz `json:"created_at"` - UpdatedAt pgtype.Timestamptz `json:"updated_at"` - LastLogin pgtype.Timestamptz `json:"last_login"` - PhoneNumber pgtype.Text `json:"phone_number"` + ID uuid.UUID `json:"id"` + Email string `json:"email"` + FullName string `json:"full_name"` + PasswordHash string `json:"password_hash"` + IsAdmin bool `json:"is_admin"` + CreatedAt pgtype.Timestamptz `json:"created_at"` + UpdatedAt pgtype.Timestamptz `json:"updated_at"` + LastLogin pgtype.Timestamptz `json:"last_login"` + PhoneNumber pgtype.Text `json:"phone_number"` + ProfilePicture pgtype.Text `json:"profile_picture"` } diff --git a/internal/repository/users.sql.go b/internal/repository/users.sql.go index 2beb2ee..176d07e 100644 --- a/internal/repository/users.sql.go +++ b/internal/repository/users.sql.go @@ -9,10 +9,11 @@ import ( "context" "github.com/google/uuid" + "github.com/jackc/pgx/v5/pgtype" ) 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) { @@ -34,6 +35,7 @@ func (q *Queries) FindAllUsers(ctx context.Context) ([]User, error) { &i.UpdatedAt, &i.LastLogin, &i.PhoneNumber, + &i.ProfilePicture, ); err != nil { return nil, err } @@ -46,7 +48,7 @@ func (q *Queries) FindAllUsers(ctx context.Context) ([]User, error) { } 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) { @@ -62,12 +64,13 @@ func (q *Queries) FindUserEmail(ctx context.Context, email string) (User, error) &i.UpdatedAt, &i.LastLogin, &i.PhoneNumber, + &i.ProfilePicture, ) return i, err } 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) { @@ -83,6 +86,7 @@ func (q *Queries) FindUserId(ctx context.Context, id uuid.UUID) (User, error) { &i.UpdatedAt, &i.LastLogin, &i.PhoneNumber, + &i.ProfilePicture, ) return i, err } @@ -114,3 +118,19 @@ func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (uuid.UU err := row.Scan(&id) 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 +}