Add option to subscribe to mailinglist

This commit is contained in:
Gonne 2024-01-03 17:04:38 +01:00
parent 47c546b880
commit 5c896e6a96
11 changed files with 38 additions and 22 deletions

View file

@ -50,7 +50,7 @@ func (r *TutorRepo) Add(tutor models.Tutor) (int, error) {
//Don't add identical tutors
existentTutor, err := r.FindByNameAndEmail(tutor.Name, tutor.Email)
if errors.Is(err, sql.ErrNoRows) {
sqlResult, err := r.db.Exec("INSERT INTO `tutor` (name, email) VALUES (?,?)", tutor.Name, tutor.Email)
sqlResult, err := r.db.Exec("INSERT INTO `tutor` (name, email, subscribeToMailinglist) VALUES (?,?,?)", tutor.Name, tutor.Email, tutor.SubscribeToMailinglist)
if err != nil {
err = fmt.Errorf("SQL-error inserting new tutor: %w", err)
log.Println(err.Error())
@ -67,7 +67,7 @@ func (r *TutorRepo) Add(tutor models.Tutor) (int, error) {
func (r *TutorRepo) getFromRow(row *sql.Row) (models.Tutor, error) {
var tutor models.Tutor
if err := row.Scan(&tutor.Id, &tutor.Name, &tutor.Email); err != nil {
if err := row.Scan(&tutor.Id, &tutor.Name, &tutor.Email, &tutor.SubscribeToMailinglist); err != nil {
err = fmt.Errorf("SQL-error scanning tutor row: %w", err)
log.Println(err.Error())
return models.Tutor{}, err
@ -79,7 +79,7 @@ func (r *TutorRepo) getFromRows(rows *sql.Rows) ([]models.Tutor, error) {
var tutors []models.Tutor
for rows.Next() {
var tutor models.Tutor
if err := rows.Scan(&tutor.Id, &tutor.Name, &tutor.Email); err != nil {
if err := rows.Scan(&tutor.Id, &tutor.Name, &tutor.Email, &tutor.SubscribeToMailinglist); err != nil {
err = fmt.Errorf("Error scanning tutor row: %w", err)
log.Println(err.Error())
return tutors, err