From d75c8828825465164f4c59f82dc8f0b54f911003 Mon Sep 17 00:00:00 2001 From: Adhityaa Date: Thu, 7 Jun 2018 13:11:02 +0530 Subject: [PATCH] api: replace commenterIsProviderUser --- api/commenter.go | 23 ----------------------- api/commenter_get.go | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/api/commenter.go b/api/commenter.go index a3a795b..59db6fc 100644 --- a/api/commenter.go +++ b/api/commenter.go @@ -13,26 +13,3 @@ type commenter struct { Provider string `json:"provider,omitempty"` JoinDate time.Time `json:"joinDate,omitempty"` } - -func commenterIsProviderUser(provider string, email string) (bool, error) { - if provider == "" || email == "" { - return false, errorMissingField - } - - statement := ` - SELECT EXISTS ( - SELECT 1 - FROM commenters - WHERE email=$1 AND provider=$2 - ); - ` - row := db.QueryRow(statement, email, provider) - - var exists bool - if err := row.Scan(&exists); err != nil { - logger.Errorf("error checking if provider user exists: %v", err) - return false, errorInternal - } - - return exists, nil -} diff --git a/api/commenter_get.go b/api/commenter_get.go index 5d59ac7..8ab4db0 100644 --- a/api/commenter_get.go +++ b/api/commenter_get.go @@ -23,6 +23,27 @@ func commenterGetByHex(commenterHex string) (commenter, error) { return c, nil } +func commenterGetByEmail(provider string, email string) (commenter, error) { + if provider == "" || email == "" { + return commenter{}, errorMissingField + } + + statement := ` + SELECT commenterHex, email, name, link, photo, provider, joinDate + FROM commenters + WHERE email = $1 AND provider = $2; + ` + row := db.QueryRow(statement, email, provider) + + c := commenter{} + if err := row.Scan(&c.CommenterHex, &c.Email, &c.Name, &c.Link, &c.Photo, &c.Provider, &c.JoinDate); err != nil { + // TODO: is this the only error? + return commenter{}, errorNoSuchCommenter + } + + return c, nil +} + func commenterGetBySession(session string) (commenter, error) { if session == "" { return commenter{}, errorMissingField