router.lisp 2.74 KB
;;; pr0nage :: PR0ject maNAGEment
;;; Copyright (C) 2016 Aaron E Krohn
;;;
;;; This program is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU General Public License
;;; as published by the Free Software Foundation; either version 2
;;; of the License, or (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

(in-package :pr0nage)

;;;;;;;
;; Dispatchers
;;;;;;;
;;; Like .htaccess rules, order matters here. You are pushing the dispatchers
;;; onto a stack which is executed in order, from the beginning. The first
;;; entry to match the request URI is going to trigger the associated handler.
;;;
;;; e.g. if you push "/projects/add" before "/projects", the former will be
;;; lower on the stack than the latter. So the former will match before the
;;; latter and you will never reach the latter with your request.

(in-package :pr0nage)

(defparameter dispatchers
  (list
    ;; Index page dispatcher
    (create-prefix-dispatcher "/" 'action-items-list-filter-page)

    ;; Directories dispatcher
    (create-folder-dispatcher-and-handler "/img/" (web-rp-str "img/"))
    (create-folder-dispatcher-and-handler "/css/" (web-rp-str "css/"))

    ;; Fixed URL dispatchers... except for the first one.
    (create-prefix-dispatcher "/objectives"         'action-items-list-filter-page)    
    (create-regex-dispatcher  "/objectives/.*"      'action-items-list-filter-page)
    (create-prefix-dispatcher "/objective/new"      'action-item-create-page)
    (create-prefix-dispatcher "/objective/add"      'action-item-create-data)
    (create-prefix-dispatcher "/objectives/report"  'action-items-text-summary-page)

    ;; Regex dispatchers
    (create-regex-dispatcher "/objective/(-?\\d+)"                     'action-item-view-redirect)
    (create-regex-dispatcher "/objective/(-?\\d+)/save"                'action-item-update-data)
    (create-regex-dispatcher "/objective/(-?\\d+)/edit"                'action-item-update-page)
    (create-regex-dispatcher "/objective/(-?\\d+)/view"                'action-item-view-page)
    (create-regex-dispatcher "/objective/(-?\\d+)/mark"                'action-item-set-status-data)
    (create-regex-dispatcher "/objective/(-?\\d+)/prioritize/(-?\\d+)" 'action-item-set-priority-data)

  ))

(dolist (dispatcher dispatchers)
  (push dispatcher *dispatch-table*))