diff options
-rw-r--r-- | api.lisp | 25 | ||||
-rw-r--r-- | dungeons-and-deadlines.asd | 8 | ||||
-rw-r--r-- | init.lisp | 11 | ||||
-rw-r--r-- | model.lisp | 16 | ||||
-rw-r--r-- | package.lisp | 7 | ||||
-rw-r--r-- | routes.lisp | 12 | ||||
-rw-r--r-- | serialization.lisp | 13 |
7 files changed, 84 insertions, 8 deletions
diff --git a/api.lisp b/api.lisp new file mode 100644 index 0000000..8159a1c --- /dev/null +++ b/api.lisp @@ -0,0 +1,25 @@ +;;;; api.lisp -- http routes for dnd + +(in-package :dungeons-and-deadlines) + +(lzb:provision-app (api) + :title "Dungeons & Deadlines" + :version "0.1.0" + :prefix "/api" + :content-type "application/json" + :auth 'default-auth) + +(defun default-auth (&rest ignore) + (declare (ignore ignore)) + t) + + + +(defendpoint* :get "/hall-of-legends" ((filter-by identity)) + (:auth t) + "Get a list of heros sorted by renown" + (json:to-json + (list :heroes + (sort (copy-seq (db:store-objects-with-class 'hero)) + #'> + :key #'renown)))) diff --git a/dungeons-and-deadlines.asd b/dungeons-and-deadlines.asd index dd4b586..0380db9 100644 --- a/dungeons-and-deadlines.asd +++ b/dungeons-and-deadlines.asd @@ -7,6 +7,7 @@ :version "0.0.1" :serial t :depends-on (#:lazybones + #:lazybones-hunchentoot #:bknr.datastore #:spinneret #:swank @@ -15,9 +16,12 @@ #:lass #:parenscript #:derrida - #:ironclad) + #:ironclad + #:jonathan) :components ((:file "package") (:file "utilities") + (:file "init") (:file "model") - (:file "routes") + (:file "serialization") + (:file "api") (:file "dungeons-and-deadlines"))) diff --git a/init.lisp b/init.lisp new file mode 100644 index 0000000..5603623 --- /dev/null +++ b/init.lisp @@ -0,0 +1,11 @@ +;;;; init.lisp + +(in-package #:dungeons-and-deadlines) + +(defun init-db (&optional config) + (if config + nil + (make-instance + 'db:mp-store + :directory (merge-pathnames "dnd-store/" (user-homedir-pathname)) + :subsystems (list (make-instance 'db:store-object-subsystem))))) @@ -1,6 +1,6 @@ ;;;; model.lisp -- bknr.datastore class definitions for dnd -ty + (in-package :dungeons-and-deadlines) @@ -10,12 +10,21 @@ ty (deftype character-class () `(member :hero)) +(defun hero-class (h) + "barGaryan") + +(defun hero-title (h) + "Scouse Chef") + +(defun renown (hero) + (experience hero)) + (defclass has-uid (db:store-object) ((nuid :reader uid :initform (nuid))) (:metaclass db:persistent-class)) (defclass can-equip (db:store-object) - ((equipment-slots + ((equipment-table :initform (make-hash-table)) (equipment-slot-names :initform (list :holding) @@ -40,8 +49,7 @@ ty :type integer) (chronicle :accessor hero-chronicle - :initform (list) - :type (cons string)) + :initform (list)) (pwhash :accessor pwhash :type string diff --git a/package.lisp b/package.lisp index c18b3eb..f7d0143 100644 --- a/package.lisp +++ b/package.lisp @@ -5,8 +5,11 @@ (:local-nicknames (#:db #:bknr.datastore) (#:idx #:bknr.indices) (#:lzb #:lazybones) - (#:re #:cl-ppcre)) + (#:re #:cl-ppcre) + (#:json #:jonathan)) (:import-from #:lazybones - #:defendpoint*)) + #:defendpoint*) + (:import-from #:derrida + #:with-plist)) diff --git a/routes.lisp b/routes.lisp new file mode 100644 index 0000000..7d98c74 --- /dev/null +++ b/routes.lisp @@ -0,0 +1,12 @@ +;;;; routes.lisp -- http routes for dnd + +(in-package :dungeons-and-deadlines) + +(lzb:provision-app (api) + :title "Dungeons & Deadlines" + :version "0.1.0" + :prefix "/api" + :content-type "application/json") + + + diff --git a/serialization.lisp b/serialization.lisp new file mode 100644 index 0000000..7066712 --- /dev/null +++ b/serialization.lisp @@ -0,0 +1,13 @@ +;;;; serialization.lisp + + + +(in-package :dungeons-and-deadlines) + +(defun hall-of-fame-hero-view (hero) + (json:to-json + (list :name (hero-name hero) + :uid (uid hero) + :renown (renown hero) + :title (hero-title hero) + :class (hero-class hero)))) |