|
@@ -57,10 +57,11 @@
|
|
|
(defparameter +200-empty+ '(200 (:content-type "application/json")
|
|
(defparameter +200-empty+ '(200 (:content-type "application/json")
|
|
|
#.(trivial-utf-8:string-to-utf-8-bytes "{}")))
|
|
#.(trivial-utf-8:string-to-utf-8-bytes "{}")))
|
|
|
|
|
|
|
|
-(defun 200-json (data)
|
|
|
|
|
- (declare #.*standard-optimize-settings*)
|
|
|
|
|
|
|
+(defun 200-json (data &optional (dumper #'to-json))
|
|
|
|
|
+ (declare #.*standard-optimize-settings*
|
|
|
|
|
+ (type function dumper))
|
|
|
`(200 (:content-type "application/json")
|
|
`(200 (:content-type "application/json")
|
|
|
- ,(trivial-utf-8:string-to-utf-8-bytes (to-json data))))
|
|
|
|
|
|
|
+ ,(trivial-utf-8:string-to-utf-8-bytes (funcall dumper data))))
|
|
|
|
|
|
|
|
(defun get-category-list (params)
|
|
(defun get-category-list (params)
|
|
|
(declare #.*standard-optimize-settings*
|
|
(declare #.*standard-optimize-settings*
|
|
@@ -85,7 +86,7 @@
|
|
|
(declare #.*standard-optimize-settings*
|
|
(declare #.*standard-optimize-settings*
|
|
|
(type (or null string) string))
|
|
(type (or null string) string))
|
|
|
(when string
|
|
(when string
|
|
|
- (parse-integer string)))
|
|
|
|
|
|
|
+ (parse-integer string :junk-allowed t)))
|
|
|
|
|
|
|
|
(defun get-restrictions (query-params)
|
|
(defun get-restrictions (query-params)
|
|
|
(declare #.*standard-optimize-settings*
|
|
(declare #.*standard-optimize-settings*
|
|
@@ -96,7 +97,7 @@
|
|
|
(year (parse-integer value :junk-allowed t))
|
|
(year (parse-integer value :junk-allowed t))
|
|
|
(otherwise value)))))
|
|
(otherwise value)))))
|
|
|
|
|
|
|
|
-(defparameter +max-limit+ 1000)
|
|
|
|
|
|
|
+(defparameter +max-limit+ 100)
|
|
|
(defmacro with-category ((params category filter restrictions offset limit) &body body)
|
|
(defmacro with-category ((params category filter restrictions offset limit) &body body)
|
|
|
(with-gensyms (query-string query-params)
|
|
(with-gensyms (query-string query-params)
|
|
|
`(let ((,category (getsym ,params :category)))
|
|
`(let ((,category (getsym ,params :category)))
|
|
@@ -107,7 +108,8 @@
|
|
|
(,filter (aget ,query-params "filter"))
|
|
(,filter (aget ,query-params "filter"))
|
|
|
(,restrictions (get-restrictions ,query-params))
|
|
(,restrictions (get-restrictions ,query-params))
|
|
|
(,offset (or (may-integer (aget ,query-params "offset")) 0))
|
|
(,offset (or (may-integer (aget ,query-params "offset")) 0))
|
|
|
- (,limit (min (the fixnum +max-limit+) (the fixnum (or (may-integer (aget ,query-params "limit")) +max-limit+)))))
|
|
|
|
|
|
|
+ (,limit (min (the fixnum +max-limit+)
|
|
|
|
|
+ (the fixnum (or (may-integer (aget ,query-params "limit")) +max-limit+)))))
|
|
|
,@body))
|
|
,@body))
|
|
|
(otherwise +404+)))))
|
|
(otherwise +404+)))))
|
|
|
|
|
|
|
@@ -115,14 +117,27 @@
|
|
|
(declare #.*standard-optimize-settings*)
|
|
(declare #.*standard-optimize-settings*)
|
|
|
(with-category (params category filter restrictions offset limit)
|
|
(with-category (params category filter restrictions offset limit)
|
|
|
(declare (ignore offset limit))
|
|
(declare (ignore offset limit))
|
|
|
- (200-json (query-category (cdr *db*) category :filter filter :restrictions restrictions :count-only t))))
|
|
|
|
|
|
|
+ (200-json (query-category (cdr *db*) category
|
|
|
|
|
+ :filter filter :restrictions restrictions
|
|
|
|
|
+ :count-only t))))
|
|
|
|
|
+
|
|
|
|
|
+(defun dumps-category-result (results)
|
|
|
|
|
+ (with-output-to-string*
|
|
|
|
|
+ (with-array
|
|
|
|
|
+ (loop for (cat . count) in results
|
|
|
|
|
+ do (with-object
|
|
|
|
|
+ (write-key-value "item" cat)
|
|
|
|
|
+ (write-key-value "count" count))))))
|
|
|
|
|
|
|
|
(defun get-category (params)
|
|
(defun get-category (params)
|
|
|
(declare #.*standard-optimize-settings*)
|
|
(declare #.*standard-optimize-settings*)
|
|
|
(with-category (params category filter restrictions offset limit)
|
|
(with-category (params category filter restrictions offset limit)
|
|
|
(200-json (query-category (cdr *db*) category
|
|
(200-json (query-category (cdr *db*) category
|
|
|
:filter filter :restrictions restrictions
|
|
:filter filter :restrictions restrictions
|
|
|
- :limit limit :offset offset))))
|
|
|
|
|
|
|
+ :limit limit :offset offset)
|
|
|
|
|
+ (case category
|
|
|
|
|
+ (album #'to-json)
|
|
|
|
|
+ (t #'dumps-category-result)))))
|
|
|
|
|
|
|
|
(defun album-tracks (params)
|
|
(defun album-tracks (params)
|
|
|
(declare #.*standard-optimize-settings*)
|
|
(declare #.*standard-optimize-settings*)
|