aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix-data-service/web/query-parameters.scm32
1 files changed, 32 insertions, 0 deletions
diff --git a/guix-data-service/web/query-parameters.scm b/guix-data-service/web/query-parameters.scm
index 3140238..66edb64 100644
--- a/guix-data-service/web/query-parameters.scm
+++ b/guix-data-service/web/query-parameters.scm
@@ -36,6 +36,7 @@
any-invalid-query-parameters?
parse-query-parameters
+ guard-against-mutually-exclusive-query-parameters
query-parameters->string
parse-datetime
@@ -56,6 +57,37 @@
(value invalid-query-parameter-value)
(message invalid-query-parameter-message))
+(define (guard-against-mutually-exclusive-query-parameters
+ parsed-query-parameters
+ mutually-exclusive-groups)
+ (map (match-lambda
+ ((name . value)
+ (if (invalid-query-parameter? value)
+ (cons name value)
+ (or
+ (any (lambda (group)
+ (if (memq name group)
+ (let ((other-names
+ (filter (lambda (other-name)
+ (and (not (eq? name other-name))
+ (memq other-name group)))
+ (map car parsed-query-parameters))))
+ (if (not (null? other-names))
+ (cons
+ name
+ (make-invalid-query-parameter
+ value
+ (string-append
+ "cannot be specified along with "
+ (string-join (map symbol->string
+ other-names)
+ ", "))))
+ #f))
+ #f))
+ mutually-exclusive-groups)
+ (cons name value)))))
+ parsed-query-parameters))
+
(define (parse-query-parameters request
accepted-query-parameters)
(define request-query-parameters