token-validator: include ping in progression

This commit is contained in:
nemunaire 2020-02-27 15:26:57 +01:00
parent c08853fd36
commit 0a50ad9346

View file

@ -5,6 +5,7 @@ import (
"crypto/sha512"
"encoding/json"
"fmt"
"log"
"strings"
"time"
@ -12,7 +13,7 @@ import (
)
func init() {
router.GET("/api/progress/", apiHandler(
router.GET("/api/progress", apiHandler(
func(httprouter.Params, []byte) (interface{}, error) {
if stds, err := getStudents(); err != nil {
return nil, err
@ -25,6 +26,16 @@ func init() {
for _, s := range sts {
ret[std.Login][fmt.Sprintf("%d", s.Challenge)] = s
}
if pongs, err := std.lastPongs(); err == nil && len(pongs) > 0 {
ret[std.Login]["ping"] = UnlockedChallenge{
IdStudent: std.Id,
Time: pongs[0].Date,
Value: pongs[0].State,
}
} else if err != nil {
log.Println(err)
}
}
}
return ret, nil
@ -187,11 +198,11 @@ func updateStudent(current Student, body []byte) (interface{}, error) {
}
type UnlockedChallenge struct {
Id int64 `json:"id"`
Id int64 `json:"id,omitempty"`
IdStudent int64 `json:"id_student"`
Challenge int `json:"challenge"`
Challenge int `json:"challenge,omitempty"`
Time time.Time `json:"time"`
Value string `json:"value,omitempty"`
Value interface{} `json:"value,omitempty"`
}
func (s Student) getStates() (ucs []UnlockedChallenge, err error) {