summaryrefslogtreecommitdiff
path: root/routes.lisp
diff options
context:
space:
mode:
authorGrant Shoshin Shangreaux <shoshin@cicadas.surf>2023-01-07 11:12:15 -0600
committerGrant Shoshin Shangreaux <shoshin@cicadas.surf>2023-01-07 11:12:15 -0600
commitaee7f487f97c10c15b6c7b48156cc95db19d9137 (patch)
tree9ccdb9b7a3e356ed39f2ed71b2d04b7e2718df20 /routes.lisp
parent9a040d4e78ab07eb9c482a40042f2ba92d2a8e3b (diff)
First Draft of hero creation and login
Diffstat (limited to 'routes.lisp')
-rw-r--r--routes.lisp38
1 files changed, 35 insertions, 3 deletions
diff --git a/routes.lisp b/routes.lisp
index 56b6191..b1d4ff7 100644
--- a/routes.lisp
+++ b/routes.lisp
@@ -2,11 +2,43 @@
(in-package :dnd)
-(lzb:provision-app (api)
+(lzb:provision-app ()
:title "Dungeons & Deadlines"
:version "0.1.0"
- :prefix "/api"
- :content-type "application/json")
+ :content-type "text/html")
+(defparameter +session-cookie-name+ "dnd-session")
+(defendpoint* :get "/a-hero-is-born" () ()
+ (a-hero-is-born))
+(defendpoint* :post "/a-hero-is-born" () ()
+ (with-plist ((name :name)) (lzb:request-body)
+ (birth-from-the-goddess-loins name)
+ (setf (lzb:response-header :location) "/tavern-door"
+ (lzb:response-code) "303")))
+
+(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")
+ (setf (lzb:response-header :location) "/tavern"
+ (lzb:response-code) "303"))
+ (setf (lzb:response-header :location) "/tavern-door"
+ (lzb:response-code) "303"))))
+
+(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)))