aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.lisp29
-rw-r--r--src/util.lisp20
2 files changed, 45 insertions, 4 deletions
diff --git a/src/main.lisp b/src/main.lisp
index ebd07c1..97e0ffc 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -289,6 +289,26 @@
(db:with-transaction ()
(make-instance 'api-access :contributor contributor)))
+(defun make-new-oneliner (contributor plist)
+ (print (list :contributor contributor :plist plist))
+ (with-plist
+ (oneliner commands brief description) plist
+ (print (list oneliner commands brief description))
+ (unless brief
+ (http-err 400 "Oneliner requires a breif description"))
+ (unless oneliner
+ (http-err 400 "Oneliner cannot be blank"))
+ (unless commands
+ (http-err 400 "This oneliner does not seem to involve any commands"))
+ (db:with-transaction ()
+ (make-instance 'oneliner
+ :created-by contributor
+ :description (or description "")
+ :commands commands
+ :oneliner oneliner
+ :brief brief))))
+
+
;;; ROUTE VARIABLE AND PARAMATER PARSERS
(defun an-int (string)
@@ -362,7 +382,8 @@
(defendpoint* :post "/add-oneliner" ()
(:auth t)
- )
+ (make-new-oneliner (request-contributor) (lzb:request-body))
+ "true")
;; (defendpoint* :get "/search" ((commands a-csl)
;; (keywords a-csl )
@@ -527,8 +548,8 @@ names. NAME must be a symbol or a string."
(jonathan:*null-value* :null))
(jonathan:to-json thing)))
-;; (defun request-contributor ()
-;; (a:when-let (access (access-by-token (lzb:request-cookie +auth-cookie-name+)))
-;; (api-contributor access)))
+(defun request-contributor ()
+ (a:when-let (access (access-by-token (lzb:request-cookie +auth-cookie-name+)))
+ (api-contributor access)))
diff --git a/src/util.lisp b/src/util.lisp
new file mode 100644
index 0000000..2fc079b
--- /dev/null
+++ b/src/util.lisp
@@ -0,0 +1,20 @@
+;;;; util.lisp -- some utilities
+
+(in-package :oneliners.api)
+
+(defun plist-find (indicator plist &key (test 'eq) (key 'identity))
+ (loop for (ind val . more) on plist by #'cddr
+ when (funcall test indicator (funcall key ind))
+ return val))
+
+(defmacro with-plist ((&rest keys) plist &rest body)
+ (let ((the-plist (gensym)))
+ `(let ((,the-plist ,plist))
+ (let
+ ,(loop for key in keys
+ collect `(,key (plist-find (symbol-name ',key)
+ ,the-plist
+ :test #'string-equal
+ :key #'symbol-name)))
+ ,@body))))
+