aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-02-21 16:17:08 -0600
committerColin Okay <okay@toyful.space>2022-02-21 16:17:08 -0600
commitb4448ff7152f30f3da3e19ee2160d4ffabb01ada (patch)
tree20151619e2757e71bd09087b0050395c3e25562f
parente604387cce370cd758e504715075e19f44bd6aca (diff)
ensuring runstyle can be added, edited, and returned
-rw-r--r--src/main.lisp34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/main.lisp b/src/main.lisp
index 2c5f466..261d722 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -154,7 +154,7 @@
(with-slots
(db::id oneliner tags brief explanation
created-at edited-at last-edited-by created-by
- flagged-by audited-by lockedp)
+ flagged-by audited-by lockedp runstyle)
instance
(json:with-object
(json:write-key-value :id db::id)
@@ -162,6 +162,7 @@
(json:write-key-value :tags tags)
(json:write-key-value :brief brief)
(json:write-key-value :explanation explanation)
+ (json:write-key-value :runstyle runstyle)
(json:write-key-value :createdAt created-at)
(json:write-key-value :editedAt (if edited-at edited-at :null))
(json:write-key-value :createdBy (contributor-handle created-by))
@@ -319,7 +320,7 @@
(a:when-let ((access (access-by-contributor contributor)))
(revoke-access access))))
-(defun make-new-oneliner (contributor oneliner tags brief explanation runstyle)
+(defun make-new-oneliner (contributor &key oneliner tags brief explanation runstyle)
(db:with-transaction ()
(make-instance 'oneliner
:created-by contributor
@@ -327,7 +328,7 @@
:tags tags
:oneliner oneliner
:brief brief
- :runstyle (or runstyle :auto))))
+ :runstyle (if runstyle (a:make-keyword runstyle) :auto))))
(defun unflag-oneliner (oneliner)
@@ -482,25 +483,30 @@ have exceeded the invite limit."
"On success, return an object containing a new [invite token](#invite-token)."
(to-json (make-new-invite (api-contributor token))))
-(defendpoint* :post "/oneliner" ((token an-api-token))
- (:auth t)
- "Make a new [oneliner](#oneliner)."
+(defun validate-new-oneliner-plist (plist)
(with-plist
- (oneliner tags brief explanation runstyle) (lzb:request-body)
+ (oneliner tags brief runstyle) plist
+ (unless tags
+ (http-err 400 "A oneliner requires tags"))
(unless brief
(http-err 400 "Oneliner requires a brief explanation"))
+ (unless (<= (length brief) +oneliner-brief-max-length+)
+ (http-err 400 "Brief description is too long. Limit to 75 characters"))
(unless oneliner
(http-err 400 "Oneliner cannot be blank"))
(when runstyle
(setf runstyle (a:make-keyword runstyle))
(unless (typep runstyle 'runstyle)
- (http-err 400 "Invalid runstyle.")))
- (make-new-oneliner (api-contributor token)
- oneliner
- tags
- brief
- explanation
- runstyle))
+ (http-err 400 "Invalid runstyle. Must be AUTO or MANUAL")))))
+
+(defendpoint* :post "/oneliner" ((token an-api-token))
+ (:auth t)
+ "Make a new [oneliner](#oneliner)."
+ (validate-new-oneliner-plist (lzb:request-body))
+ (apply 'make-new-oneliner
+ (api-contributor token)
+ (lzb:request-body))
+
"true")
(defun admin-only ()