diff --git a/backend/handlers/auth/local.go b/backend/handlers/auth/local.go index dd88af9..f6f5b7f 100644 --- a/backend/handlers/auth/local.go +++ b/backend/handlers/auth/local.go @@ -14,7 +14,6 @@ import ( "fmt" "log" "net/http" - "net/mail" "regexp" "strings" "sync" @@ -136,9 +135,8 @@ func RegisterHandler(w http.ResponseWriter, r *http.Request) { } // Validate email format - _, err := mail.ParseAddress(req.Email) - if err != nil { - http.Error(w, "invalid email format", http.StatusBadRequest) + if err := validators.ValidateEmail(req.Email); err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) return } diff --git a/backend/handlers/bookings/bookings.go b/backend/handlers/bookings/bookings.go index a35defe..41fbc48 100644 --- a/backend/handlers/bookings/bookings.go +++ b/backend/handlers/bookings/bookings.go @@ -687,7 +687,7 @@ func GetAllAdminBookingsHandler(w http.ResponseWriter, r *http.Request) { func GetAllBookingsByUserHandler(w http.ResponseWriter, r *http.Request) { userID := chi.URLParam(r, "user_id") if userID == "" || !validators.IsValidID(userID) { - http.Error(w, "User not found", http.StatusNotFound) + http.Error(w, "user not found", http.StatusNotFound) return } diff --git a/backend/handlers/services/services.go b/backend/handlers/services/services.go index f49774f..b42572e 100644 --- a/backend/handlers/services/services.go +++ b/backend/handlers/services/services.go @@ -398,7 +398,7 @@ func ServicesHandler(w http.ResponseWriter, r *http.Request) { func ServicesEligibleForUserHandler(w http.ResponseWriter, r *http.Request) { userID := chi.URLParam(r, "user_id") if userID == "" || !validators.IsValidID(userID) { - http.Error(w, "User not found", http.StatusNotFound) + http.Error(w, "user not found", http.StatusNotFound) return } @@ -406,7 +406,7 @@ func ServicesEligibleForUserHandler(w http.ResponseWriter, r *http.Request) { var dob time.Time err := db.DB.QueryRow(r.Context(), `SELECT date_of_birth FROM users WHERE id = $1`, userID).Scan(&dob) if errors.Is(err, sql.ErrNoRows) { - http.Error(w, "User not found", http.StatusNotFound) + http.Error(w, "user not found", http.StatusNotFound) return } if err != nil { diff --git a/backend/handlers/user/customer_relationship.go b/backend/handlers/user/customer_relationship.go index cf34b59..387e71e 100644 --- a/backend/handlers/user/customer_relationship.go +++ b/backend/handlers/user/customer_relationship.go @@ -36,7 +36,7 @@ type TopService struct { func GetCustomerRelationshipHandler(w http.ResponseWriter, r *http.Request) { userID := chi.URLParam(r, "id") if userID == "" || !validators.IsValidID(userID) { - http.Error(w, "User not found", http.StatusNotFound) + http.Error(w, "user not found", http.StatusNotFound) return } @@ -52,7 +52,7 @@ func GetCustomerRelationshipHandler(w http.ResponseWriter, r *http.Request) { return } if !exists { - http.Error(w, "User not found", http.StatusNotFound) + http.Error(w, "user not found", http.StatusNotFound) return } diff --git a/backend/handlers/user/profile.go b/backend/handlers/user/profile.go index 2704f0f..b3ddac7 100644 --- a/backend/handlers/user/profile.go +++ b/backend/handlers/user/profile.go @@ -301,7 +301,7 @@ func UpdateProfileHandler(w http.ResponseWriter, r *http.Request) { func GetAdminUserHandler(w http.ResponseWriter, r *http.Request) { userID := chi.URLParam(r, "id") if userID == "" || !validators.IsValidID(userID) { - http.Error(w, "User not found", http.StatusNotFound) + http.Error(w, "user not found", http.StatusNotFound) return } @@ -330,7 +330,7 @@ func GetAdminUserHandler(w http.ResponseWriter, r *http.Request) { if err != nil { if errors.Is(err, sql.ErrNoRows) { - http.Error(w, "User not found", http.StatusNotFound) + http.Error(w, "user not found", http.StatusNotFound) return } log.Printf("Failed to fetch user %s: %v", userID, err) @@ -610,7 +610,7 @@ type ServiceForPatchTest struct { func GetEligiblePatchTestServicesHandler(w http.ResponseWriter, r *http.Request) { userID := chi.URLParam(r, "id") if userID == "" || !validators.IsValidID(userID) { - http.Error(w, "User not found", http.StatusNotFound) + http.Error(w, "user not found", http.StatusNotFound) return } @@ -665,7 +665,7 @@ type AddPatchTestRequest struct { func AddPatchTestHandler(w http.ResponseWriter, r *http.Request) { userID := chi.URLParam(r, "id") if userID == "" || !validators.IsValidID(userID) { - http.Error(w, "User not found", http.StatusNotFound) + http.Error(w, "user not found", http.StatusNotFound) return } @@ -726,7 +726,7 @@ type UserPatchTest struct { func GetUserPatchTestsHandler(w http.ResponseWriter, r *http.Request) { userID := chi.URLParam(r, "user_id") if userID == "" || !validators.IsValidID(userID) { - http.Error(w, "User not found", http.StatusNotFound) + http.Error(w, "user not found", http.StatusNotFound) return } @@ -763,7 +763,7 @@ func DeletePatchTestHandler(w http.ResponseWriter, r *http.Request) { userID := chi.URLParam(r, "user_id") testID := chi.URLParam(r, "test_id") if userID == "" || !validators.IsValidID(userID) { - http.Error(w, "User not found", http.StatusNotFound) + http.Error(w, "user not found", http.StatusNotFound) return } if testID == "" || !validators.IsValidID(testID) {