@ -10,10 +10,11 @@ import (
func ( d * DB ) CreateUser ( ctx context . Context , create * store . User ) ( * store . User , error ) {
fields := [ ] string { "username" , "role" , "email" , "nickname" , "password_hash" , "avatar_url" }
args := [ ] any { create . Username , create . Role , create . Email , create . Nickname , create . PasswordHash , create . AvatarURL }
stmt := "INSERT INTO \"user\" (" + strings . Join ( fields , ", " ) + ") VALUES (" + placeholders ( len ( args ) ) + ") RETURNING id, avatar_url, created_ts, updated_ts, row_status"
stmt := "INSERT INTO \"user\" (" + strings . Join ( fields , ", " ) + ") VALUES (" + placeholders ( len ( args ) ) + ") RETURNING id, avatar_url, description, created_ts, updated_ts, row_status"
if err := d . db . QueryRowContext ( ctx , stmt , args ... ) . Scan (
& create . ID ,
& create . AvatarURL ,
& create . Description ,
& create . CreatedTs ,
& create . UpdatedTs ,
& create . RowStatus ,
@ -47,12 +48,15 @@ func (d *DB) UpdateUser(ctx context.Context, update *store.UpdateUser) (*store.U
if v := update . PasswordHash ; v != nil {
set , args = append ( set , "password_hash = " + placeholder ( len ( args ) + 1 ) ) , append ( args , * v )
}
if v := update . Description ; v != nil {
set , args = append ( set , "description = " + placeholder ( len ( args ) + 1 ) ) , append ( args , * v )
}
query := `
UPDATE "user"
SET ` + strings.Join(set, ", ") + `
WHERE id = ` + placeholder(len(args)+1) + `
RETURNING id , username , role , email , nickname , password_hash , avatar_url , created_ts, updated_ts , row_status
RETURNING id , username , role , email , nickname , password_hash , avatar_url , description, created_ts, updated_ts , row_status
`
args = append ( args , update . ID )
user := & store . User { }
@ -64,6 +68,7 @@ func (d *DB) UpdateUser(ctx context.Context, update *store.UpdateUser) (*store.U
& user . Nickname ,
& user . PasswordHash ,
& user . AvatarURL ,
& user . Description ,
& user . CreatedTs ,
& user . UpdatedTs ,
& user . RowStatus ,
@ -102,6 +107,7 @@ func (d *DB) ListUsers(ctx context.Context, find *store.FindUser) ([]*store.User
nickname ,
password_hash ,
avatar_url ,
description ,
created_ts ,
updated_ts ,
row_status
@ -126,6 +132,7 @@ func (d *DB) ListUsers(ctx context.Context, find *store.FindUser) ([]*store.User
& user . Nickname ,
& user . PasswordHash ,
& user . AvatarURL ,
& user . Description ,
& user . CreatedTs ,
& user . UpdatedTs ,
& user . RowStatus ,
@ -143,9 +150,7 @@ func (d *DB) ListUsers(ctx context.Context, find *store.FindUser) ([]*store.User
}
func ( d * DB ) DeleteUser ( ctx context . Context , delete * store . DeleteUser ) error {
result , err := d . db . ExecContext ( ctx , `
DELETE FROM "user" WHERE id = $ 1
` , delete . ID )
result , err := d . db . ExecContext ( ctx , ` DELETE FROM "user" WHERE id = $1 ` , delete . ID )
if err != nil {
return err
}