# HG changeset patch # User Sascha L. Teichmann # Date 1550156702 -3600 # Node ID 1c8b8a4476af1b211adb9e1c798a76e0ebd8281c # Parent dfa4db82e78496b8d711833cead6d2192c88db8b Print templates: Add country to listing if template has one. diff -r dfa4db82e784 -r 1c8b8a4476af pkg/controllers/printtemplates.go --- a/pkg/controllers/printtemplates.go Thu Feb 14 15:42:35 2019 +0100 +++ b/pkg/controllers/printtemplates.go Thu Feb 14 16:05:02 2019 +0100 @@ -32,7 +32,8 @@ listPrintTemplatesSQL = ` SELECT template_name, - date_info + date_info, + country FROM users.templates ORDER BY date_info DESC` @@ -66,8 +67,9 @@ ) (jr JSONResult, err error) { type template struct { - Name string `json:"name"` - Time models.Time `json:"time"` + Name string `json:"name"` + Time models.Time `json:"time"` + Country *string `json:"country,omitempty"` } var rows *sql.Rows @@ -81,10 +83,14 @@ for rows.Next() { var tmpl template var w time.Time - if err = rows.Scan(&tmpl.Name, &w); err != nil { + var country sql.NullString + if err = rows.Scan(&tmpl.Name, &w, &country); err != nil { return } tmpl.Time = models.Time{w} + if country.Valid { + tmpl.Country = &country.String + } templates = append(templates, &tmpl) }