From 492697d86c6eb4092609f9b8b0e11c62e238ccaa Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 28 Feb 2023 13:19:26 -0500 Subject: redirect to correct location on delete --- main.scm | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/main.scm b/main.scm index 0519c3b..4af1ece 100644 --- a/main.scm +++ b/main.scm @@ -234,6 +234,13 @@ (map (cut post current-user <>) comments)) ,(if current-user (new-post-form (id p)) '()))))) +(define (post-path id) + (if + (and id + (not (equal? "" id))) + (string-append "/posts/" id) + "/")) + (define routes `( @@ -286,11 +293,7 @@ [user (get-current-user)] [success? (if user (create-post user content parent-id) #f)]) (send-response - headers: `((location ,(if - (and parent-id - (not (equal? "" parent-id))) - (string-append "/posts/" parent-id) - "/"))) + headers: `((location ,(post-path parent-id))) status: 'see-other )))) (GET (/ "") ,(lambda (rt) @@ -314,12 +317,12 @@ (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? (send-response - headers: `((location "/")) - status: 'see-other - ) + headers: `((location ,(post-path (parent-id post)))) + status: 'see-other) (send-status 'internal-server-error "Deletion Failed"))))) (GET (/ "posts") ,(lambda (rt) -- cgit v1.2.3