libfic/mcq: remove Kind, as we can only handle checkbox; another kind of record should be created to handle select/radio

This commit is contained in:
nemunaire 2017-12-17 16:28:31 +01:00
commit 4052969304
4 changed files with 11 additions and 20 deletions

View file

@ -8,7 +8,6 @@ type MCQ struct {
Id int64 `json:"id"`
IdExercice int64 `json:"idExercice"`
Title string `json:"title"`
Kind string `json:"kind"`
Entries []MCQ_entry `json:"entries"`
}
@ -19,7 +18,7 @@ type MCQ_entry struct {
}
func (e Exercice) GetMCQ() ([]MCQ, error) {
if rows, err := DBQuery("SELECT id_mcq, id_exercice, title, kind FROM exercice_mcq WHERE id_exercice = ?", e.Id); err != nil {
if rows, err := DBQuery("SELECT id_mcq, id_exercice, title FROM exercice_mcq WHERE id_exercice = ?", e.Id); err != nil {
return nil, err
} else {
defer rows.Close()
@ -29,7 +28,7 @@ func (e Exercice) GetMCQ() ([]MCQ, error) {
var m MCQ
m.IdExercice = e.Id
if err := rows.Scan(&m.Id, &m.IdExercice, &m.Title, &m.Kind); err != nil {
if err := rows.Scan(&m.Id, &m.IdExercice, &m.Title); err != nil {
return nil, err
}
@ -59,18 +58,18 @@ func (e Exercice) GetMCQ() ([]MCQ, error) {
}
}
func (e Exercice) AddMCQ(title string, kind string) (MCQ, error) {
if res, err := DBExec("INSERT INTO exercice_mcq (id_exercice, title, kind) VALUES (?, ?, ?)", e.Id, title, kind); err != nil {
func (e Exercice) AddMCQ(title string) (MCQ, error) {
if res, err := DBExec("INSERT INTO exercice_mcq (id_exercice, title) VALUES (?, ?)", e.Id, title); err != nil {
return MCQ{}, err
} else if qid, err := res.LastInsertId(); err != nil {
return MCQ{}, err
} else {
return MCQ{qid, e.Id, title, kind, []MCQ_entry{}}, nil
return MCQ{qid, e.Id, title, []MCQ_entry{}}, nil
}
}
func (m MCQ) Update() (int64, error) {
if res, err := DBExec("UPDATE exercice_mcq SET id_exercice = ?, title = ?, kind = ? WHERE id_mcq = ?", m.IdExercice, m.Title, m.Kind, m.Id); err != nil {
if res, err := DBExec("UPDATE exercice_mcq SET id_exercice = ?, title = ? WHERE id_mcq = ?", m.IdExercice, m.Title, m.Id); err != nil {
return 0, err
} else if nb, err := res.RowsAffected(); err != nil {
return 0, err