Kleine Bugfixes und Aufräumarbeiten

This commit is contained in:
2023-10-28 10:52:06 +02:00
parent 34ef95ad76
commit 33cbf4b215
11 changed files with 165 additions and 128 deletions

View File

@ -68,21 +68,23 @@ func (db *DB) WriteParticipant(p *Participant) error {
return nil
}
func (db *DB) WriteGivenAnswer(b *Briefing, p *Participant, q *Question, g int) error {
_, err := db.Exec(`
INSERT INTO given_answers
(briefing_id, participant_id, question_id, given_answer)
VALUES
(?, ?, ?, ?)
`, b.ID, p.ID, q.ID, g)
if err != nil {
return fmt.Errorf("*DB.writeGivenAnswers: db.Exec(): %v\n", err)
func (db *DB) WriteGivenAnswers(b Briefing, p Participant, sq []Question, givenAnswers []int) error {
for i, q := range sq {
_, err := db.Exec(`
INSERT INTO given_answers
(briefing_id, participant_id, question_id, given_answer)
VALUES
(?, ?, ?, ?)
`, b.ID, p.ID, q.ID, givenAnswers[i])
if err != nil {
return fmt.Errorf("*DB.WriteGivenAnswers: db.Exec(): %v\n", err)
}
}
return nil
}
func (db *DB) GetAllOverviewTableData() ([]*OverviewTableData, error) {
func (db *DB) GetAllOverviewTableData() ([]OverviewTableData, error) {
rows, err := db.Query(`
SELECT
i.first_name,
@ -115,7 +117,7 @@ func (db *DB) GetAllOverviewTableData() ([]*OverviewTableData, error) {
}
defer rows.Close()
data := make([]*OverviewTableData, 0)
data := make([]OverviewTableData, 0)
for rows.Next() {
otd := new(OverviewTableData)
@ -135,7 +137,7 @@ func (db *DB) GetAllOverviewTableData() ([]*OverviewTableData, error) {
return nil, fmt.Errorf("*DB.ReadAllBriefings: rows.Scan(): %v\n", err)
}
data = append(data, otd)
data = append(data, *otd)
}
return data, nil