From 63adce5be15d67ba4074226c2feb3a02b63412bb Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 1 Mar 2023 21:36:26 -0500 Subject: 404 page show when attempting to view a deleted post --- main.scm | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'main.scm') diff --git a/main.scm b/main.scm index c3bfe98..e26dd5c 100644 --- a/main.scm +++ b/main.scm @@ -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 tag links (GET (/ "posts" ":id" "delete") ,(lambda (rt) (let* ([current-user (get-current-user)] -- cgit v1.2.3