Define a make-survey function
This commit is contained in:
parent
bfd430a317
commit
615c547b19
1 changed files with 17 additions and 2 deletions
|
@ -29,6 +29,21 @@
|
|||
(check-type id integer)
|
||||
(first (rest (assoc id (load-response (make-surveys-db-path))))))
|
||||
|
||||
(defun make-survey (uri)
|
||||
(labels ((survey-fn (action)
|
||||
(case action
|
||||
(id (second (split-uri uri)))
|
||||
(id-p (let ((ids (mapcar #'car (load-response (make-surveys-db-path)))))
|
||||
(if (member (survey-fn 'id) ids) t nil)))
|
||||
(uri-p (let ((parts (split-uri uri)))
|
||||
(and (= (length parts) 2)
|
||||
(string= (first parts) "survey")
|
||||
(every #'digit-char-p (second parts))
|
||||
(survey-fn 'id-p))))
|
||||
(properties (let ((survey-id (parse-integer (survey-fn 'id))))
|
||||
(first (rest (assoc survey-id (load-response (make-surveys-db-path))))))))))
|
||||
#'survey-fn))
|
||||
|
||||
(define-easy-handler (survey :uri #'survey-uri) ()
|
||||
(let ((id (survey-id (request-uri*))))
|
||||
(ml-survey/views:survey id (survey-properties (parse-integer id)))))
|
||||
(let ((survey (make-survey (request-uri*))))
|
||||
(ml-survey/views:survey (funcall survey 'id) (funcall survey 'properties))))
|
||||
|
|
Loading…
Add table
Reference in a new issue