QA: add a list of team's exercices

This commit is contained in:
nemunaire 2020-11-13 13:11:58 +01:00
parent 911bcb032e
commit ea334a8a2f
5 changed files with 154 additions and 23 deletions

View file

@ -457,6 +457,17 @@ CREATE TABLE IF NOT EXISTS teams_qa_todo(
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice),
FOREIGN KEY(id_team) REFERENCES teams(id_team)
) DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
`); err != nil {
return err
}
if _, err := db.Exec(`
CREATE TABLE IF NOT EXISTS teams_qa_view(
id_view INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
id_team INTEGER NOT NULL,
id_exercice INTEGER NOT NULL,
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice),
FOREIGN KEY(id_team) REFERENCES teams(id_team)
) DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
`); err != nil {
return err
}

View file

@ -238,3 +238,34 @@ func (t Team) NewQATodo(idExercice int64) (QATodo, error) {
return QATodo{tid, t.Id, idExercice}, nil
}
}
// QAView
func (t Team) GetQAView() (res []QATodo, err error) {
var rows *sql.Rows
if rows, err = DBQuery("SELECT id_view, id_exercice FROM teams_qa_view WHERE id_team = ?", t.Id); err != nil {
return nil, err
}
defer rows.Close()
for rows.Next() {
var t QATodo
if err = rows.Scan(&t.Id, &t.IdExercice); err != nil {
return
}
res = append(res, t)
}
err = rows.Err()
return
}
func (t Team) NewQAView(idExercice int64) (QATodo, error) {
if res, err := DBExec("INSERT INTO teams_qa_view (id_team, id_exercice) VALUES (?, ?)", t.Id, idExercice); err != nil {
return QATodo{}, err
} else if tid, err := res.LastInsertId(); err != nil {
return QATodo{}, err
} else {
return QATodo{tid, t.Id, idExercice}, nil
}
}