summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api.lisp16
-rw-r--r--init.lisp12
-rw-r--r--model.lisp6
-rw-r--r--package.lisp14
-rw-r--r--routes.lisp12
-rw-r--r--serialization.lisp25
-rw-r--r--utilities.lisp2
7 files changed, 50 insertions, 37 deletions
diff --git a/api.lisp b/api.lisp
index cecacb4..ca60f21 100644
--- a/api.lisp
+++ b/api.lisp
@@ -1,8 +1,8 @@
;;;; api.lisp -- http routes for dnd
-(in-package :dnd)
+(in-package :dnd.api)
-(lzb:provision-app (api)
+(lzb:provision-app ()
:title "Dungeons & Deadlines"
:version "0.1.0"
:prefix "/api"
@@ -13,13 +13,11 @@
(declare (ignore ignore))
t)
-
-
-(defendpoint* :get "/hall-of-legends" ((filter-by identity))
+(defendpoint api :get "/heroes" ()
(: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))))
+ (list :|heroes|
+ (sort (copy-seq (db:store-objects-with-class 'hero))
+ #'>
+ :key #'renown))))
diff --git a/init.lisp b/init.lisp
index 535da6c..c3382aa 100644
--- a/init.lisp
+++ b/init.lisp
@@ -1,6 +1,6 @@
;;;; init.lisp
-(in-package #:dnd)
+(in-package #:dnd.api)
(defun init-db (&optional config)
(if config
@@ -9,3 +9,13 @@
'db:mp-store
:directory (merge-pathnames "dnd-store/" (user-homedir-pathname))
:subsystems (list (make-instance 'db:store-object-subsystem)))))
+
+(defvar *dnd-arena* nil
+ "The instance of the HTTP server.")
+
+(defun conjure-arena ()
+ (setf *dnd-arena* (lzb:create-server))
+ (lzb:install-app *dnd-arena* 'api)
+ (lzb:start-server *dnd-arena*))
+
+
diff --git a/model.lisp b/model.lisp
index 8605ace..050bbfe 100644
--- a/model.lisp
+++ b/model.lisp
@@ -1,8 +1,6 @@
;;;; model.lisp -- bknr.datastore class definitions for dnd
-
-
-(in-package :dnd)
+(in-package :dnd.api)
(deftype title ()
`(member :noob))
@@ -20,7 +18,7 @@
(experience hero))
(defclass has-uid ()
- ((nuid :reader uid :initform (nuid)))
+ ((uid :reader uid :initform (nuid)))
(:metaclass db:persistent-class))
(defclass can-equip ()
diff --git a/package.lisp b/package.lisp
index 2c7bff8..ff06a36 100644
--- a/package.lisp
+++ b/package.lisp
@@ -8,8 +8,20 @@
(#:re #:cl-ppcre)
(#:json #:jonathan))
(:import-from #:lazybones
+ #:defendpoint
#:defendpoint*)
(:import-from #:derrida
#:with-plist))
-
+(defpackage #:dnd.api
+ (:use #:cl)
+ (:local-nicknames (#:db #:bknr.datastore)
+ (#:idx #:bknr.indices)
+ (#:lzb #:lazybones)
+ (#:re #:cl-ppcre)
+ (#:json #:jonathan))
+ (:import-from #:lazybones
+ #:defendpoint
+ #:defendpoint*)
+ (:import-from #:derrida
+ #:with-plist))
diff --git a/routes.lisp b/routes.lisp
deleted file mode 100644
index 56b6191..0000000
--- a/routes.lisp
+++ /dev/null
@@ -1,12 +0,0 @@
-;;;; routes.lisp -- http routes for dnd
-
-(in-package :dnd)
-
-(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
index 6579b92..d1689c1 100644
--- a/serialization.lisp
+++ b/serialization.lisp
@@ -1,13 +1,20 @@
;;;; serialization.lisp
+(in-package :dnd.api)
+(defmacro with-json-object (&body pairs)
+ (list*
+ 'json:with-object
+ (loop for (key val . more) on pairs by #'cddr
+ collect `(json:write-key-value ,key ,val))))
-(in-package :dnd)
-
-(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))))
+(defmethod json:%to-json ((hero hero))
+ (with-slots (name experience chronicle uid equipment-table) hero
+ (with-json-object
+ :|name| name
+ :|experience| experience
+ :|chronicle| chronicle
+ :|uid| uid
+ :|renown| (renown hero)
+ :|title| (hero-title hero)
+ :|class| (hero-class hero))))
diff --git a/utilities.lisp b/utilities.lisp
index b6cf16a..987ddce 100644
--- a/utilities.lisp
+++ b/utilities.lisp
@@ -1,6 +1,6 @@
;;;; utilities -- nuff said
-(in-package :dnd)
+(in-package :dnd.api)
(let ((host (uiop:hostname))