Add authors in themes

This commit is contained in:
nemunaire 2016-01-23 12:21:02 +01:00
parent e628e7931c
commit 859dbc68cb
4 changed files with 24 additions and 17 deletions

View file

@ -3,12 +3,13 @@ package fic
import ()
type Theme struct {
Id int64 `json:"id"`
Name string `json:"name"`
Id int64 `json:"id"`
Name string `json:"name"`
Authors string `json:"authors"`
}
func GetThemes() ([]Theme, error) {
if rows, err := DBQuery("SELECT id_theme, name FROM themes"); err != nil {
if rows, err := DBQuery("SELECT id_theme, name, authors FROM themes"); err != nil {
return nil, err
} else {
defer rows.Close()
@ -16,7 +17,7 @@ func GetThemes() ([]Theme, error) {
var themes = make([]Theme, 0)
for rows.Next() {
var t Theme
if err := rows.Scan(&t.Id, &t.Name); err != nil {
if err := rows.Scan(&t.Id, &t.Name, &t.Authors); err != nil {
return nil, err
}
themes = append(themes, t)
@ -31,25 +32,25 @@ func GetThemes() ([]Theme, error) {
func GetTheme(id int) (Theme, error) {
var t Theme
if err := DBQueryRow("SELECT id_theme, name FROM themes WHERE id_theme=?", id).Scan(&t.Id, &t.Name); err != nil {
if err := DBQueryRow("SELECT id_theme, name, authors FROM themes WHERE id_theme=?", id).Scan(&t.Id, &t.Name, &t.Authors); err != nil {
return t, err
}
return t, nil
}
func CreateTheme(name string) (Theme, error) {
if res, err := DBExec("INSERT INTO themes (name) VALUES (?)", name); err != nil {
func CreateTheme(name string, authors string) (Theme, error) {
if res, err := DBExec("INSERT INTO themes (name, authors) VALUES (?, ?)", name, authors); err != nil {
return Theme{}, err
} else if tid, err := res.LastInsertId(); err != nil {
return Theme{}, err
} else {
return Theme{tid, name}, nil
return Theme{tid, name, authors}, nil
}
}
func (t Theme) Update() (int64, error) {
if res, err := DBExec("UPDATE themes SET name = ? WHERE id_theme = ?", t.Name, t.Id); err != nil {
if res, err := DBExec("UPDATE themes SET name = ?, authors = ? WHERE id_theme = ?", t.Name, t.Authors, t.Id); err != nil {
return 0, err
} else if nb, err := res.RowsAffected(); err != nil {
return 0, err