diff --git a/src/handlers/questionnaire-submit.lisp b/src/handlers/questionnaire-submit.lisp index 9201928..3ac3708 100644 --- a/src/handlers/questionnaire-submit.lisp +++ b/src/handlers/questionnaire-submit.lisp @@ -2,10 +2,11 @@ (defun questionnaire-submit-uri-p (uri) "Check if the request URI matches the pattern '/survey//submit'" - (let ((parts (split-uri uri))) + (let ((parts (split-uri uri)) + (survey (make-survey uri))) (and (= (length parts) 3) (string= (first parts) "survey") - (and (survey-id-p (parse-integer (second parts))) + (and (funcall survey 'id) (every #'digit-char-p (second parts))) (search "submit" (third parts))))) @@ -21,6 +22,6 @@ (define-easy-handler (questionnaire-submit :uri #'questionnaire-submit-uri) nil (let ((post-params (post-parameters* *request*)) - (id (survey-id (request-uri*)))) - (store-response (ensure-data-file-exist id) post-params) + (survey (make-survey (request-uri*)))) + (store-response (ensure-data-file-exist (funcall survey 'id)) post-params) (ml-survey/views:questionnaire-submit))) diff --git a/src/handlers/survey.lisp b/src/handlers/survey.lisp index 80f8480..b59a019 100644 --- a/src/handlers/survey.lisp +++ b/src/handlers/survey.lisp @@ -1,10 +1,5 @@ (in-package :ml-survey/handlers) -(defun survey-id-p (id) - (check-type id integer) - (let ((ids (mapcar #'car (load-response (make-surveys-db-path))))) - (if (member id ids) t nil))) - (defun survey-uri-p (uri) "Check if the request URI matches the pattern '/survey/'" (check-type uri string) @@ -18,17 +13,6 @@ (let ((uri (request-uri request))) (survey-uri-p uri))) -(defun survey-id (uri) - (check-type uri string) - (let ((id (second (split-uri uri)))) - (unless (survey-id-p (parse-integer id)) - (error "Wrong survey id")) - id)) - -(defun survey-properties (id) - (check-type id integer) - (first (rest (assoc id (load-response (make-surveys-db-path)))))) - (defun make-survey (uri) (labels ((survey-fn (action) (case action