From 2dbbd840bb4c0ae0f700d6e894c06e383df2cc01 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sat, 15 Oct 2022 10:47:56 -0500 Subject: Refactor: defendpoint defines a function; easier debugging --- lazybones.lisp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lazybones.lisp b/lazybones.lisp index 234340e..5bdd7e6 100644 --- a/lazybones.lisp +++ b/lazybones.lisp @@ -358,6 +358,15 @@ any way to do it, hence NIL is returned." ;;; ENDPOINT DEFINITION +(eval-when (:compile-toplevel :load-toplevel :execute) + (defun endpoint-function-name-helper (method route) + (string-upcase + (format nil "~a-~{~a~^-~}" + (symbol-name method) + (mapcar + (lambda (x) (if (stringp x) x (car x))) + (cdr (parse-route-string-template route))))))) + (defmacro defendpoint (appname method route query-params @@ -374,6 +383,8 @@ making a new one if not." (a:with-gensyms (the-app auth-method) (let* ((dispatch-pattern (parse-route-string-template route)) + (endpoint-name + (intern (endpoint-function-name-helper method route))) (lambda-list (mapcar 'intern (route-variables dispatch-pattern))) (documentation @@ -388,6 +399,12 @@ making a new one if not." (or (app ',appname) (make-instance 'lazybones:app :name ',appname))) (,auth-method ,auth)) + (defun ,endpoint-name ,lambda-list + (declare (ignorable ,@lambda-list)) + (setf (lazybones:response-header :content-type) + (or ,content-type (lazybones::default-content-type ,the-app))) + ,@real-body) + (register-endpoint ,the-app (make-instance @@ -399,12 +416,7 @@ making a new one if not." :pattern ',dispatch-pattern :doc ,documentation :auth ,auth-method - :function - (lambda ,lambda-list - (declare (ignorable ,@lambda-list)) - (setf (lazybones:response-header :content-type) - (or ,content-type (lazybones::default-content-type ,the-app))) - ,@real-body))))))) + :function ',endpoint-name)))))) (defmacro defendpoint* (method route params options &rest body) "Like DEFENDPOINT but uses the current package name as the app name." -- cgit v1.2.3