diff options
author | dan <[email protected]> | 2023-03-01 21:36:26 -0500 |
---|---|---|
committer | dan <[email protected]> | 2023-03-01 21:36:26 -0500 |
commit | 63adce5be15d67ba4074226c2feb3a02b63412bb (patch) | |
tree | 1424797587843299e5f1d471f725d92013d0e213 | |
parent | 4eacc5129b8612b65cf6b28b739cf8e62e616405 (diff) | |
download | 54-63adce5be15d67ba4074226c2feb3a02b63412bb.tar.gz 54-63adce5be15d67ba4074226c2feb3a02b63412bb.tar.bz2 54-63adce5be15d67ba4074226c2feb3a02b63412bb.zip |
404 page show when attempting to view a deleted post
-rw-r--r-- | main.scm | 41 |
1 files changed, 21 insertions, 20 deletions
@@ -1,13 +1,12 @@ -(import (chicken format) (srfi-1)) -(import spiffy intarweb uri-common html-parser (chicken port)) -(import spiffy-request-vars) -(import (chicken io)) -(import sqlite3) -(import sql-null) -(import srfi-69) -(import (chicken random)) -(import (chicken process-context)) -(import (chicken irregex)) +(import + scheme (chicken base) + (chicken format) (chicken port) (chicken io) (chicken random) + (chicken process-context) (chicken irregex) (chicken condition) + spiffy intarweb uri-common html-parser spiffy-request-vars + sqlite3 sql-null + srfi-69 ;hash tables + srfi-1 ;list functions +) ;; db open and create @@ -64,18 +63,17 @@ WHERE p.parent_id IS NULL 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")) - - - + (define (get-post post-id) - (first-row db + (condition-case (first-row db "SELECT p.id, p.user_id, p.content, p.created_at, p.parent_id, count(c.id) FROM posts p LEFT JOIN posts c ON c.parent_id = p.id WHERE p.id = ? GROUP BY p.id, p.user_id, p.content, p.created_at, p.parent_id ORDER BY count(c.id) DESC LIMIT 1" - post-id)) + post-id) + [(exn sqlite3) #f])) (define (get-child-posts post-id) (map-row list db @@ -319,11 +317,14 @@ (let* ([current-user (get-current-user)] [post-id (get-route-param rt "id")] [post (get-post post-id)] - [comments (get-child-posts post-id)]) - (send-response - headers: '((content-type text/html)) - status: 'ok - body: (post-page current-user post comments))))) + [comments (if post (get-child-posts post-id) #f)]) + (if post + (send-response + headers: '((content-type text/html)) + status: 'ok + body: (post-page current-user post comments)) + (send-status 'not-found "This Post no longer exists!"))))) + ; Has method GET so that it can be used from <a> tag links (GET (/ "posts" ":id" "delete") ,(lambda (rt) (let* ([current-user (get-current-user)] |