Replace survey functions

This commit is contained in:
Marcus Kammer 2024-06-02 21:07:47 +02:00
parent 0fa55fa629
commit 66054cddbe
Signed by: marcuskammer
GPG key ID: C374817BE285268F
2 changed files with 5 additions and 20 deletions

View file

@ -2,10 +2,11 @@
(defun questionnaire-submit-uri-p (uri)
"Check if the request URI matches the pattern '/survey/<numeric>/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)))

View file

@ -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/<numeric>'"
(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