Able to check MCQ
This commit is contained in:
parent
037f27c62c
commit
6903c91df2
6 changed files with 79 additions and 13 deletions
|
@ -1,6 +1,7 @@
|
|||
package fic
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type MCQ struct {
|
||||
|
@ -32,13 +33,23 @@ func (e Exercice) GetMCQ() ([]MCQ, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if entries_rows, err := DBQuery("SELECT id_mcq, id_exercice, label, response FROM mcq_entries WHERE id_mcq = ?", m.Id); err != nil {
|
||||
if entries_rows, err := DBQuery("SELECT id_mcq_entry, label, response FROM mcq_entries WHERE id_mcq = ?", m.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer entries_rows.Close()
|
||||
|
||||
mcqs = append(mcqs, m)
|
||||
for entries_rows.Next() {
|
||||
var e MCQ_entry
|
||||
|
||||
if err := entries_rows.Scan(&e.Id, &e.Label, &e.Response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.Entries = append(m.Entries, e)
|
||||
}
|
||||
}
|
||||
|
||||
mcqs = append(mcqs, m)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
|
@ -110,6 +121,7 @@ func (n MCQ_entry) Delete() (int64, error) {
|
|||
|
||||
func (m MCQ) Check(vals map[int64]bool) int {
|
||||
diff := 0
|
||||
|
||||
for _, n := range m.Entries {
|
||||
if v, ok := vals[n.Id]; ok && v == n.Response {
|
||||
continue
|
||||
|
@ -119,3 +131,7 @@ func (m MCQ) Check(vals map[int64]bool) int {
|
|||
|
||||
return diff
|
||||
}
|
||||
|
||||
func (m MCQ) FoundBy(t Team) {
|
||||
DBExec("INSERT INTO mcq_found (id_mcq, id_team, time) VALUES (?, ?, ?)", m.Id, t.Id, time.Now())
|
||||
}
|
||||
|
|
Reference in a new issue