From 6eb51cf545f6b377a3ca23ec785a8f65b82fee84 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Tue, 29 Aug 2023 21:10:00 -0700 Subject: [PATCH] Filter member directory by HereFor --- pkg/controller/account/search.go | 5 +++ pkg/models/user.go | 11 ++++++ web/templates/account/search.html | 58 +++++++++++++++++++++---------- 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/pkg/controller/account/search.go b/pkg/controller/account/search.go index 6d14695..8aed64e 100644 --- a/pkg/controller/account/search.go +++ b/pkg/controller/account/search.go @@ -21,7 +21,9 @@ func Search() http.HandlerFunc { "last_login_at desc", "created_at desc", "username", + "username desc", "lower(name)", + "lower(name) desc", "distance", } @@ -33,6 +35,7 @@ func Search() http.HandlerFunc { gender = r.FormValue("gender") orientation = r.FormValue("orientation") maritalStatus = r.FormValue("marital_status") + hereFor = r.FormValue("here_for") sort = r.FormValue("sort") sortOK bool ageMin int @@ -87,6 +90,7 @@ func Search() http.HandlerFunc { Gender: gender, Orientation: orientation, MaritalStatus: maritalStatus, + HereFor: hereFor, Certified: isCertified != "false", InnerCircle: isCertified == "circle", AgeMin: ageMin, @@ -109,6 +113,7 @@ func Search() http.HandlerFunc { "Gender": gender, "Orientation": orientation, "MaritalStatus": maritalStatus, + "HereFor": hereFor, "EmailOrUsername": username, "AgeMin": ageMin, "AgeMax": ageMax, diff --git a/pkg/models/user.go b/pkg/models/user.go index 387cb1e..b498209 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -188,6 +188,7 @@ type UserSearch struct { Gender string Orientation string MaritalStatus string + HereFor string Certified bool InnerCircle bool AgeMin int @@ -278,6 +279,16 @@ func SearchUsers(user *User, search *UserSearch, pager *Pagination) ([]*User, er placeholders = append(placeholders, "marital_status", search.MaritalStatus) } + if search.HereFor != "" { + wheres = append(wheres, ` + EXISTS ( + SELECT 1 FROM profile_fields + WHERE user_id = users.id AND name = ? AND value = ? + ) + `) + placeholders = append(placeholders, "here_for", search.HereFor) + } + if search.Certified { wheres = append(wheres, "certified = ?", "status = ?") placeholders = append(placeholders, search.Certified, UserStatusActive) diff --git a/web/templates/account/search.html b/web/templates/account/search.html index 915dfb7..630cfeb 100644 --- a/web/templates/account/search.html +++ b/web/templates/account/search.html @@ -70,7 +70,7 @@
-
+
@@ -100,9 +100,9 @@
-
+
-
+
-
+
+
+
- - - - - - +
+
+ +
+ +
-
+ +
+
+ +
+ +
+
+
+ +
Reset