From 31b9690d74d1736a3c6c23c12a235e8e620d151b Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sun, 21 Jul 2019 21:22:26 +0530 Subject: [PATCH] Remove orphan func --- handlers.go | 37 ------------------------------------- queries.go | 1 + queries.sql | 4 ++++ 3 files changed, 5 insertions(+), 37 deletions(-) diff --git a/handlers.go b/handlers.go index 733020c..c53bb5a 100644 --- a/handlers.go +++ b/handlers.go @@ -1,14 +1,11 @@ package main import ( - "encoding/json" "net/http" "net/url" "regexp" "strconv" - "strings" - "github.com/asaskevich/govalidator" "github.com/labstack/echo" ) @@ -153,40 +150,6 @@ func validateUUID(next echo.HandlerFunc, params ...string) echo.HandlerFunc { } } -// makeAttribsBlob takes a list of keys and values and creates -// a JSON map out of them. -func makeAttribsBlob(keys []string, vals []string) ([]byte, bool) { - attribs := make(map[string]interface{}) - for i, key := range keys { - var ( - s = vals[i] - val interface{} - ) - - // Try to detect common JSON types. - if govalidator.IsFloat(s) { - val, _ = strconv.ParseFloat(s, 64) - } else if govalidator.IsInt(s) { - val, _ = strconv.ParseInt(s, 10, 64) - } else { - ls := strings.ToLower(s) - if ls == "true" || ls == "false" { - val, _ = strconv.ParseBool(ls) - } else { - // It's a string. - val = s - } - } - attribs[key] = val - } - - if len(attribs) > 0 { - j, _ := json.Marshal(attribs) - return j, true - } - return nil, false -} - // getPagination takes form values and extracts pagination values from it. func getPagination(q url.Values) pagination { var ( diff --git a/queries.go b/queries.go index c23844e..dace61b 100644 --- a/queries.go +++ b/queries.go @@ -19,6 +19,7 @@ type Queries struct { GetSubscriber *sqlx.Stmt `query:"get-subscriber"` GetSubscribersByEmails *sqlx.Stmt `query:"get-subscribers-by-emails"` GetSubscriberLists *sqlx.Stmt `query:"get-subscriber-lists"` + SubscriberExists *sqlx.Stmt `query:"subscriber-exists"` UpdateSubscriber *sqlx.Stmt `query:"update-subscriber"` BlacklistSubscribers *sqlx.Stmt `query:"blacklist-subscribers"` AddSubscribersToLists *sqlx.Stmt `query:"add-subscribers-to-lists"` diff --git a/queries.sql b/queries.sql index 67409b6..3108f00 100644 --- a/queries.sql +++ b/queries.sql @@ -3,6 +3,10 @@ -- Get a single subscriber by id or UUID. SELECT * FROM subscribers WHERE CASE WHEN $1 > 0 THEN id = $1 ELSE uuid = $2 END; +-- name: subscriber-exists +-- Check if a subscriber exists by id or UUID. +SELECT exists (SELECT true FROM subscribers WHERE CASE WHEN $1 > 0 THEN id = $1 ELSE uuid = $2 END); + -- name: get-subscribers-by-emails -- Get subscribers by emails. SELECT * FROM subscribers WHERE email=ANY($1);