feat: add support for new fields in user table

This commit is contained in:
2025-06-05 20:49:35 +02:00
parent e774f415d8
commit cb3a6ddc58
3 changed files with 21 additions and 11 deletions

View File

@ -35,4 +35,6 @@ type User struct {
LastLogin *time.Time `json:"last_login"` LastLogin *time.Time `json:"last_login"`
PhoneNumber *string `json:"phone_number"` PhoneNumber *string `json:"phone_number"`
ProfilePicture *string `json:"profile_picture"` ProfilePicture *string `json:"profile_picture"`
CreatedBy *uuid.UUID `json:"created_by"`
EmailVerified bool `json:"email_verified"`
} }

View File

@ -12,7 +12,7 @@ import (
) )
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, profile_picture FROM users SELECT id, email, full_name, password_hash, is_admin, created_at, updated_at, last_login, phone_number, profile_picture, created_by, email_verified FROM users
` `
func (q *Queries) FindAllUsers(ctx context.Context) ([]User, error) { func (q *Queries) FindAllUsers(ctx context.Context) ([]User, error) {
@ -35,6 +35,8 @@ func (q *Queries) FindAllUsers(ctx context.Context) ([]User, error) {
&i.LastLogin, &i.LastLogin,
&i.PhoneNumber, &i.PhoneNumber,
&i.ProfilePicture, &i.ProfilePicture,
&i.CreatedBy,
&i.EmailVerified,
); err != nil { ); err != nil {
return nil, err return nil, err
} }
@ -47,7 +49,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, profile_picture 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, created_by, email_verified 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) {
@ -64,12 +66,14 @@ func (q *Queries) FindUserEmail(ctx context.Context, email string) (User, error)
&i.LastLogin, &i.LastLogin,
&i.PhoneNumber, &i.PhoneNumber,
&i.ProfilePicture, &i.ProfilePicture,
&i.CreatedBy,
&i.EmailVerified,
) )
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, profile_picture 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, created_by, email_verified 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) {
@ -86,15 +90,17 @@ func (q *Queries) FindUserId(ctx context.Context, id uuid.UUID) (User, error) {
&i.LastLogin, &i.LastLogin,
&i.PhoneNumber, &i.PhoneNumber,
&i.ProfilePicture, &i.ProfilePicture,
&i.CreatedBy,
&i.EmailVerified,
) )
return i, err return i, err
} }
const insertUser = `-- name: InsertUser :one const insertUser = `-- name: InsertUser :one
INSERT INTO users ( INSERT INTO users (
email, full_name, password_hash, is_admin email, full_name, password_hash, is_admin, created_by
) VALUES ( ) VALUES (
$1, $2, $3, $4 $1, $2, $3, $4, $5
) )
RETURNING id RETURNING id
` `
@ -104,6 +110,7 @@ type InsertUserParams struct {
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"`
CreatedBy *uuid.UUID `json:"created_by"`
} }
func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (uuid.UUID, error) { func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (uuid.UUID, error) {
@ -112,6 +119,7 @@ func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (uuid.UU
arg.FullName, arg.FullName,
arg.PasswordHash, arg.PasswordHash,
arg.IsAdmin, arg.IsAdmin,
arg.CreatedBy,
) )
var id uuid.UUID var id uuid.UUID
err := row.Scan(&id) err := row.Scan(&id)

View File

@ -3,9 +3,9 @@ SELECT * FROM users;
-- name: InsertUser :one -- name: InsertUser :one
INSERT INTO users ( INSERT INTO users (
email, full_name, password_hash, is_admin email, full_name, password_hash, is_admin, created_by
) VALUES ( ) VALUES (
$1, $2, $3, $4 $1, $2, $3, $4, $5
) )
RETURNING id; RETURNING id;