summaryrefslogtreecommitdiff
path: root/endpoints.lisp
diff options
context:
space:
mode:
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)