aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-06-19 15:51:41 +0200
committerMax Magorsch <arzano@gentoo.org>2020-06-19 15:51:41 +0200
commit21181c518cf41828917d36005b726f9452fde657 (patch)
tree38fab1b3c86a41383e48be6b2686d92efd86db62 /pkg/app/list/show.go
downloadarchives-21181c518cf41828917d36005b726f9452fde657.tar.gz
archives-21181c518cf41828917d36005b726f9452fde657.tar.bz2
archives-21181c518cf41828917d36005b726f9452fde657.zip
Initial version
Signed-off-by: Max Magorsch <arzano@gentoo.org>
Diffstat (limited to 'pkg/app/list/show.go')
-rw-r--r--pkg/app/list/show.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/pkg/app/list/show.go b/pkg/app/list/show.go
new file mode 100644
index 0000000..8db8778
--- /dev/null
+++ b/pkg/app/list/show.go
@@ -0,0 +1,44 @@
+package list
+
+import (
+ "archives/pkg/database"
+ "archives/pkg/models"
+ "github.com/go-pg/pg/v10/orm"
+ "net/http"
+ "strings"
+)
+
+func Show(w http.ResponseWriter, r *http.Request) {
+
+ listName := strings.ReplaceAll(r.URL.Path, "/", "")
+
+ var res []struct {
+ CombinedDate string
+ MessageCount int
+ }
+ err := database.DBCon.Model((*models.Message)(nil)).
+ WhereGroup(func(q *orm.Query) (*orm.Query, error) {
+ q = q.WhereOr(`(headers::jsonb->>'Subject')::jsonb->>0 LIKE '[` + listName + `]%'`).
+ WhereOr(`(headers::jsonb->>'Subject')::jsonb->>0 LIKE 'Re: [` + listName + `]%'`)
+ return q, nil
+ }).
+ WhereGroup(func(q *orm.Query) (*orm.Query, error) {
+ q = q.WhereOr(`headers::jsonb->>'To' LIKE '%` + listName + `@lists.gentoo.org%'`).
+ WhereOr(`headers::jsonb->>'Cc' LIKE '%` + listName + `@lists.gentoo.org%'`).
+ WhereOr(`headers::jsonb->>'To' LIKE '%` + listName + `@gentoo.org%'`).
+ WhereOr(`headers::jsonb->>'Cc' LIKE '%` + listName + `@gentoo.org%'`)
+ return q, nil
+ }).
+ ColumnExpr("to_char(date, 'YYYY-MM') AS combined_date").
+ ColumnExpr("count(*) AS message_count").
+ Group("combined_date").
+ Order("combined_date DESC").
+ Select(&res)
+
+ if err != nil {
+ http.NotFound(w, r)
+ return
+ }
+
+ renderShowTemplate(w, listName, res)
+}