feat(web/panettone): implement shorthand issue URLs

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
This commit is contained in:
edef 2020-08-05 00:59:01 +00:00
parent 3049f31d28
commit 3115113854
2 changed files with 16 additions and 6 deletions

View file

@ -155,7 +155,7 @@ its new value will be formatted using ~A into NEW-VALUE"))
(define-condition issue-not-found (error)
((id :type integer
:initarg :id
:reader not-found-id
:reader id
:documentation "ID of the issue that was not found"))
(:documentation
"Error condition for when an issue requested by ID is not found"))

View file

@ -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.")