summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob L. Kreuze <zerodaysfordays@sdf.org>2022-12-03 12:28:28 -0500
committerJakob L. Kreuze <zerodaysfordays@sdf.org>2022-12-03 12:28:28 -0500
commit94560dbfda98c33b5fbf96cc1a00bb3c1832f74c (patch)
tree43ba4a9f4d8260c283abfb5a127c68abc68e711c
parentee0db22ccc33812525094785910cd4d7c7d3077a (diff)
[dynamic] Expose `get-comments' endpoint
-rw-r--r--haunt/api.scm2
-rw-r--r--haunt/jakob/dynamic/capabilities/comments.scm30
2 files changed, 21 insertions, 11 deletions
diff --git a/haunt/api.scm b/haunt/api.scm
index 1b24bc0..c083fcc 100644
--- a/haunt/api.scm
+++ b/haunt/api.scm
@@ -69,7 +69,7 @@
(('GET "comment-form" _) get-comment-form)
('(GET "challenge" "proof-of-work") make-pow-challenge!)
('(GET "challenge" "captcha") make-captcha-challenge!)
- ;; ('(GET "comments") get-comments)
+ ('(GET "comments") get-comments)
(('POST "comment") put-comment)
(('GET "gallery") get-gallery)
(('GET "gallery" "image") get-image)
diff --git a/haunt/jakob/dynamic/capabilities/comments.scm b/haunt/jakob/dynamic/capabilities/comments.scm
index 044852b..ee4172c 100644
--- a/haunt/jakob/dynamic/capabilities/comments.scm
+++ b/haunt/jakob/dynamic/capabilities/comments.scm
@@ -29,6 +29,7 @@
#:use-module (web uri)
#:export (get-comments
get-comments-by-slug
+
put-comment
put-reaction
@@ -44,15 +45,22 @@
(define conn (connect-to-postgres-paramstring "dbname=jakob_comments"))
-(define-json-type <internal-comment>
- (id)
- (name)
- (subject)
- (email)
- (comment)
- (url)
- (publish-time)
- (reactions))
+(define-json-mapping <internal-comment>
+ make-internal-comment
+ internal-comment?
+ json->internal-comment <=> internal-comment->json
+ (id internal-comment-id)
+ (name internal-comment-name)
+ (subject internal-comment-subject)
+ (email internal-comment-email)
+ (comment internal-comment-comment)
+ (url internal-comment-url)
+ (publish-time
+ internal-comment-publish-time
+ "publish-time"
+ (lambda (x) (string->date x "~Y~m~d ~H~M~S.~N"))
+ (lambda (x) (date->string x "~Y-~m-~d ~H:~M:~S.~N")))
+ (reactions internal-comment-reactions))
(define (get-comments-by-slug slug)
"Internal function for querying the approved comments on a post
@@ -76,6 +84,8 @@ This interface exists for dynamically generating the comment view from Haunt."
"API endpoint handler for querying for the comments on a particular post
This is a wrapper around `get-comments-by-slug'."
+ (define (normalize-record record)
+ (json-string->scm (internal-comment->json record)))
(let* ((query-string (uri-query (request-uri request)))
(params (if query-string
(decode-form query-string)
@@ -85,7 +95,7 @@ This is a wrapper around `get-comments-by-slug'."
(values '((content-type . (application/json)))
(scm->json-string
(list->vector
- (get-comments-by-slug (car slug)))))))
+ (map normalize-record (get-comments-by-slug (car slug))))))))