HasSolved now returns a tuple (bool, Time, int)
This commit is contained in:
parent
c33c2b8e8a
commit
381aefa597
|
@ -134,7 +134,8 @@ func (e Exercice) Solved(t Team) error {
|
|||
}
|
||||
|
||||
func (e Exercice) CheckResponse(response string, t Team) (bool, error) {
|
||||
if t.HasSolved(e) {
|
||||
s, _, _ := t.HasSolved(e)
|
||||
if s {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@ import (
|
|||
)
|
||||
|
||||
type Key struct {
|
||||
Id int64 `json:"id"`
|
||||
IdExercice int64 `json:"idExercice"`
|
||||
Type string `json:"type"`
|
||||
Value []byte `json:"value"`
|
||||
Id int64 `json:"id"`
|
||||
IdExercice int64 `json:"idExercice"`
|
||||
Type string `json:"type"`
|
||||
Value []byte `json:"value"`
|
||||
}
|
||||
|
||||
func (e Exercice) GetKeys() ([]Key, error) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package fic
|
||||
|
||||
import ()
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Team struct {
|
||||
Id int64 `json:"id"`
|
||||
|
@ -74,15 +76,19 @@ func (t Team) HasAccess(e Exercice) bool {
|
|||
} else {
|
||||
ed := Exercice{}
|
||||
ed.Id = *e.Depend
|
||||
return t.HasSolved(ed)
|
||||
s, _, _ := t.HasSolved(ed)
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
func (t Team) HasSolved(e Exercice) bool {
|
||||
var nb int
|
||||
if err := DBQueryRow("SELECT COUNT(id_exercice) FROM exercice_solved WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&nb); err != nil {
|
||||
return false
|
||||
func (t Team) HasSolved(e Exercice) (bool, time.Time, int64) {
|
||||
var nb int64
|
||||
var tm time.Time
|
||||
if err := DBQueryRow("SELECT time FROM exercice_solved WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&tm); err != nil {
|
||||
return false, time.Now(), 0
|
||||
} else if err := DBQueryRow("SELECT COUNT(id_exercice) FROM exercice_solved WHERE id_exercice = ? AND time < ?", e.Id, tm).Scan(&nb); err != nil {
|
||||
return true, tm, 0
|
||||
} else {
|
||||
return nb > 0
|
||||
return true, tm, nb
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue