sync: Extract function that builds a theme from importer
This commit is contained in:
parent
536dc0eb6b
commit
682598fdbb
3 changed files with 87 additions and 74 deletions
|
|
@ -14,6 +14,11 @@ type Theme struct {
|
|||
Image string `json:"image,omitempty"`
|
||||
}
|
||||
|
||||
// CmpTheme returns true if given Themes are identicals.
|
||||
func CmpTheme(t1 Theme, t2 Theme) bool {
|
||||
return !(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)
|
||||
}
|
||||
|
||||
// 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, headline, image FROM themes"); err != nil {
|
||||
|
|
@ -58,13 +63,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, 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 {
|
||||
func CreateTheme(theme Theme) (Theme, error) {
|
||||
if res, err := DBExec("INSERT INTO themes (name, url_id, authors, path, intro, headline, image) VALUES (?, ?, ?, ?, ?, ?, ?)", theme.Name, theme.URLId, theme.Authors, theme.Path, theme.Intro, theme.Headline, theme.Image); err != nil {
|
||||
return Theme{}, err
|
||||
} else if tid, err := res.LastInsertId(); err != nil {
|
||||
} else if theme.Id, err = res.LastInsertId(); err != nil {
|
||||
return Theme{}, err
|
||||
} else {
|
||||
return Theme{tid, name, url_id, path, authors, intro, headline, image}, nil
|
||||
return theme, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue