1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-29 22:56:37 -04:00

api,db: add comments count endpoint

Closes https://gitlab.com/commento/commento-ce/issues/27
This commit is contained in:
Adhityaa Chandrasekar
2018-09-23 00:40:06 -04:00
parent 299649cea2
commit 330131f390
6 changed files with 118 additions and 2 deletions

View File

@ -11,19 +11,20 @@ func pageGet(domain string, path string) (page, error) {
}
statement := `
SELECT isLocked
SELECT isLocked, commentCount
FROM pages
WHERE domain=$1 AND path=$2;
`
row := db.QueryRow(statement, domain, path)
p := page{Domain: domain, Path: path}
if err := row.Scan(&p.IsLocked); err != nil {
if err := row.Scan(&p.IsLocked, &p.CommentCount); err != nil {
if err == sql.ErrNoRows {
// If there haven't been any comments, there won't be a record for this
// page. The sane thing to do is return defaults.
// TODO: the defaults are hard-coded in two places: here and the schema
p.IsLocked = false
p.CommentCount = 0
} else {
logger.Errorf("error scanning page: %v", err)
return page{}, errorInternal