CREATE TABLE IF NOT EXISTS comments ( id INTEGER PRIMARY KEY AUTOINCREMENT, resource_id INTEGER NOT NULL, user_id INTEGER NOT NULL, body TEXT NOT NULL, created_at TEXT NOT NULL);CREATE INDEX IF NOT EXISTS idx_comments_resource ON comments (resource_id, id ASC);
$stmt = $this->pdo->prepare( 'SELECT * FROM comments WHERE resource_id = :rid ORDER BY id ASC LIMIT :lim OFFSET :off');$stmt->bindValue(':rid', $resourceId, PDO::PARAM_INT);$stmt->bindValue(':lim', $limit, PDO::PARAM_INT);$stmt->bindValue(':off', $offset, PDO::PARAM_INT);
1 2 3 4 5 6
The response includes total (count of all comments for the resource), limit, and offset so clients can build pagination controls:
POST /resources/{resourceId}/comments Post a comment (X-User-Id required)GET /resources/{resourceId}/comments List comments (paginated, public)DELETE /comments/{id} Delete comment (author or admin)
How-to: Comment Thread API
This guide demonstrates resource-scoped comment threads with pagination, author-only deletion, and admin override.
Pattern Overview
limitandoffsetquery parameters.Schema
2
3
4
5
6
7
8
Pagination Pattern
2
3
4
5
6
The response includes
total(count of all comments for the resource),limit, andoffsetso clients can build pagination controls:2
3
4
5
6
Limit Clamping
Invalid or out-of-range limit/offset values are silently clamped to safe defaults:
2
3
4
5
6
7
8
ctype_digit()is used to avoid ReDoS on the query string.IDOR: Author-Only Deletion
Non-admin users can only delete their own comments. Attempting to delete another user's comment returns 404 (not 403):
2
3
Resource Isolation
All queries include
WHERE resource_id = :rid, ensuring comments for resource 1 are never mixed with resource 2.Validation Rules
X-User-Idctype_digit, >0body{resourceId}pathctype_digit, max 18 chars, >0; else 404limitqueryoffsetqueryRoutes
2
3
See Also
../NENE2-FT/commentlog/docs/howto/note-taking.md(FT202, note CRUD)docs/howto/leaderboard-ranking.md(FT206, resource-scoped data)