diff options
Diffstat (limited to 'modules/lists')
| -rw-r--r-- | modules/lists/lists.go | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/modules/lists/lists.go b/modules/lists/lists.go index 24d774e..343ba62 100644 --- a/modules/lists/lists.go +++ b/modules/lists/lists.go | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | package lists | 1 | package lists |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "database/sql" | ||
| 4 | "fagott.pw/charakterin" | 5 | "fagott.pw/charakterin" |
| 5 | "fagott.pw/grilist/frontend" | 6 | "fagott.pw/grilist/frontend" |
| 6 | "fagott.pw/grilist/grilist" | 7 | "fagott.pw/grilist/grilist" |
| @@ -90,17 +91,9 @@ func mkCard(title, description string, actions ...frontend.Action) frontend.Card | |||
| 90 | return card | 91 | return card |
| 91 | } | 92 | } |
| 92 | 93 | ||
| 93 | func (m *Module) ProvideDashboardData(user *charakterin.User) grilist.DashboardCategory { | 94 | func rowsToCard(rows *sql.Rows) []frontend.Card { |
| 94 | data := grilist.DashboardCategory{ | 95 | var cards []frontend.Card |
| 95 | Title: "Meine Listen", | ||
| 96 | } | ||
| 97 | |||
| 98 | rows, err := m.g.DB.Query(`SELECT id, name, description FROM grilist.lists WHERE user_id = $1`, user.ID) | ||
| 99 | if err != nil { | ||
| 100 | return data | ||
| 101 | } | ||
| 102 | 96 | ||
| 103 | defer rows.Close() | ||
| 104 | for rows.Next() { | 97 | for rows.Next() { |
| 105 | var id int | 98 | var id int |
| 106 | var title, description string | 99 | var title, description string |
| @@ -109,12 +102,45 @@ func (m *Module) ProvideDashboardData(user *charakterin.User) grilist.DashboardC | |||
| 109 | continue | 102 | continue |
| 110 | } | 103 | } |
| 111 | 104 | ||
| 112 | data.Cards = append(data.Cards, mkCard(title, description, frontend.Action{"anguckieren", fmt.Sprintf("/lists/%d", id)})) | 105 | cards = append(cards, mkCard(title, description, frontend.Action{"anguckieren", fmt.Sprintf("/lists/%d", id)})) |
| 113 | } | 106 | } |
| 107 | return cards | ||
| 108 | } | ||
| 109 | |||
| 110 | // ProvideDashboardData gibt Daten für das Dashboard bezogen auf den Benutzer zurück | ||
| 111 | func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { | ||
| 112 | var categories []grilist.DashboardCategory | ||
| 113 | |||
| 114 | // Listen des Benutzers | ||
| 115 | rows, err := m.g.DB.Query(`SELECT id, name, description FROM grilist.lists WHERE user_id = $1`, user.ID) | ||
| 116 | if err != nil { | ||
| 117 | log.Println(err) | ||
| 118 | return []grilist.DashboardCategory{} | ||
| 119 | } | ||
| 120 | defer rows.Close() | ||
| 121 | |||
| 122 | categories = append(categories, grilist.DashboardCategory{ | ||
| 123 | Title: "Meine Listen", | ||
| 124 | Cards: rowsToCard(rows), | ||
| 125 | }) | ||
| 126 | |||
| 127 | // Neue Listen | ||
| 128 | rows, err = m.g.DB.Query(`SELECT id, name, description FROM grilist.lists ORDER BY id DESC LIMIT 5`) | ||
| 129 | if err != nil { | ||
| 130 | log.Println(err) | ||
| 131 | return categories | ||
| 132 | } | ||
| 133 | defer rows.Close() | ||
| 134 | |||
| 135 | categories = append(categories, grilist.DashboardCategory{ | ||
| 136 | Title: "Neueste Listen", | ||
| 137 | Cards: rowsToCard(rows), | ||
| 138 | }) | ||
| 114 | 139 | ||
| 115 | return data | 140 | return categories |
| 116 | } | 141 | } |
| 117 | 142 | ||
| 143 | // New erstellt eine neue Instanz des Modules | ||
| 118 | func New() *Module { | 144 | func New() *Module { |
| 119 | return &Module{} | 145 | return &Module{} |
| 120 | } | 146 | } |
