diff --git a/api/comment_approve.go b/api/comment_approve.go index 19428e4..31c2641 100644 --- a/api/comment_approve.go +++ b/api/comment_approve.go @@ -42,7 +42,7 @@ func commentApproveHandler(w http.ResponseWriter, r *http.Request) { return } - domain, err := commentDomainGet(*x.CommentHex) + domain, _, err := commentDomainPathGet(*x.CommentHex) if err != nil { bodyMarshal(w, response{"success": false, "message": err.Error()}) return diff --git a/api/comment_delete.go b/api/comment_delete.go index f9afdff..d736bb7 100644 --- a/api/comment_delete.go +++ b/api/comment_delete.go @@ -41,7 +41,7 @@ func commentDeleteHandler(w http.ResponseWriter, r *http.Request) { return } - domain, err := commentDomainGet(*x.CommentHex) + domain, _, err := commentDomainPathGet(*x.CommentHex) if err != nil { bodyMarshal(w, response{"success": false, "message": err.Error()}) return diff --git a/api/comment_domain_get.go b/api/comment_domain_get.go deleted file mode 100644 index b5f0afb..0000000 --- a/api/comment_domain_get.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import () - -func commentDomainGet(commentHex string) (string, error) { - if commentHex == "" { - return "", errorMissingField - } - - statement := ` - SELECT domain - FROM comments - WHERE commentHex = $1; - ` - row := db.QueryRow(statement, commentHex) - - var domain string - var err error - if err = row.Scan(&domain); err != nil { - return "", errorNoSuchDomain - } - - return domain, nil -} diff --git a/api/comment_domain_path_get.go b/api/comment_domain_path_get.go new file mode 100644 index 0000000..3f06d27 --- /dev/null +++ b/api/comment_domain_path_get.go @@ -0,0 +1,25 @@ +package main + +import () + +func commentDomainPathGet(commentHex string) (string, string, error) { + if commentHex == "" { + return "", "", errorMissingField + } + + statement := ` + SELECT domain, path + FROM comments + WHERE commentHex = $1; + ` + row := db.QueryRow(statement, commentHex) + + var domain string + var path string + var err error + if err = row.Scan(&domain, &path); err != nil { + return "", "", errorNoSuchDomain + } + + return domain, path, nil +} diff --git a/api/comment_domain_get_test.go b/api/comment_domain_path_get_test.go similarity index 61% rename from api/comment_domain_get_test.go rename to api/comment_domain_path_get_test.go index 14d6506..3e71ae9 100644 --- a/api/comment_domain_get_test.go +++ b/api/comment_domain_path_get_test.go @@ -5,19 +5,24 @@ import ( "time" ) -func TestCommentDomainGetBasics(t *testing.T) { +func TestCommentDomainPathGetBasics(t *testing.T) { failTestOnError(t, setupTestEnv()) commentHex, _ := commentNew("temp-commenter-hex", "example.com", "/path.html", "root", "**foo**", "approved", time.Now().UTC()) - domain, err := commentDomainGet(commentHex) + domain, path, err := commentDomainPathGet(commentHex) if err != nil { t.Errorf("unexpected error getting domain by hex: %v", err) return } if domain != "example.com" { - t.Errorf("expected domain = example.com got domain = %s", domain) + t.Errorf("expected domain=example.com got domain=%s", domain) + return + } + + if path != "/path.html" { + t.Errorf("expected path=/path.html got path=%s", path) return } } @@ -25,7 +30,7 @@ func TestCommentDomainGetBasics(t *testing.T) { func TestCommentDomainGetEmpty(t *testing.T) { failTestOnError(t, setupTestEnv()) - if _, err := commentDomainGet(""); err == nil { + if _, _, err := commentDomainPathGet(""); err == nil { t.Errorf("expected error not found getting domain with empty commentHex") return }