about summary refs log tree commit diff
path: root/web/panettone/src/panettone.lisp
diff options
context:
space:
mode:
authoredef <edef@edef.eu>2020-08-05T00·59+0000
committeredef <edef@edef.eu>2020-08-08T18·23+0000
commit311511385455f680aedf78aab761fcebf3ca7731 (patch)
treed0d677945734a8e97d04ef897c9c417a10969510 /web/panettone/src/panettone.lisp
parent3049f31d2824b95c8a2e13c6b919847de6bd0705 (diff)
feat(web/panettone): implement shorthand issue URLs r/1617
Fix #32

Change-Id: I6ccec959201673850b4b56a44734a2874aad5856
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1648
Reviewed-by: glittershark <grfn@gws.fyi>
Reviewed-by: edef <edef@edef.eu>
Tested-by: BuildkiteCI
Diffstat (limited to 'web/panettone/src/panettone.lisp')
-rw-r--r--web/panettone/src/panettone.lisp20
1 files changed, 15 insertions, 5 deletions
diff --git a/web/panettone/src/panettone.lisp b/web/panettone/src/panettone.lisp
index 7594c3ab24..cf9c608b07 100644
--- a/web/panettone/src/panettone.lisp
+++ b/web/panettone/src/panettone.lisp
@@ -369,8 +369,9 @@
              (render/new-comment (id issue))))))))))
 
 (defun render/not-found (entity-type)
+  (setf (hunchentoot:return-code*) 404)
   (render ()
-    (:h1 (who:esc entity-type) "Not Found")))
+    (:h1 (who:esc entity-type) " Not Found")))
 
 ;;;
 ;;; HTTP handlers
@@ -452,10 +453,12 @@
 (defroute show-issue
     ("/issues/:id" :decorators (@auth-optional @handle-issue-not-found))
     (&path (id 'integer))
-  (let* ((issue (model:get-issue id))
-         (*title* (format nil "~A | Panettone"
-                          (subject issue))))
-    (render/issue issue)))
+  (when id
+    (let* ((issue (model:get-issue id))
+           (*title* (format nil "~A | Panettone"
+                            (subject issue))))
+      (render/issue issue))
+    (render/not-found "Issue")))
 
 (defroute edit-issue
     ("/issues/:id/edit" :decorators (@auth @handle-issue-not-found))
@@ -516,6 +519,13 @@
   (setf (hunchentoot:content-type*) "text/css")
   (apply #'lass:compile-and-write panettone.css:styles))
 
+(defroute shorthand-issue
+    ("/:id" :decorators (@auth-optional))
+    (&path (id 'integer))
+  (if id
+      (hunchentoot:redirect (format nil "/issues/~A" id))
+      (render/not-found "Route")))
+
 (defvar *acceptor* nil
   "Hunchentoot acceptor for Panettone's web server.")