admin/sync: import theme introductions
This commit is contained in:
parent
39b57119fe
commit
ea3f3b709d
4 changed files with 34 additions and 22 deletions
|
@ -7,11 +7,12 @@ import (
|
|||
type Theme struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Authors string `json:"authors"`
|
||||
Authors string `json:"authors,omitempty"`
|
||||
Intro string `json:"intro,omitempty"`
|
||||
}
|
||||
|
||||
func GetThemes() ([]Theme, error) {
|
||||
if rows, err := DBQuery("SELECT id_theme, name, authors FROM themes"); err != nil {
|
||||
if rows, err := DBQuery("SELECT id_theme, name, authors, intro FROM themes"); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
@ -19,7 +20,7 @@ func GetThemes() ([]Theme, error) {
|
|||
var themes = make([]Theme, 0)
|
||||
for rows.Next() {
|
||||
var t Theme
|
||||
if err := rows.Scan(&t.Id, &t.Name, &t.Authors); err != nil {
|
||||
if err := rows.Scan(&t.Id, &t.Name, &t.Authors, &t.Intro); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
themes = append(themes, t)
|
||||
|
@ -34,7 +35,7 @@ func GetThemes() ([]Theme, error) {
|
|||
|
||||
func GetTheme(id int) (Theme, error) {
|
||||
var t Theme
|
||||
if err := DBQueryRow("SELECT id_theme, name, authors FROM themes WHERE id_theme=?", id).Scan(&t.Id, &t.Name, &t.Authors); err != nil {
|
||||
if err := DBQueryRow("SELECT id_theme, name, authors, intro FROM themes WHERE id_theme=?", id).Scan(&t.Id, &t.Name, &t.Authors, &t.Intro); err != nil {
|
||||
return t, err
|
||||
}
|
||||
|
||||
|
@ -43,25 +44,25 @@ func GetTheme(id int) (Theme, error) {
|
|||
|
||||
func GetThemeByName(name string) (Theme, error) {
|
||||
var t Theme
|
||||
if err := DBQueryRow("SELECT id_theme, name, authors FROM themes WHERE name=?", name).Scan(&t.Id, &t.Name, &t.Authors); err != nil {
|
||||
if err := DBQueryRow("SELECT id_theme, name, authors, intro FROM themes WHERE name=?", name).Scan(&t.Id, &t.Name, &t.Authors, &t.Intro); err != nil {
|
||||
return t, err
|
||||
}
|
||||
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func CreateTheme(name string, authors string) (Theme, error) {
|
||||
if res, err := DBExec("INSERT INTO themes (name, authors) VALUES (?, ?)", name, authors); err != nil {
|
||||
func CreateTheme(name string, authors string, intro string) (Theme, error) {
|
||||
if res, err := DBExec("INSERT INTO themes (name, authors, intro) VALUES (?, ?, ?)", name, authors, intro); err != nil {
|
||||
return Theme{}, err
|
||||
} else if tid, err := res.LastInsertId(); err != nil {
|
||||
return Theme{}, err
|
||||
} else {
|
||||
return Theme{tid, name, authors}, nil
|
||||
return Theme{tid, name, authors, intro}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t Theme) Update() (int64, error) {
|
||||
if res, err := DBExec("UPDATE themes SET name = ?, authors = ? WHERE id_theme = ?", t.Name, t.Authors, t.Id); err != nil {
|
||||
if res, err := DBExec("UPDATE themes SET name = ?, authors = ?, intro = ? WHERE id_theme = ?", t.Name, t.Authors, t.Intro, t.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
@ -91,6 +92,7 @@ type ExportedExercice struct {
|
|||
type exportedTheme struct {
|
||||
Name string `json:"name"`
|
||||
Authors string `json:"authors"`
|
||||
Intro string `json:"intro"`
|
||||
Exercices map[string]ExportedExercice `json:"exercices"`
|
||||
}
|
||||
|
||||
|
@ -116,6 +118,7 @@ func ExportThemes() (interface{}, error) {
|
|||
ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{
|
||||
theme.Name,
|
||||
theme.Authors,
|
||||
theme.Intro,
|
||||
exos,
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue