diff options
author | Christopher Baines <mail@cbaines.net> | 2019-05-11 20:34:53 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2019-05-11 20:34:53 +0100 |
commit | 3d004f8597083d7847c340dde55bf41f2efa2d2e (patch) | |
tree | 61db5b50b872c9a3875710f52268bc2648fe80f0 | |
parent | bec838caf95ae154ead22e109217186cfc858670 (diff) | |
download | data-service-3d004f8597083d7847c340dde55bf41f2efa2d2e.tar data-service-3d004f8597083d7847c340dde55bf41f2efa2d2e.tar.gz |
Add #:required and #:multi-value support to parse-query-parameters
-rw-r--r-- | guix-data-service/web/query-parameters.scm | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/guix-data-service/web/query-parameters.scm b/guix-data-service/web/query-parameters.scm index 0809791..45353b9 100644 --- a/guix-data-service/web/query-parameters.scm +++ b/guix-data-service/web/query-parameters.scm @@ -59,7 +59,8 @@ accepted-query-parameters) (define request-query-parameters (let ((query (uri-query (request-uri request)))) - (if query + (if (and query + (not (string-null? query))) (map (match-lambda ((name . value) (cons (string->symbol name) @@ -75,6 +76,32 @@ ((_ . "") #f) ((_ . value) (cons name (processor value))))) + + ((name processor #:required) + (match (assq name request-query-parameters) + (#f (cons name + (make-invalid-query-parameter + #f "this value is required."))) + ((_ . "") (cons name + (make-invalid-query-parameter + #f "this value is required."))) + ((_ . value) (cons name + (processor value))))) + + ((name processor #:multi-value) + (match (filter-map + (match-lambda + ((k . value) + (and + (eq? k name) + (match value + (#f #f) + ("" #f) + (value (processor value)))))) + request-query-parameters) + (() #f) + (x (cons name x)))) + ((name processor #:default default) (match (assq name request-query-parameters) (#f (cons name default)) |