aboutsummaryrefslogtreecommitdiff
path: root/modules/lists
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2015-12-22 18:01:08 (UTC)
committerjan <jan@ruken.pw>2015-12-22 18:01:08 (UTC)
commitf239fc2678f2f4e458cf10a4ab30d54acc5b92c2 (patch)
tree059c8593e91257eeb39a049a7b8e47df8ba4638d /modules/lists
parent50d50d37809fef22b08c0b260302a5e96ad35694 (diff)
mehr cleanup, neue Listen anzeigen auf dem Dashboard
Diffstat (limited to 'modules/lists')
-rw-r--r--modules/lists/lists.go50
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 @@
1package lists 1package lists
2 2
3import ( 3import (
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
93func (m *Module) ProvideDashboardData(user *charakterin.User) grilist.DashboardCategory { 94func 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
111func (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
118func New() *Module { 144func New() *Module {
119 return &Module{} 145 return &Module{}
120} 146}