ch13.3
This commit is contained in:
@@ -75,7 +75,7 @@ func ValidateUser(v *validator.Validator, user *User) {
|
||||
ValidatePasswordPlaintext(v, *user.Password.plaintext)
|
||||
}
|
||||
|
||||
if user.Password.hash != nil {
|
||||
if user.Password.hash == nil {
|
||||
panic("missing password hash for user")
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ func (m UserModel) Insert(user *User) error {
|
||||
err := m.DB.QueryRowContext(ctx, query, args...).Scan(&user.ID, &user.CreatedAt, &user.Version)
|
||||
if err != nil {
|
||||
switch {
|
||||
case err.Error() == `pq: duplicate key value violates unique constraint "users_email_key"`:
|
||||
case err.Error() == `pq: duplicate key value violates unique constraint "users_email_key" (23505)`:
|
||||
return ErrDuplicateEmail
|
||||
default:
|
||||
return err
|
||||
@@ -161,7 +161,7 @@ func (m UserModel) Update(user *User) error {
|
||||
err := m.DB.QueryRowContext(ctx, query, args...).Scan(&user.Version)
|
||||
if err != nil {
|
||||
switch {
|
||||
case err.Error() == `pq: duplicate key value violates unique constraint "users_email_key"`:
|
||||
case err.Error() == `pq: duplicate key value violates unique constraint "users_email_key" (23505)`:
|
||||
return ErrDuplicateEmail
|
||||
default:
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user