aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-02-15 11:17:02 -0600
committerColin Okay <okay@toyful.space>2022-02-15 11:17:02 -0600
commit55cbb146e64eac0d5ce5188f66551aa1a6dd9e97 (patch)
treef5fe7eeb9d4e51d5d94c03ad68444668f9e8fb14
parenta5c0dc58ae1acd4f934e2dd116e80890c1bd1a54 (diff)
adding oneliners
-rw-r--r--oneliners.api.asd3
-rw-r--r--src/main.lisp29
-rw-r--r--src/util.lisp20
3 files changed, 47 insertions, 5 deletions
diff --git a/oneliners.api.asd b/oneliners.api.asd
index 2091136..db307e4 100644
--- a/oneliners.api.asd
+++ b/oneliners.api.asd
@@ -11,7 +11,8 @@
"lambda-riffs")
:components ((:module "src"
:components
- ((:file "main"))))
+ ((:file "util")
+ (:file "main"))))
:description ""
:in-order-to ((test-op (test-op "oneliners.api/tests"))))
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))))
+