// CreateUser checks if user already exists, and if not, creates it
CreateUser checks if user already exists, and if not, creates it
// CreateUser checks if user already exists and if not creates it
func (db *Postgres) CreateUser(user *models.User) error {
	var count int
	if err := db.Model(user).Where("email = ?", user.Email).Count(&count).Error; err != nil || count > 0 {
		fmt.Println("user_exists", err)
		return helpers.NewError(http.StatusBadRequest, "user_exists", "the user already exists", err)
	}
	if err := db.Create(user).Error; err != nil {
		fmt.Println("user_creation_failed", err)
		return helpers.NewError(http.StatusInternalServerError, "user_creation_failed", "could not create the user", err)
	}
	return nil
}
func ( db * Postgres ) CreateUser ( user * models . User ) error { var count int if err := db . Model ( user ) . Where ( " " , user . Email ) . Count ( & count ) . Error ; err != nil || count > 0 { fmt . Println ( " " , err ) return helpers . NewError ( http . StatusBadRequest , " " , " " , err ) } if err := db . Create ( user ) . Error ; err != nil { fmt . Println ( " " , err ) return helpers . NewError ( http . StatusInternalServerError , " " , " " , err ) } return nil }
CreateUser checks if user already exists, and if not, creates it
CreateUser checks if user already exists and if not creates it