Extract background color to continue image
This commit is contained in:
parent
35d07c1aa4
commit
26c282138e
23 changed files with 218 additions and 115 deletions
|
|
@ -4,19 +4,20 @@ import ()
|
|||
|
||||
// Theme represents a group of challenges, to display to players
|
||||
type Theme struct {
|
||||
Id int64 `json:"id"`
|
||||
Language string `json:"lang,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Locked bool `json:"locked"`
|
||||
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"`
|
||||
PartnerImage string `json:"partner_img,omitempty"`
|
||||
PartnerLink string `json:"partner_href,omitempty"`
|
||||
PartnerText string `json:"partner_txt,omitempty"`
|
||||
Id int64 `json:"id"`
|
||||
Language string `json:"lang,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Locked bool `json:"locked"`
|
||||
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"`
|
||||
BackgroundColor uint32 `json:"background_color,omitempty"`
|
||||
PartnerImage string `json:"partner_img,omitempty"`
|
||||
PartnerLink string `json:"partner_href,omitempty"`
|
||||
PartnerText string `json:"partner_txt,omitempty"`
|
||||
}
|
||||
|
||||
func (t *Theme) GetId() *int64 {
|
||||
|
|
@ -29,12 +30,12 @@ func (t *Theme) GetId() *int64 {
|
|||
|
||||
// CmpTheme returns true if given Themes are identicals.
|
||||
func CmpTheme(t1 *Theme, t2 *Theme) bool {
|
||||
return t1 != nil && t2 != nil && !(t1.Name != t2.Name || t1.URLId != t2.URLId || t1.Path != t2.Path || t1.Authors != t2.Authors || t1.Intro != t2.Intro || t1.Headline != t2.Headline || t1.Image != t2.Image || t1.PartnerImage != t2.PartnerImage || t1.PartnerLink != t2.PartnerLink || t1.PartnerText != t2.PartnerText)
|
||||
return t1 != nil && t2 != nil && !(t1.Name != t2.Name || t1.URLId != t2.URLId || t1.Path != t2.Path || t1.Authors != t2.Authors || t1.Intro != t2.Intro || t1.Headline != t2.Headline || t1.Image != t2.Image || t1.BackgroundColor != t2.BackgroundColor || t1.PartnerImage != t2.PartnerImage || t1.PartnerLink != t2.PartnerLink || t1.PartnerText != t2.PartnerText)
|
||||
}
|
||||
|
||||
// GetThemes returns a list of registered Themes from the database.
|
||||
func GetThemes() ([]*Theme, error) {
|
||||
if rows, err := DBQuery("SELECT id_theme, name, locked, url_id, path, authors, intro, headline, image, partner_img, partner_href, partner_text FROM themes"); err != nil {
|
||||
if rows, err := DBQuery("SELECT id_theme, name, locked, url_id, path, authors, intro, headline, image, background_color, partner_img, partner_href, partner_text FROM themes"); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
|
@ -42,7 +43,7 @@ func GetThemes() ([]*Theme, error) {
|
|||
var themes []*Theme
|
||||
for rows.Next() {
|
||||
t := &Theme{}
|
||||
if err := rows.Scan(&t.Id, &t.Name, &t.Locked, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Headline, &t.Image, &t.PartnerImage, &t.PartnerLink, &t.PartnerText); err != nil {
|
||||
if err := rows.Scan(&t.Id, &t.Name, &t.Locked, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Headline, &t.Image, &t.BackgroundColor, &t.PartnerImage, &t.PartnerLink, &t.PartnerText); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
themes = append(themes, t)
|
||||
|
|
@ -58,7 +59,7 @@ func GetThemes() ([]*Theme, error) {
|
|||
// GetTheme retrieves a Theme from its identifier.
|
||||
func GetTheme(id int64) (*Theme, error) {
|
||||
t := &Theme{}
|
||||
if err := DBQueryRow("SELECT id_theme, name, locked, url_id, path, authors, intro, headline, image, partner_img, partner_href, partner_text FROM themes WHERE id_theme=?", id).Scan(&t.Id, &t.Name, &t.Locked, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Headline, &t.Image, &t.PartnerImage, &t.PartnerLink, &t.PartnerText); err != nil {
|
||||
if err := DBQueryRow("SELECT id_theme, name, locked, url_id, path, authors, intro, headline, image, background_color, partner_img, partner_href, partner_text FROM themes WHERE id_theme=?", id).Scan(&t.Id, &t.Name, &t.Locked, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Headline, &t.Image, &t.BackgroundColor, &t.PartnerImage, &t.PartnerLink, &t.PartnerText); err != nil {
|
||||
return t, err
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +69,7 @@ func GetTheme(id int64) (*Theme, error) {
|
|||
// GetTheme retrieves a Theme from an given Exercice.
|
||||
func (e *Exercice) GetTheme() (*Theme, error) {
|
||||
t := &Theme{}
|
||||
if err := DBQueryRow("SELECT id_theme, name, locked, url_id, path, authors, intro, headline, image, partner_img, partner_href, partner_text FROM themes WHERE id_theme=?", e.IdTheme).Scan(&t.Id, &t.Name, &t.Locked, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Headline, &t.Image, &t.PartnerImage, &t.PartnerLink, &t.PartnerText); err != nil {
|
||||
if err := DBQueryRow("SELECT id_theme, name, locked, url_id, path, authors, intro, headline, image, background_color, partner_img, partner_href, partner_text FROM themes WHERE id_theme=?", e.IdTheme).Scan(&t.Id, &t.Name, &t.Locked, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Headline, &t.Image, &t.BackgroundColor, &t.PartnerImage, &t.PartnerLink, &t.PartnerText); err != nil {
|
||||
return t, err
|
||||
}
|
||||
|
||||
|
|
@ -78,7 +79,7 @@ func (e *Exercice) GetTheme() (*Theme, error) {
|
|||
// GetThemeByName retrieves a Theme from its title
|
||||
func GetThemeByName(name string) (*Theme, error) {
|
||||
t := &Theme{}
|
||||
if err := DBQueryRow("SELECT id_theme, name, locked, url_id, path, authors, intro, headline, image, partner_img, partner_text FROM themes WHERE name=?", name).Scan(&t.Id, &t.Name, &t.Locked, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Headline, &t.Image, &t.PartnerImage, &t.PartnerText); err != nil {
|
||||
if err := DBQueryRow("SELECT id_theme, name, locked, url_id, path, authors, intro, headline, image, background_color, partner_img, partner_text FROM themes WHERE name=?", name).Scan(&t.Id, &t.Name, &t.Locked, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Headline, &t.Image, &t.BackgroundColor, &t.PartnerImage, &t.PartnerText); err != nil {
|
||||
return t, err
|
||||
}
|
||||
|
||||
|
|
@ -88,14 +89,14 @@ func GetThemeByName(name string) (*Theme, error) {
|
|||
// GetThemeByPath retrieves a Theme from its dirname
|
||||
func GetThemeByPath(dirname string) (*Theme, error) {
|
||||
t := &Theme{}
|
||||
err := DBQueryRow("SELECT id_theme, name, locked, url_id, path, authors, intro, headline, image, partner_img, partner_href, partner_text FROM themes WHERE path=?", dirname).Scan(&t.Id, &t.Name, &t.Locked, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Headline, &t.Image, &t.PartnerImage, &t.PartnerLink, &t.PartnerText)
|
||||
err := DBQueryRow("SELECT id_theme, name, locked, url_id, path, authors, intro, headline, image, background_color, partner_img, partner_href, partner_text FROM themes WHERE path=?", dirname).Scan(&t.Id, &t.Name, &t.Locked, &t.URLId, &t.Path, &t.Authors, &t.Intro, &t.Headline, &t.Image, &t.BackgroundColor, &t.PartnerImage, &t.PartnerLink, &t.PartnerText)
|
||||
|
||||
return t, err
|
||||
}
|
||||
|
||||
// CreateTheme creates and fills a new struct Theme and registers it into the database.
|
||||
func CreateTheme(theme *Theme) (*Theme, error) {
|
||||
if res, err := DBExec("INSERT INTO themes (name, locked, url_id, authors, path, intro, headline, image, partner_img, partner_href, partner_text) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", theme.Name, theme.Locked, theme.URLId, theme.Authors, theme.Path, theme.Intro, theme.Headline, theme.Image, theme.PartnerImage, theme.PartnerLink, theme.PartnerText); err != nil {
|
||||
if res, err := DBExec("INSERT INTO themes (name, locked, url_id, authors, path, intro, headline, image, background_color, partner_img, partner_href, partner_text) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", theme.Name, theme.Locked, theme.URLId, theme.Authors, theme.Path, theme.Intro, theme.Headline, theme.Image, theme.BackgroundColor, theme.PartnerImage, theme.PartnerLink, theme.PartnerText); err != nil {
|
||||
return nil, err
|
||||
} else if theme.Id, err = res.LastInsertId(); err != nil {
|
||||
return nil, err
|
||||
|
|
@ -116,7 +117,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 = ?, locked = ?, url_id = ?, authors = ?, path = ?, intro = ?, headline = ?, image = ?, partner_img = ?, partner_href = ?, partner_text = ? WHERE id_theme = ?", t.Name, t.Locked, t.URLId, t.Authors, t.Path, t.Intro, t.Headline, t.Image, t.PartnerImage, t.PartnerLink, t.PartnerText, t.Id); err != nil {
|
||||
if res, err := DBExec("UPDATE themes SET name = ?, locked = ?, url_id = ?, authors = ?, path = ?, intro = ?, headline = ?, image = ?, background_color = ?, partner_img = ?, partner_href = ?, partner_text = ? WHERE id_theme = ?", t.Name, t.Locked, t.URLId, t.Authors, t.Path, t.Intro, t.Headline, t.Image, t.BackgroundColor, t.PartnerImage, t.PartnerLink, t.PartnerText, t.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
|
|
|||
Reference in a new issue