diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/grils/grils.go | 30 |
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 | } |