frontend: dedicate a field in JSON to file hint

This commit is contained in:
nemunaire 2017-01-14 15:03:25 +01:00
parent b772a22705
commit 21e4b04c19
3 changed files with 28 additions and 28 deletions

View file

@ -6,16 +6,18 @@ import (
)
type EHint struct {
Id int64 `json:"id"`
IdExercice int64 `json:"idExercice"`
Title string `json:"title"`
Id int64 `json:"id"`
IdExercice int64 `json:"idExercice"`
Title string `json:"title"`
Content string `json:"content"`
Cost int64 `json:"cost"`
File string `json:"file"`
Cost int64 `json:"cost"`
}
func treatHintContent(content *string) {
if strings.HasPrefix(*content, "$FILES") {
*content = "$FILES" + path.Join(FilesDir, strings.TrimPrefix(*content, "$FILES"))
func treatHintContent(h *EHint) {
if strings.HasPrefix(h.Content, "$FILES") {
h.File = path.Join(FilesDir, strings.TrimPrefix(h.Content, "$FILES"))
h.Content = ""
}
}
@ -24,7 +26,7 @@ func GetHint(id int64) (EHint, error) {
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)
treatHintContent(&h)
return h, nil
}
@ -42,7 +44,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)
treatHintContent(&h)
hints = append(hints, h)
}
if err := rows.Err(); err != nil {
@ -59,7 +61,7 @@ func (e Exercice) AddHint(title string, content string, cost int64) (EHint, erro
} else if hid, err := res.LastInsertId(); err != nil {
return EHint{}, err
} else {
return EHint{hid, e.Id, title, content, cost}, nil
return EHint{hid, e.Id, title, content, "", cost}, nil
}
}