aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clpmfile.lock2
-rw-r--r--src/main.lisp112
2 files changed, 59 insertions, 55 deletions
diff --git a/clpmfile.lock b/clpmfile.lock
index f1412ff..da11900 100644
--- a/clpmfile.lock
+++ b/clpmfile.lock
@@ -73,7 +73,7 @@
("lazybones" :version (:commit "128f72863fa3f736c93175267beb23292e70e096")
:source :implicit-vcs :systems ("lazybones" "lazybones-hunchentoot"))
("lazybones-client" :version
- (:commit "22a1c72874e579858d6add4f2b617495acc7cd4d") :source :implicit-vcs
+ (:commit "42253bda23237c918edf73b790d98aad16a44b3c") :source :implicit-vcs
:systems ("lazybones-client"))
("lisp-namespace" :version "2021-10-21" :source "quicklisp" :systems
("lisp-namespace"))
diff --git a/src/main.lisp b/src/main.lisp
index ddfcc20..0dcc5cd 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -258,57 +258,66 @@
;; presently if the token merely exists then that's good enough.
(request-contributor))
-;;; ENDPOINT DEFINITIONS
+;;; ROUTE VARIABLE AND PARAMATER PARSERS
-(defendpoint* :get "/search" () ()
- "A search endpoint returning a JSON encoded array of Oneliner Entries.
+(defun an-int (string)
+ "An Integer")
+
+(defun a-csl (s)
+ "A list of strings separated by commas. e.g. \"foo,bar,goo\""
+ (mapcar #'str:trim (str:split "," s)))
+
+(defun a-boolean (s)
+ "Either \"true\" or \"false\"/"
+ (cond ((string-equal s "true") t)
+ ((string-equal s "false") nil)
+ (t (error "String ~s is neither 'true' nor 'false'" s))))
+
+(defun a-page-key (key)
+ "A page key"
+ key)
-/search accepts the following query parameters:
+;;; ENDPOINT DEFINITIONS
-- commands : A comma-separated list of commands. E.g. `'ls,grep'`
-- keywords : A comma-separated list of words that may appear in the title or description, e.g. `'foo,bar,goo,zar,moo_blar'
-- limit : An integer, limiting the number of results returned. Defaults to 10.
-- nextpage : true or false; requests that the query be accompanied by a nextpage key
-- page : a nextpage token that will continue from a previous search. These expire after 10 minutes.
-- notFlagged : true or false; defaults to false. true filters out oneliners that have been flagged.
-- onlyAudited : true or false; defaults to false. true filters out oneliners that have not been audited.
+(defendpoint* :get "/search" ((commands a-csl)
+ (keywords a-cls)
+ (limit an-int)
+ (page a-page-key)
+ (nextpage a-boolean)
+ (notflagged a-boolean)
+ (onlyaudited a-boolean))
+ ()
+ "A search endpoint returning a JSON encoded array of Oneliner Entries.
**Note**: either command or keywords are required.
"
- (lzb:map-parameters
- ((commands parse-cls)
- (keywords parse-cls)
- (limit parse-integer)
- (nextpage true-or-false)
- (page identity)
- (notflagged true-or-false)
- (onlyaudited true-or-false))
- (cond
- ;; if page is incluced, ignore everything, fetch the next page,
- ;; and return it.
- (page
- (to-json (fetch-next-page page)))
-
- ;; otherwise one of command keywords are required
- ((or commands keywords)
- (let* ((limit
- (or limit 10)) ; default-limit, should probably be configurable.
- (results
- (query-oneliners :commands commands
- :keywords keywords
- :notflagged notflagged
- :onlyaudited onlyaudited))
- (limited-results
- (a:subseq* results 0 limit)))
- (to-json
- (if nextpage
- (list
- :page (make-next-page limit (nthcdr limit results))
- :oneliners limited-results)
- (list :oneliners limited-results)))))
- ;; if neither command nor keywords were supplied, return a 400
- (t
- (http-err 400)))))
+ (print commands)
+ (cond
+ ;; if page is incluced, ignore everything, fetch the next page,
+ ;; and return it.
+ (page
+ (to-json (fetch-next-page page)))
+
+ ;; otherwise one of command keywords are required
+ ((or commands keywords)
+ (let* ((limit
+ (or limit 10)) ; default-limit, should probably be configurable.
+ (results
+ (query-oneliners :commands commands
+ :keywords keywords
+ :notflagged notflagged
+ :onlyaudited onlyaudited))
+ (limited-results
+ (a:subseq* results 0 limit)))
+ (to-json
+ (if nextpage
+ (list
+ :page (make-next-page limit (nthcdr limit results))
+ :oneliners limited-results)
+ (list :oneliners limited-results)))))
+ ;; if neither command nor keywords were supplied, return a 400
+ (t
+ (http-err 400))))
(defendpoint* :put "/oneliner/:oneliner object-with-id:" () (:auth t)
"Updates a oneliner entry in the wiki database."
@@ -316,9 +325,9 @@
(oneliner
(update-oneliner (request-contributor)
oneliner
- (lzb:request-body)) ; throws an error if fails, triggering a 500
+ (lzb:request-body))
"true")
- (t (http-err 404)))) ;no oneliner with the given id.
+ (t (http-err 404))))
(defendpoint* :post "/oneliner" () (:auth t)
"Adds a new oneliner entry to the wiki database."
@@ -396,14 +405,9 @@ names. NAME must be a symbol or a string."
(defun uuid ()
(format nil "~a" (uuid:make-v1-uuid)))
-(defun parse-cls (s)
- "parse comman separated list."
- (mapcar #'str:trim (str:split "," s)))
-(defun parse-true-or-false (s)
- (cond ((string-equal s "true") t)
- ((string-equal s "false") nil)
- (t (error "String ~s is neither 'true' nor 'false'" s))))
+
+
(defun oneliner-mentions-any (ol keywords)
"A case insensitive search for the presence of any of KEYWORDS in the oneliner OL."