Implement and display headlines in interface
This commit is contained in:
parent
abd7fc6bef
commit
8c95782eff
13 changed files with 85 additions and 58 deletions
|
@ -4,18 +4,19 @@ import ()
|
|||
|
||||
// Theme represents a group of challenges, to display to players
|
||||
type Theme struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
URLId string `json:"urlid"`
|
||||
Path string `json:"path"`
|
||||
Authors string `json:"authors,omitempty"`
|
||||
Intro string `json:"intro,omitempty"`
|
||||
Image string `json:"image,omitempty"`
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
URLId string `json:"urlid"`
|
||||
Path string `json:"path"`
|
||||
Authors string `json:"authors,omitempty"`
|
||||
Intro string `json:"intro,omitempty"`
|
||||
Headline string `json:"headline,omitempty"`
|
||||
Image string `json:"image,omitempty"`
|
||||
}
|
||||
|
||||
// GetThemes returns a list of registered Themes from the database.
|
||||
func GetThemes() ([]Theme, error) {
|
||||
if rows, err := DBQuery("SELECT id_theme, name, url_id, path, authors, intro, image FROM themes"); err != nil {
|
||||
if rows, err := DBQuery("SELECT id_theme, name, url_id, path, authors, intro, headline, image FROM themes"); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
@ -23,7 +24,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.URLId, &t.Path, &t.Authors, &t.Intro, &t.Image); err != nil {
|
||||
if err := rows.Scan(&t.Id, &t.Name, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Headline, &t.Image); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
themes = append(themes, t)
|
||||
|
@ -39,7 +40,7 @@ func GetThemes() ([]Theme, error) {
|
|||
// GetTheme retrieves a Theme from its identifier.
|
||||
func GetTheme(id int64) (Theme, error) {
|
||||
var t Theme
|
||||
if err := DBQueryRow("SELECT id_theme, name, url_id, path, authors, intro, image FROM themes WHERE id_theme=?", id).Scan(&t.Id, &t.Name, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Image); err != nil {
|
||||
if err := DBQueryRow("SELECT id_theme, name, url_id, path, authors, intro, headline, image FROM themes WHERE id_theme=?", id).Scan(&t.Id, &t.Name, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Headline, &t.Image); err != nil {
|
||||
return t, err
|
||||
}
|
||||
|
||||
|
@ -49,7 +50,7 @@ func GetTheme(id int64) (Theme, error) {
|
|||
// GetThemeByName retrieves a Theme from its title
|
||||
func GetThemeByName(name string) (Theme, error) {
|
||||
var t Theme
|
||||
if err := DBQueryRow("SELECT id_theme, name, url_id, path, authors, intro, image FROM themes WHERE name=?", name).Scan(&t.Id, &t.Name, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Image); err != nil {
|
||||
if err := DBQueryRow("SELECT id_theme, name, url_id, path, authors, intro, headline, image FROM themes WHERE name=?", name).Scan(&t.Id, &t.Name, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Headline, &t.Image); err != nil {
|
||||
return t, err
|
||||
}
|
||||
|
||||
|
@ -57,13 +58,13 @@ func GetThemeByName(name string) (Theme, error) {
|
|||
}
|
||||
|
||||
// CreateTheme creates and fills a new struct Theme and registers it into the database.
|
||||
func CreateTheme(name string, url_id string, path string, authors string, intro string, image string) (Theme, error) {
|
||||
if res, err := DBExec("INSERT INTO themes (name, url_id, authors, path, intro, image) VALUES (?, ?, ?, ?, ?, ?)", name, url_id, authors, path, intro, image); err != nil {
|
||||
func CreateTheme(name string, url_id string, path string, authors string, intro string, headline string, image string) (Theme, error) {
|
||||
if res, err := DBExec("INSERT INTO themes (name, url_id, authors, path, intro, headline, image) VALUES (?, ?, ?, ?, ?, ?, ?)", name, url_id, authors, path, intro, headline, image); err != nil {
|
||||
return Theme{}, err
|
||||
} else if tid, err := res.LastInsertId(); err != nil {
|
||||
return Theme{}, err
|
||||
} else {
|
||||
return Theme{tid, name, url_id, path, authors, intro, image}, nil
|
||||
return Theme{tid, name, url_id, path, authors, intro, headline, image}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +80,7 @@ func (t *Theme) FixURLId() bool {
|
|||
|
||||
// Update applies modifications back to the database.
|
||||
func (t Theme) Update() (int64, error) {
|
||||
if res, err := DBExec("UPDATE themes SET name = ?, url_id = ?, authors = ?, path = ?, intro = ?, image = ? WHERE id_theme = ?", t.Name, t.URLId, t.Authors, t.Path, t.Intro, t.Image, t.Id); err != nil {
|
||||
if res, err := DBExec("UPDATE themes SET name = ?, url_id = ?, authors = ?, path = ?, intro = ?, headline = ?, image = ? WHERE id_theme = ?", t.Name, t.URLId, t.Authors, t.Path, t.Intro, t.Headline, t.Image, t.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
|
Reference in a new issue