Separate route from function definitions

This commit is contained in:
Tom Willemse 2013-08-18 16:19:54 +02:00
parent 612e219bec
commit 6e5b291257

View file

@ -70,194 +70,205 @@
(defun make-tpl-parameters (&rest args) (defun make-tpl-parameters (&rest args)
(append (list :prefix (script-name *request*)) args)) (append (list :prefix (script-name *request*)) args))
(setf (route *app* "/") (defun story-list-page (params)
(lambda (params) (declare (ignore params))
(declare (ignore params)) (if (logged-in-p)
(if (logged-in-p) (scrumli-templates:main
(scrumli-templates:main (make-tpl-parameters
(make-tpl-parameters :title (page-title "Backlog")
:title (page-title "Backlog") :csss (list *scrumli-bootstrap-css-location*
:csss (list *scrumli-bootstrap-css-location* *scrumli-font-awesome-css-location*
*scrumli-font-awesome-css-location* (concatenate 'string (script-name *request*)
(concatenate 'string (script-name *request*) "static/css/scrumli.css")) "static/css/scrumli.css"))
:jss (list *scrumli-jquery-js-location* :jss (list *scrumli-jquery-js-location*
*scrumli-bootstrap-js-location* *scrumli-bootstrap-js-location*
*scrumli-react-js-location* *scrumli-react-js-location*
*scrumli-jsxtransformer-js-location* *scrumli-jsxtransformer-js-location*
(concatenate 'string (script-name *request*) "js/bridge.js")) (concatenate 'string (script-name *request*)
:username (gethash :username (getf (env *request*) :clack.session)) "js/bridge.js"))
:usermd5 (md5-hash (gethash :username (getf (env *request*) :clack.session))) :username (gethash :username (getf (env *request*)
:ulogout (concatenate 'string (script-name *request*) "logout") :clack.session))
:umainjs (concatenate 'string (script-name *request*) "static/js/main.js"))) :usermd5 (md5-hash (gethash :username (getf (env *request*)
(redirect *response* :clack.session)))
(concatenate 'string (script-name *request*) :ulogout (concatenate 'string (script-name *request*) "logout")
"login"))))) :umainjs (concatenate 'string (script-name *request*)
"static/js/main.js")))
(redirect *response*
(concatenate 'string (script-name *request*)
"login"))))
(setf (route *app* "/login") (defun login-page (params)
(lambda (params) (declare (ignore params))
(declare (ignore params)) (if (not (logged-in-p))
(if (not (logged-in-p)) (scrumli-templates:login
(scrumli-templates:login (make-tpl-parameters
(make-tpl-parameters :title (page-title "Login")
:title (page-title "Login") :csss (list *scrumli-bootstrap-css-location*
:csss (list *scrumli-bootstrap-css-location* *scrumli-font-awesome-css-location*)
*scrumli-font-awesome-css-location*) :jss (list *scrumli-bootstrap-js-location*
:jss (list *scrumli-bootstrap-js-location* "https://login.persona.org/include.js"
"https://login.persona.org/include.js" (concatenate 'string (script-name *request*)
(concatenate 'string (script-name *request*) "js/bridge.js")
"js/bridge.js") (concatenate 'string (script-name *request*)
(concatenate 'string (script-name *request*) "static/js/login.js"))))
"static/js/login.js")))) (redirect *response* (if (equal (script-name *request*) "")
(redirect *response* (if (equal (script-name *request*) "") "/" (script-name *request*)))))
"/" (script-name *request*))))))
(setf (route *app* "/login" :method :post) (defun login-page/post (params)
(lambda (params) (let ((result (verify-credentials
(let ((result (verify-credentials *scrumli-host* (getf params :|assertion|))))
*scrumli-host* (getf params :|assertion|)))) (if (equal (cdr (assoc :status result)) "okay")
(if (equal (cdr (assoc :status result)) "okay") (progn
(progn (setf (gethash :username
(setf (gethash :username (getf (env *request*) :clack.session))
(getf (env *request*) :clack.session)) (cdr (assoc :email result)))
(cdr (assoc :email result))) (redirect *response*
(redirect *response* (if (equal (script-name *request*) "")
(if (equal (script-name *request*) "") "/" (script-name *request*))))
"/" (script-name *request*)))) '(403))))
'(403)))))
(setf (route *app* "/logout") (defun logout (params)
(lambda (params) (declare (ignore params))
(declare (ignore params)) (if (logged-in-p)
(if (logged-in-p) (setf (gethash :username
(setf (gethash :username (getf (env *request*) :clack.session)) nil))
(getf (env *request*) :clack.session)) nil)) (redirect *response* (concatenate 'string (script-name *request*)
(redirect *response* (concatenate 'string (script-name *request*) "login")))
"login"))))
(setf (route *app* "/stories") (defun stories-json (params)
(lambda (params) (declare (ignore params))
(declare (ignore params)) (if (logged-in-p)
(if (logged-in-p) (list 200 '(:content-type "text/json")
(list 200 '(:content-type "text/json") (encode-json-to-string (get-all-stories)))
(encode-json-to-string (get-all-stories))) '(403)))
'(403))))
(setf (route *app* "/stories/mine") (defun user-stories-json (params)
(lambda (params) (declare (ignore params))
(declare (ignore params)) (if (logged-in-p)
(if (logged-in-p) (list 200 '(:content-type "text/json")
(list 200 '(:content-type "text/json") (encode-json-to-string
(encode-json-to-string (get-stories-for
(get-stories-for (gethash
(gethash :username (getf (env *request*) :clack.session))))) :username (getf (env *request*) :clack.session)))))
'(403)))) '(403)))
(setf (route *app* "/stories/new" :method :post) (defun add-story-json/post (params)
(lambda (params) (if (logged-in-p)
(if (logged-in-p) (let ((role (getf params :|role|))
(let ((role (getf params :|role|)) (necessity (getf params :|necessity|))
(necessity (getf params :|necessity|)) (headline (getf params :|headline|))
(headline (getf params :|headline|)) (content (getf params :|content|)))
(content (getf params :|content|))) (post-story
(post-story role necessity headline content role necessity headline content
(gethash :username (getf (env *request*) :clack.session))) (gethash :username (getf (env *request*) :clack.session)))
(list 200 '(:content-type "text/json") (list 200 '(:content-type "text/json")
(encode-json-to-string '((status . "ok"))))) (encode-json-to-string '((status . "ok")))))
'(403)))) '(403)))
(setf (route *app* "/stories/tasks/new" :method :post) (defun add-task-json/post (params)
(lambda (params) (if (logged-in-p)
(if (logged-in-p) (let ((story-id (getf params :|storyId|))
(let ((story-id (getf params :|storyId|)) (description (getf params :|description|)))
(description (getf params :|description|))) (post-task
(post-task story-id description story-id description
(gethash :username (getf (env *request*) :clack.session))) (gethash :username (getf (env *request*) :clack.session)))
(list 200 '(:content-type "text/json") (list 200 '(:content-type "text/json")
(encode-json-to-string '((status . "ok"))))) (encode-json-to-string '((status . "ok")))))
'(403)))) '(403)))
(setf (route *app* "/stories/state" :method :post) (defun story-set-state-json/post (params)
(lambda (params) (if (logged-in-p)
(if (logged-in-p) (let* ((id (getf params :|id|))
(let* ((id (getf params :|id|)) (current-state (story-get-state 'story id))
(current-state (story-get-state 'story id)) (next (ecase (intern current-state :scrumli)
(next (ecase (intern current-state :scrumli) (todo "DOING")
(todo "DOING") (doing "DONE")
(doing "DONE") (done "TODO"))))
(done "TODO")))) (story-set-state 'story id next)
(story-set-state 'story id next) (list 200 '(:content-type "text/json")
(list 200 '(:content-type "text/json") (encode-json-to-string `((status . "ok")
(encode-json-to-string `((status . "ok") (state . ,next)))))
(state . ,next))))) '(403)))
'(403))))
(setf (route *app* "/tasks/state" :method :post) (defun task-set-state-json/post (params)
(lambda (params) (if (logged-in-p)
(if (logged-in-p) (let* ((id (getf params :|id|))
(let* ((id (getf params :|id|)) (current-state (story-get-state 'task id))
(current-state (story-get-state 'task id)) (next (ecase (intern current-state :scrumli)
(next (ecase (intern current-state :scrumli) (todo "DOING")
(todo "DOING") (doing "DONE")
(doing "DONE") (done "TODO"))))
(done "TODO")))) (story-set-state 'task id next)
(story-set-state 'task id next) (list 200 '(:content-type "text/json")
(list 200 '(:content-type "text/json") (encode-json-to-string `((status . "ok")
(encode-json-to-string `((status . "ok") (state . ,next)))))
(state . ,next))))) '(403)))
'(403))))
(setf (route *app* "/stories/:dir" :method :post) (defun story-move-json/post (params)
(lambda (params) (if (logged-in-p)
(if (logged-in-p) (let ((id (getf params :|id|))
(let ((id (getf params :|id|)) (dir (getf params :dir)))
(dir (getf params :dir))) (story-change-priority
(story-change-priority 'story id (intern (string-upcase dir) :keyword))
'story id (intern (string-upcase dir) :keyword)) (list 200 '(:content-type "text/json")
(list 200 '(:content-type "text/json") (encode-json-to-string '((status . "ok")))))
(encode-json-to-string '((status . "ok"))))) '(403)))
'(403))))
(setf (route *app* "/tasks/:dir" :method :post) (defun task-move-json/post (params)
(lambda (params) (if (logged-in-p)
(if (logged-in-p) (let ((id (getf params :|id|)))
(let ((id (getf params :|id|))) (story-change-priority
(story-change-priority 'task id (intern (string-upcase (getf params :dir)) :keyword))
'task id (intern (string-upcase (getf params :dir)) :keyword)) (list 200 '(:content-type "text/json")
(list 200 '(:content-type "text/json") (encode-json-to-string '((status . "ok")))))
(encode-json-to-string '((status . "ok"))))) '(403)))
'(403))))
(setf (route *app* "/stories/:id") (defun story-json (params)
(lambda (params) (if (logged-in-p)
(if (logged-in-p) (list 200 '(:content-type "text/json")
(list 200 '(:content-type "text/json") (encode-json-to-string (get-story (getf params :id))))
(encode-json-to-string (get-story (getf params :id)))) '(403)))
'(403))))
(setf (route *app* "/story/assignee" :method :post) (defun story-set-assignee/post (params)
(lambda (params) (if (logged-in-p)
(if (logged-in-p) (progn
(progn (set-assignee 'story (getf params :|id|)
(set-assignee 'story (getf params :|id|) (getf params :|assignee|)) (getf params :|assignee|))
(list 200 '(:content-type "text/json") (list 200 '(:content-type "text/json")
(encode-json-to-string '((status . "ok"))))) (encode-json-to-string '((status . "ok")))))
'(403)))) '(403)))
(setf (route *app* "/task/assignee" :method :post) (defun task-set-assignee/post (params)
(lambda (params) (if (logged-in-p)
(if (logged-in-p) (progn
(progn (set-assignee 'task (getf params :|id|)
(set-assignee 'task (getf params :|id|) (getf params :|assignee|)) (getf params :|assignee|))
(list 200 '(:content-type "text/json") (list 200 '(:content-type "text/json")
(encode-json-to-string '((status . "ok"))))) (encode-json-to-string '((status . "ok")))))
'(403)))) '(403)))
(setf (route *app* "/js/bridge.js") (defun lisp->js-bridge (params)
(lambda (params) (declare (ignore params))
(declare (ignore params)) (list 200 '(:content-type "text/javascript")
(list 200 '(:content-type "text/javascript") (ps (var base-url (lisp (if (equal (script-name *request*) "")
(ps (var base-url (lisp (if (equal (script-name *request*) "") "/" (script-name *request*)))))))
"/" (script-name *request*))))))))
(setf (route *app* "/") #'story-list-page)
(setf (route *app* "/login") #'login-page)
(setf (route *app* "/login" :method :post) #'login-page/post)
(setf (route *app* "/logout") #'logout)
(setf (route *app* "/stories") #'stories-json)
(setf (route *app* "/stories/mine") #'user-stories-json)
(setf (route *app* "/stories/new" :method :post) #'add-story-json/post)
(setf (route *app* "/stories/tasks/new" :method :post) #'add-task-json/post)
(setf (route *app* "/stories/state" :method :post) #'story-set-state-json/post)
(setf (route *app* "/tasks/state" :method :post) #'task-set-state-json/post)
(setf (route *app* "/stories/:dir" :method :post) #'story-move-json/post)
(setf (route *app* "/tasks/:dir" :method :post) #'task-move-json/post)
(setf (route *app* "/stories/:id") #'story-json)
(setf (route *app* "/story/assignee" :method :post) #'story-set-assignee/post)
(setf (route *app* "/task/assignee" :method :post) #'task-set-assignee/post)
(setf (route *app* "/js/bridge.js") #'lisp->js-bridge)
(defun get-app () (defun get-app ()
(builder (builder