summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrant Shangreaux <shoshin@cicadas.surf>2023-01-24 21:34:57 -0600
committerGrant Shangreaux <shoshin@cicadas.surf>2023-01-24 21:34:57 -0600
commit01c9197114270d153308226a1588de78ed05ee29 (patch)
tree2818ea612f624b42b97800db422f5eac1a85f405
parent1d40a541e41b37d03446b471ef8c072b005ee24e (diff)
Clean: reorganize and document some of endpoints.lisp
-rw-r--r--endpoints.lisp57
1 files changed, 33 insertions, 24 deletions
diff --git a/endpoints.lisp b/endpoints.lisp
index 4d8b85c..5c2a656 100644
--- a/endpoints.lisp
+++ b/endpoints.lisp
@@ -9,7 +9,40 @@
(defparameter +session-cookie-name+ "dnd-session")
+;;; Endpoints that do not require a session:
+
+(defendpoint* :get "/" () ()
+ (redirect-to "/tavern-door"))
+
+(defendpoint* :get "/tavern-door" () ()
+ (doorkeeper))
+
+(defendpoint* :post "/tavern-door" () ()
+ (with-plist ((name :name)) (lzb:request-body)
+ (a:if-let ((hero (hero-known-as name)))
+ (a:when-let ((sesh (new-sesh hero)))
+ (lzb:set-response-cookie +session-cookie-name+ (session-id sesh)
+ :path "/" :domain "localhost")
+ (redirect-to "/tavern"))
+ (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)
+ (redirect-to "/tavern-door")))
+
+;;; Endpoints that do require a session:
+
+(defendpoint* :get "/tavern" () ()
+ (with-hero-session (hero)
+ (tavern hero)))
+
(defun redirect-to (location)
+ "Set the lazybones response header and response code for redirecting to LOCATION.
+This procedure will error if lazybones:*request* is not currently bound."
(setf (lzb:response-header :location) location
(lzb:response-code) "303"))
@@ -27,27 +60,3 @@ I.e. It should be called within the scope of a request handler."
(let ((,hero (session-hero ,session)))
,@body)
(redirect-to ,redirect))))
-
-(defendpoint* :get "/godess-shrine" () ()
- (godess-shrine))
-
-(defendpoint* :post "/godess-shrine" () ()
- (with-plist ((name :name)) (lzb:request-body)
- (birth-from-the-goddess-loins name)
- (redirect-to "/tavern-door")))
-
-(defendpoint* :get "/tavern-door" () ()
- (doorkeeper))
-
-(defendpoint* :post "/tavern-door" () ()
- (with-plist ((name :name)) (lzb:request-body)
- (a:if-let ((hero (hero-known-as name)))
- (a:when-let ((sesh (new-sesh hero)))
- (lzb:set-response-cookie +session-cookie-name+ (session-id sesh)
- :path "/" :domain "localhost")
- (redirect-to "/tavern"))
- (redirect-to "/tavern-door"))))
-
-(defendpoint* :get "/tavern" () ()
- (with-hero-session (hero)
- (tavern hero)))