backend: can open hint

This commit is contained in:
nemunaire 2016-12-09 11:49:29 +01:00
commit 4b20c1dc1e
4 changed files with 52 additions and 0 deletions

View file

@ -11,6 +11,15 @@ type EHint struct {
Cost int64 `json:"cost"`
}
func GetHint(id int64) (EHint, error) {
var h EHint
if err := DBQueryRow("SELECT id_hint, id_exercice, title, content, cost FROM exercice_hints WHERE id_hint = ?", id).Scan(&h.Id, &h.IdExercice, &h.Title, &h.Content, &h.Cost); err != nil {
return h, err
}
return h, nil
}
func (e Exercice) GetHints() ([]EHint, error) {
if rows, err := DBQuery("SELECT id_hint, title, content, cost FROM exercice_hints WHERE id_exercice = ?", e.Id); err != nil {
return nil, err

View file

@ -216,6 +216,11 @@ func (t Team) HasHint(h EHint) (bool) {
return tm != nil
}
func (t Team) OpenHint(h EHint) (error) {
_, err := DBExec("INSERT INTO team_hints (id_team, id_hint, time) VALUES (?, ?, ?)", t.Id, h.Id, time.Now())
return err
}
func (t Team) HasSolved(e Exercice) (bool, time.Time, int64) {
var nb *int64
var tm *time.Time