Remove legacy question storage (#7)
Deletes obsolete question/answer/vote persistence and the compatibility answer endpoint. Existing databases drop the legacy tables through migration 009. Plumber replies now notify the root homeowner even when nested beneath another plumber reply. Post and reply forms prevent duplicate submissions and show progress while posting. Reviewed-on: #7 Co-authored-by: codegirl-007 <s.raide@gmail.com>
This commit was merged in pull request #7.
This commit is contained in:
+20
-2
@@ -9,12 +9,19 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
|
||||
"plumber/internal/store/sqlc"
|
||||
)
|
||||
|
||||
// ErrLastAdmin is returned when demoting the only remaining admin.
|
||||
var ErrLastAdmin = errors.New("cannot demote the last admin")
|
||||
var (
|
||||
// ErrLastAdmin is returned when demoting the only remaining admin.
|
||||
ErrLastAdmin = errors.New("cannot demote the last admin")
|
||||
// ErrDuplicateUsername is returned when inserting an existing username.
|
||||
ErrDuplicateUsername = errors.New("username taken")
|
||||
// ErrDuplicateEmail is returned when inserting or updating an existing email.
|
||||
ErrDuplicateEmail = errors.New("email taken")
|
||||
)
|
||||
|
||||
// Role is a user privilege level stored in users.role.
|
||||
type Role string
|
||||
@@ -51,6 +58,17 @@ func NormalizeUsername(s string) string {
|
||||
return strings.ToLower(strings.TrimSpace(s))
|
||||
}
|
||||
|
||||
func mapUniqueViolation(err error) error {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) && pgErr.Code == "23505" {
|
||||
if strings.Contains(strings.ToLower(pgErr.ConstraintName), "email") {
|
||||
return ErrDuplicateEmail
|
||||
}
|
||||
return ErrDuplicateUsername
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func toUser(db *sql.DB, id, username, name, role, email, avatarURL, state, createdAt, passwordHash string) *User {
|
||||
return &User{
|
||||
ID: id,
|
||||
|
||||
Reference in New Issue
Block a user