aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-05-19 21:26:38 +0100
committerChristopher Baines <mail@cbaines.net>2019-05-19 21:26:38 +0100
commit0a7e6a76f332813f6b1d37db026fa8ce5243784c (patch)
tree561f20a73643e0da16b899c72c69fa9cc18f5b04
parent9f94e3278eb0b9df82d0035e19476498ad2c3484 (diff)
downloaddata-service-0a7e6a76f332813f6b1d37db026fa8ce5243784c.tar
data-service-0a7e6a76f332813f6b1d37db026fa8ce5243784c.tar.gz
Add #:no-default-when option to parse-query-parameters
Where there are multiple interrelated fields, then it's useful to only apply the default if another field hasn't been specified.
-rw-r--r--guix-data-service/web/query-parameters.scm15
1 files changed, 15 insertions, 0 deletions
diff --git a/guix-data-service/web/query-parameters.scm b/guix-data-service/web/query-parameters.scm
index 41e9beb..12ac4c6 100644
--- a/guix-data-service/web/query-parameters.scm
+++ b/guix-data-service/web/query-parameters.scm
@@ -150,6 +150,21 @@
(() (cons name default))
(x (cons name x))))
+ ((name processor #:no-default-when fields #:default default)
+ (let ((use-default?
+ (every (lambda (field)
+ (not (memq field fields)))
+ fields)))
+ (match (assq name request-query-parameters)
+ (#f (if use-default?
+ (cons name default)
+ #f))
+ ((_ . "") (if use-default?
+ (cons name default)
+ #f))
+ ((_ . value) (cons name
+ (processor value))))))
+
((name processor #:default default)
(match (assq name request-query-parameters)
(#f (cons name default))