split checker from token-validator

This commit is contained in:
nemunaire 2020-03-27 14:57:14 +01:00
commit 0c661f36f6
20 changed files with 634 additions and 748 deletions

36
libadlin/ping.go Normal file
View file

@ -0,0 +1,36 @@
package adlin
import (
"time"
)
type Pong struct {
Date time.Time
State bool
}
func (s Student) LastPongs() (pongs []Pong, err error) {
if rows, errr := DBQuery("SELECT time, state FROM student_pong WHERE id_student = ? ORDER BY time DESC", s.Id); errr != nil {
return nil, errr
} else {
defer rows.Close()
for rows.Next() {
var p Pong
if err = rows.Scan(&p.Date, &p.State); err != nil {
return
}
pongs = append(pongs, p)
}
if err = rows.Err(); err != nil {
return
}
return
}
}
func (s *Student) OnPong(state bool) (err error) {
_, err = DBExec("INSERT INTO student_pong (id_student, time, state) VALUES (?, ?, ?)", s.Id, time.Now(), state)
return
}