summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.scm14
1 files changed, 8 insertions, 6 deletions
diff --git a/main.scm b/main.scm
index 4af1ece..45dc91f 100644
--- a/main.scm
+++ b/main.scm
@@ -85,10 +85,12 @@
LEFT JOIN posts c ON c.parent_id = p.id
WHERE p.parent_id = ?
GROUP BY p.id, p.user_id, p.content, p.created_at, p.parent_id
- ORDER BY count(c.id) DESC, p.created_at DESC LIMIT 25" post-id))
+ ORDER BY count(c.id) DESC, p.created_at ASC LIMIT 25" post-id))
(define (delete-post post-id current-user)
- (execute db "DELETE FROM posts WHERE id = ? AND user_id = ?" post-id current-user))
+ (first-result db "DELETE FROM posts
+ WHERE id = ? AND user_id = ?
+ RETURNING parent_id" post-id current-user))
;(define (top-posts) (map-row list db
; "SELECT id, user_id, content, created_at
@@ -237,6 +239,7 @@
(define (post-path id)
(if
(and id
+ (not (sql-null? id))
(not (equal? "" id)))
(string-append "/posts/" id)
"/"))
@@ -317,11 +320,10 @@
(GET (/ "posts" ":id" "delete") ,(lambda (rt)
(let* ([current-user (get-current-user)]
[post-id (get-route-param rt "id")]
- [post (get-post post-id)]
- [succeeded? (delete-post post-id current-user)])
- (if succeeded?
+ [parent-id (delete-post post-id current-user)])
+ (if parent-id
(send-response
- headers: `((location ,(post-path (parent-id post))))
+ headers: `((location ,(post-path parent-id)))
status: 'see-other)
(send-status 'internal-server-error "Deletion Failed")))))