Réécrire le projet pour la v4 #4

Merged
vlbeaudoin merged 16 commits from breaking/v4 into main 2023-05-25 23:31:14 -04:00
Showing only changes of commit 3e37e8ffef - Show all commits

View file

@ -1,6 +1,7 @@
package data
import (
"errors"
"fmt"
"git.agecem.com/agecem/bottin/v4/models"
@ -68,12 +69,23 @@ func (d *DataClient) InsertMembres(membres []models.Membre) (int64, error) {
}
for _, membre := range membres {
_, err := tx.NamedExec("INSERT INTO membres (id, last_name, first_name, prefered_name, programme_id) VALUES (:id, :last_name, :first_name, :prefered_name, :programme_id);", &membre)
if membre.ID == "" {
tx.Rollback()
return 0, errors.New("Cannot insert membre with no membre_id")
}
result, err := tx.NamedExec("INSERT INTO membres (id, last_name, first_name, prefered_name, programme_id) VALUES (:id, :last_name, :first_name, :prefered_name, :programme_id);", &membre)
if err != nil {
tx.Rollback()
return rowsInserted, err
return 0, err
}
rowsInserted++
rows, err := result.RowsAffected()
if err != nil {
tx.Rollback()
return 0, err
}
rowsInserted += rows
}
err = tx.Commit()
@ -93,12 +105,24 @@ func (d *DataClient) InsertProgrammes(programmes []models.Programme) (int64, err
}
for _, programme := range programmes {
_, err := tx.NamedExec("INSERT INTO programmes (id, titre) VALUES (:id, :titre);", &programme)
if programme.ID == "" {
tx.Rollback()
return 0, errors.New("Cannot insert programme with no programme_id")
}
result, err := tx.NamedExec("INSERT INTO programmes (id, titre) VALUES (:id, :titre);", &programme)
if err != nil {
tx.Rollback()
return rowsInserted, err
return 0, err
}
rowsInserted++
rows, err := result.RowsAffected()
if err != nil {
tx.Rollback()
return 0, err
}
rowsInserted += rows
}
err = tx.Commit()