summaryrefslogtreecommitdiff
path: root/endpoints.lisp
diff options
context:
space:
mode:
authorcolin <colin@cicadas.surf>2023-02-20 10:02:57 -0800
committercolin <colin@cicadas.surf>2023-02-20 10:02:57 -0800
commitc129745433a3acd62e600adc6c9a1000b66f6f4c (patch)
tree1f8e4d68f210346d760f54c78c9f2cc1232e74d9 /endpoints.lisp
parentfc4b6e145457bc057b050170245d290b9b70fbe8 (diff)
Add: route building protocol functions
Diffstat (limited to 'endpoints.lisp')
-rw-r--r--endpoints.lisp24
1 files changed, 24 insertions, 0 deletions
diff --git a/endpoints.lisp b/endpoints.lisp
index 788dc2d..6dde37e 100644
--- a/endpoints.lisp
+++ b/endpoints.lisp
@@ -9,6 +9,30 @@
(defparameter +session-cookie-name+ "dnd-session")
+;;; DND ROUTE PROTOCOL
+
+(defgeneric unique-name (object)
+ (:documentation "Returns a unique name for an object, or NIL if it does not have one.")
+ (:method ((ob t)) nil))
+
+(defmethod unique-name ((campaign campaign))
+ (campaign-title campaign))
+
+(defmethod unique-name ((hero hero))
+ (hero-name hero))
+
+(defgeneric urlpath (inflection object)
+ (:documentation "Return the path to the object given a particular")
+ (:method ((inflection t) (object has-uid))
+ "If the object has a unique human readable name, urlify that name and
+incorporate it into the urlpath. Otherwise use the object's uid.
+
+Returns /inflection/class/identifier."
+ (format nil "~a/~a/~a"
+ (urlify inflection)
+ (urlify (class-name (class-of object)))
+ (urlify (or (unique-name object) (uid object))))))
+
;;; UTILITIES
(defun redirect-to (location)