From e46a94b715fdbf55ea71dc2e2664883e53955605 Mon Sep 17 00:00:00 2001 From: Jan C Date: Fri, 11 Mar 2016 14:16:08 +0100 Subject: =?UTF-8?q?=C3=A4hnliche=20grils=20anzeigen,=20wenn=20verf=C3=BCgb?= =?UTF-8?q?ar=20(gril=20view)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 data := m.g.Renderer.DefaultData() data["user"] = user data["gril"] = gril + + // ähnliche grils holen + rows, err := m.g.DB.Query(`SELECT gril_id FROM ( + SELECT DISTINCT gril_id FROM gril_appearance WHERE appearance_id IN (SELECT appearance_id FROM gril_appearance WHERE gril_id = $1) + ) as t + ORDER BY RANDOM() + LIMIT 4;`, id) + if err != nil { + log.Println("could not get similar grils:", err) + http.Error(w, "500", http.StatusInternalServerError) + return + } + + defer rows.Close() + var similar []*Gril + for rows.Next() { + var id int + if err := rows.Scan(&id); err != nil { + log.Println("error scanning for similar gril:", err) + continue + } + + g, err := m.FromID(id) + if err != nil { + log.Println("invalid similar gril:", err) + continue + } + similar = append(similar, g) + } + data["SimilarGrils"] = similar m.g.Renderer.RenderPage("gril", w, data) } diff --git a/views/includes/card_gril.html b/views/includes/card_gril.html new file mode 100644 index 0000000..337c9a9 --- /dev/null +++ b/views/includes/card_gril.html @@ -0,0 +1,11 @@ +{{ define "card_gril" }} +
+
+
+
+
+ {{ .RomajiName }} {{ .KanjiName }} +
+ +
+{{ end }} \ No newline at end of file diff --git a/views/pages/gril.html b/views/pages/gril.html index cd92208..eb66537 100644 --- a/views/pages/gril.html +++ b/views/pages/gril.html @@ -75,6 +75,17 @@ + + {{ if .SimilarGrils }} +

Ähnliche Grils

+
+ {{ range .SimilarGrils }} +
+ {{ template "card_gril" . }} +
+ {{ end }} +
+ {{ end }} -- cgit v0.10.1