aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorJan C <jan@ruken.pw>2016-03-11 13:16:08 (UTC)
committerJan C <jan@ruken.pw>2016-03-11 13:16:08 (UTC)
commite46a94b715fdbf55ea71dc2e2664883e53955605 (patch)
treec1ccf1d97e68b4ac7d089cf8a56ebfa1e6c0d364 /modules
parent848558c3ddcceddc3df6f0ff446a2691c895228d (diff)
ähnliche grils anzeigen, wenn verfügbar (gril view)
Diffstat (limited to 'modules')
-rw-r--r--modules/grils/grils.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index 5d548e6..e6aaa11 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -195,6 +195,36 @@ func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprou
195 data := m.g.Renderer.DefaultData() 195 data := m.g.Renderer.DefaultData()
196 data["user"] = user 196 data["user"] = user
197 data["gril"] = gril 197 data["gril"] = gril
198
199 // ähnliche grils holen
200 rows, err := m.g.DB.Query(`SELECT gril_id FROM (
201 SELECT DISTINCT gril_id FROM gril_appearance WHERE appearance_id IN (SELECT appearance_id FROM gril_appearance WHERE gril_id = $1)
202 ) as t
203 ORDER BY RANDOM()
204 LIMIT 4;`, id)
205 if err != nil {
206 log.Println("could not get similar grils:", err)
207 http.Error(w, "500", http.StatusInternalServerError)
208 return
209 }
210
211 defer rows.Close()
212 var similar []*Gril
213 for rows.Next() {
214 var id int
215 if err := rows.Scan(&id); err != nil {
216 log.Println("error scanning for similar gril:", err)
217 continue
218 }
219
220 g, err := m.FromID(id)
221 if err != nil {
222 log.Println("invalid similar gril:", err)
223 continue
224 }
225 similar = append(similar, g)
226 }
227 data["SimilarGrils"] = similar
198 228
199 m.g.Renderer.RenderPage("gril", w, data) 229 m.g.Renderer.RenderPage("gril", w, data)
200} 230}