Change HasSolved behaviour: now return last try if not solved

This commit is contained in:
nemunaire 2016-01-21 05:33:40 +01:00
parent e30afad3d2
commit 8465f442c6
1 changed files with 11 additions and 6 deletions

View File

@ -120,12 +120,17 @@ func (t Team) HasAccess(e Exercice) bool {
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.Unix()).Scan(&nb); err != nil {
return true, tm, 0
var tm int64
var mt *time.Time
if DBQueryRow("SELECT MIN(time) FROM exercice_solved WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&mt); mt == nil {
if err := DBQueryRow("SELECT COUNT(id_exercice), MAX(time) FROM exercice_tries WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&nb, &mt); err != nil {
return false, time.Unix(0, 0), 0
} else {
return false, *mt, nb
}
} 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, time.Unix(tm, 0), 0
} else {
return true, tm, nb + 1
return true, time.Unix(tm, 0), nb + 1
}
}