From c129745433a3acd62e600adc6c9a1000b66f6f4c Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 20 Feb 2023 10:02:57 -0800 Subject: Add: route building protocol functions --- endpoints.lisp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'endpoints.lisp') 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) -- cgit v1.2.3