aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-05-11 20:36:18 +0100
committerChristopher Baines <mail@cbaines.net>2019-05-11 20:36:18 +0100
commit94e321ec383426c44ac9dd6abc7739f34559133e (patch)
tree818b6ef932925b7d9316385e559974dd8d85c444
parent3d004f8597083d7847c340dde55bf41f2efa2d2e (diff)
downloaddata-service-94e321ec383426c44ac9dd6abc7739f34559133e.tar
data-service-94e321ec383426c44ac9dd6abc7739f34559133e.tar.gz
Add query-parameters->string
-rw-r--r--guix-data-service/web/query-parameters.scm26
1 files changed, 26 insertions, 0 deletions
diff --git a/guix-data-service/web/query-parameters.scm b/guix-data-service/web/query-parameters.scm
index 45353b9..3140238 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
+ query-parameters->string
parse-datetime
parse-result-limit))
@@ -110,6 +111,31 @@
(processor value))))))
accepted-query-parameters))
+(define (query-parameters->string query-parameters)
+ (define (value->text value)
+ (match value
+ (#f "")
+ ((? date? date)
+ (date->string date "~1 ~3"))
+ (other other)))
+
+ (string-join
+ (concatenate
+ (map
+ (match-lambda
+ ((key . ($ <invalid-query-parameter>))
+ '())
+ ((key . value)
+ (list (simple-format #f "~A=~A"
+ key (value->text value))))
+ ((key values ...)
+ (map (lambda (value)
+ (simple-format #f "~A=~A"
+ key (value->text value)))
+ values)))
+ query-parameters))
+ "&"))
+
(define (parse-datetime s)
(catch
'misc-error