Hints can something else than text

This commit is contained in:
nemunaire 2017-01-05 02:21:32 +01:00
commit c2dea2f985
6 changed files with 69 additions and 25 deletions

View file

@ -1,6 +1,8 @@
package fic
import (
"path"
"strings"
)
type EHint struct {
@ -11,11 +13,18 @@ type EHint struct {
Cost int64 `json:"cost"`
}
func treatHintContent(content *string) {
if strings.HasPrefix(*content, "$FILES") {
*content = "$FILES" + path.Join(FilesDir, strings.TrimPrefix(*content, "$FILES"))
}
}
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
}
treatHintContent(&h.Content)
return h, nil
}
@ -33,6 +42,7 @@ func (e Exercice) GetHints() ([]EHint, error) {
if err := rows.Scan(&h.Id, &h.Title, &h.Content, &h.Cost); err != nil {
return nil, err
}
treatHintContent(&h.Content)
hints = append(hints, h)
}
if err := rows.Err(); err != nil {