comment_domain_path_get.go: include path in return
This commit is contained in:
parent
9fb33fbd9d
commit
afeef81b29
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
25
api/comment_domain_path_get.go
Normal file
25
api/comment_domain_path_get.go
Normal file
@ -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
|
||||
}
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user