aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/grils/grils.go10
-rw-r--r--modules/lists/lists.go50
2 files changed, 43 insertions, 17 deletions
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index 6ce7c5e..fa1f21c 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -6,7 +6,7 @@ import (
6) 6)
7 7
8type GrilsModule struct { 8type GrilsModule struct {
9 g *grilist.Grilist 9 g *grilist.Grilist
10 Test []int 10 Test []int
11} 11}
12 12
@@ -16,16 +16,16 @@ func (m *GrilsModule) Name() string {
16 16
17func (m *GrilsModule) Init(g *grilist.Grilist) { 17func (m *GrilsModule) Init(g *grilist.Grilist) {
18 m.g = g 18 m.g = g
19 m.Test = append(m.Test, len(m.Test) + 1) 19 m.Test = append(m.Test, len(m.Test)+1)
20} 20}
21 21
22func (m *GrilsModule) Interface() interface{} { 22func (m *GrilsModule) Interface() interface{} {
23 m.Test = append(m.Test, len(m.Test) + 1) 23 m.Test = append(m.Test, len(m.Test)+1)
24 return m 24 return m
25} 25}
26 26
27func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) grilist.DashboardCategory { 27func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory {
28 return grilist.DashboardCategory{} 28 return []grilist.DashboardCategory{}
29} 29}
30 30
31func New() *GrilsModule { 31func New() *GrilsModule {
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}