token-validator: existing student is not a case of failure
This commit is contained in:
parent
6bcc445691
commit
f3249cc9ed
1 changed files with 11 additions and 1 deletions
|
@ -64,6 +64,12 @@ func getStudentByLogin(login string) (s Student, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func studentExists(login string) bool {
|
||||||
|
var z int
|
||||||
|
err := DBQueryRow("SELECT 1 FROM students WHERE login=?", login).Scan(&z)
|
||||||
|
return err != nil && z == 1
|
||||||
|
}
|
||||||
|
|
||||||
func NewStudent(login string) (Student, error) {
|
func NewStudent(login string) (Student, error) {
|
||||||
if res, err := DBExec("INSERT INTO students (login, time) VALUES (?, ?)", login, time.Now()); err != nil {
|
if res, err := DBExec("INSERT INTO students (login, time) VALUES (?, ?)", login, time.Now()); err != nil {
|
||||||
return Student{}, err
|
return Student{}, err
|
||||||
|
@ -114,7 +120,11 @@ func createStudent(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if exist, err := getStudentByLogin(strings.TrimSpace(std.Login)); err != nil {
|
||||||
return NewStudent(strings.TrimSpace(std.Login))
|
return NewStudent(strings.TrimSpace(std.Login))
|
||||||
|
} else {
|
||||||
|
return exist, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateStudent(current Student, body []byte) (interface{}, error) {
|
func updateStudent(current Student, body []byte) (interface{}, error) {
|
||||||
|
|
Reference in a new issue