token-validator: include ping in progression
This commit is contained in:
parent
c08853fd36
commit
0a50ad9346
1 changed files with 17 additions and 6 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
router.GET("/api/progress/", apiHandler(
|
router.GET("/api/progress", apiHandler(
|
||||||
func(httprouter.Params, []byte) (interface{}, error) {
|
func(httprouter.Params, []byte) (interface{}, error) {
|
||||||
if stds, err := getStudents(); err != nil {
|
if stds, err := getStudents(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -25,6 +26,16 @@ func init() {
|
||||||
for _, s := range sts {
|
for _, s := range sts {
|
||||||
ret[std.Login][fmt.Sprintf("%d", s.Challenge)] = s
|
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
|
return ret, nil
|
||||||
|
@ -187,11 +198,11 @@ func updateStudent(current Student, body []byte) (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type UnlockedChallenge struct {
|
type UnlockedChallenge struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id,omitempty"`
|
||||||
IdStudent int64 `json:"id_student"`
|
IdStudent int64 `json:"id_student"`
|
||||||
Challenge int `json:"challenge"`
|
Challenge int `json:"challenge,omitempty"`
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
Value string `json:"value,omitempty"`
|
Value interface{} `json:"value,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Student) getStates() (ucs []UnlockedChallenge, err error) {
|
func (s Student) getStates() (ucs []UnlockedChallenge, err error) {
|
||||||
|
|
Reference in a new issue