diff options
Diffstat (limited to 'routes.lisp')
-rw-r--r-- | routes.lisp | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/routes.lisp b/routes.lisp index b1d4ff7..b0b81ac 100644 --- a/routes.lisp +++ b/routes.lisp @@ -9,14 +9,22 @@ (defparameter +session-cookie-name+ "dnd-session") -(defendpoint* :get "/a-hero-is-born" () () - (a-hero-is-born)) +(defun redirect-to (location) + (setf (lzb:response-header :location) location + (lzb:response-code) "303")) -(defendpoint* :post "/a-hero-is-born" () () +(defmacro with-session (&body body) + `(a:if-let ((sesh (session-with-id (lzb:request-cookie +session-cookie-name+)))) + ,@body + (redirect-to "/tavern-door"))) + +(defendpoint* :get "/godess-shrine" () () + (godess-shrine)) + +(defendpoint* :post "/godess-shrine" () () (with-plist ((name :name)) (lzb:request-body) (birth-from-the-goddess-loins name) - (setf (lzb:response-header :location) "/tavern-door" - (lzb:response-code) "303"))) + (redirect-to "/tavern-door"))) (defendpoint* :get "/tavern-door" () () (doorkeeper)) @@ -27,18 +35,8 @@ (a:when-let ((sesh (new-sesh hero))) (lzb:set-response-cookie +session-cookie-name+ (session-id sesh) :path "/" :domain "localhost") - (setf (lzb:response-header :location) "/tavern" - (lzb:response-code) "303")) - (setf (lzb:response-header :location) "/tavern-door" - (lzb:response-code) "303")))) + (redirect-to "/tavern")) + (redirect-to "/tavern-door")))) (defendpoint* :get "/tavern" () () - (let ((hero (session-hero (session-with-id (lzb:request-cookie +session-cookie-name+))))) - (tavern hero))) - -(defun birth-from-the-goddess-loins (name) - (db:with-transaction () - (make-instance 'hero :name name))) - -(defun new-sesh (hero) - (db:with-transaction () (make-instance 'session :hero hero))) + (with-session (tavern (session-hero sesh)))) |