this is tuto1

This commit is contained in:
nemunaire 2019-03-04 09:00:22 +01:00
parent 9eaa2bf4e8
commit 9262917553
19 changed files with 928 additions and 68 deletions

View file

@ -44,6 +44,18 @@ func init() {
func(std Student, _ []byte) (interface{}, error) {
return std.Delete()
}))))
router.GET("/api/students/:sid/progress", apiHandler(studentHandler(
func(std Student, _ []byte) (interface{}, error) {
ret := map[string]UnlockedChallenge{}
if sts, err := std.getStates(); err == nil {
for _, s := range sts {
ret[fmt.Sprintf("%d", s.Challenge)] = s
}
}
return ret, nil
})))
}
type Student struct {
@ -61,7 +73,7 @@ type uploadedStudent struct {
}
func getStudents() (students []Student, err error) {
if rows, errr := DBQuery("SELECT S.id_student, S.login, MAX(L.time), L.ip, L.mac FROM students S INNER JOIN (SELECT a.id_student, a.time, a.ip, a.mac FROM student_login a INNER JOIN (SELECT id_student, MAX(time) AS time FROM student_login GROUP BY id_student) b ON a.id_student = b.id_student AND a.time = b.time) L ON S.id_student = L.id_student"); errr != nil {
if rows, errr := DBQuery("SELECT S.id_student, S.login, MAX(L.time), L.ip, L.mac FROM students S INNER JOIN (SELECT a.id_student, a.time, a.ip, a.mac FROM student_login a INNER JOIN (SELECT id_student, MAX(time) AS time FROM student_login GROUP BY id_student) b ON a.id_student = b.id_student AND a.time = b.time) L ON S.id_student = L.id_student GROUP BY id_student"); errr != nil {
return nil, errr
} else {
defer rows.Close()