summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordan <[email protected]>2023-02-28 13:19:26 -0500
committerdan <[email protected]>2023-02-28 13:19:26 -0500
commit492697d86c6eb4092609f9b8b0e11c62e238ccaa (patch)
tree6a8a538b2b2011aa9048a382934e6c8e0b7b875d
parentccf1a1c0730f36158c1150893935668507d945e8 (diff)
download54-492697d86c6eb4092609f9b8b0e11c62e238ccaa.tar.gz
54-492697d86c6eb4092609f9b8b0e11c62e238ccaa.tar.bz2
54-492697d86c6eb4092609f9b8b0e11c62e238ccaa.zip
redirect to correct location on delete
-rw-r--r--main.scm19
1 files 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)