WIP ping support
This commit is contained in:
parent
82f83e3d89
commit
792f6bbe25
2 changed files with 29 additions and 1 deletions
|
@ -88,11 +88,20 @@ CREATE TABLE IF NOT EXISTS student_challenges(
|
||||||
id_st INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
id_st INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
id_student INTEGER NOT NULL,
|
id_student INTEGER NOT NULL,
|
||||||
challenge INTEGER NOT NULL,
|
challenge INTEGER NOT NULL,
|
||||||
time TIMESTAMP NOT NULL,
|
time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
value VARCHAR(255) NOT NULL,
|
value VARCHAR(255) NOT NULL,
|
||||||
CONSTRAINT token_found UNIQUE (id_student,challenge),
|
CONSTRAINT token_found UNIQUE (id_student,challenge),
|
||||||
FOREIGN KEY(id_student) REFERENCES students(id_student)
|
FOREIGN KEY(id_student) REFERENCES students(id_student)
|
||||||
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_bin;
|
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_bin;
|
||||||
|
`); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := db.Exec(`
|
||||||
|
CREATE TABLE IF NOT EXISTS student_pong(
|
||||||
|
id_student INTEGER NOT NULL,
|
||||||
|
time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY(id_student) REFERENCES students(id_student)
|
||||||
|
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_bin;
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
19
token-validator/ping.go
Normal file
19
token-validator/ping.go
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
router.POST("/api/students/:sid/pong", apiHandler(studentHandler(stdPong), sslOnly))
|
||||||
|
}
|
||||||
|
|
||||||
|
func stdPong(student Student, body []byte) (interface{}, error) {
|
||||||
|
if res, err := DBExec("INSERT INTO student_pong (id_student, time) VALUES (?, ?)", student.Id, time.Now()); err != nil {
|
||||||
|
return false, err
|
||||||
|
} else if _, err := res.LastInsertId(); err != nil {
|
||||||
|
return false, err
|
||||||
|
} else {
|
||||||
|
return true, err
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue