qa: Add todo list on home page
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2020-09-08 13:30:28 +02:00
commit 42d594ccac
5 changed files with 159 additions and 1 deletions

View file

@ -446,6 +446,17 @@ CREATE TABLE IF NOT EXISTS qa_comments(
FOREIGN KEY(id_qa) REFERENCES exercices_qa(id_qa),
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_todo(
id_todo 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

@ -64,6 +64,26 @@ func (e Exercice) GetQAQueries() (res []QAQuery, err error) {
return
}
// GetQAQueries returns a list of all QAQuery registered for the Exercice.
func (t Team) GetQAQueries() (res []QAQuery, err error) {
var rows *sql.Rows
if rows, err = DBQuery("SELECT id_qa, id_exercice, id_team, authuser, creation, state, subject, solved, closed FROM exercices_qa WHERE id_team = ?", t.Id); err != nil {
return nil, err
}
defer rows.Close()
for rows.Next() {
var q QAQuery
if err = rows.Scan(&q.Id, &q.IdExercice, &q.IdTeam, &q.User, &q.Creation, &q.State, &q.Subject, &q.Solved, &q.Closed); err != nil {
return
}
res = append(res, q)
}
err = rows.Err()
return
}
// GetQAQuery retrieves the query with the given identifier.
func (e Exercice) GetQAQuery(id int64) (q QAQuery, err error) {
err = DBQueryRow("SELECT id_qa, id_exercice, id_team, authuser, creation, state, subject, solved, closed FROM exercices_qa WHERE id_qa = ? AND id_exercice = ?", id, e.Id).Scan(&q.Id, &q.IdExercice, &q.IdTeam, &q.User, &q.Creation, &q.State, &q.Subject, &q.Solved, &q.Closed)
@ -181,3 +201,38 @@ func (c QAComment) Delete() (int64, error) {
return nb, err
}
}
type QATodo struct {
Id int64 `json:"id"`
IdTeam int64 `json:"id_team,omitempty"`
IdExercice int64 `json:"id_exercice"`
}
func (t Team) GetQATodo() (res []QATodo, err error) {
var rows *sql.Rows
if rows, err = DBQuery("SELECT id_todo, id_exercice FROM teams_qa_todo 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) NewQATodo(idExercice int64) (QATodo, error) {
if res, err := DBExec("INSERT INTO teams_qa_todo (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
}
}