From fae634e711ae4348a86e007b118a8b5794201299 Mon Sep 17 00:00:00 2001 From: Ricardo Romero Date: Fri, 26 Jan 2024 19:29:34 +0100 Subject: [PATCH] Fixed query params for lists --- .../src/route/dartness_router_handler.dart | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/packages/dartness_server/lib/src/route/dartness_router_handler.dart b/packages/dartness_server/lib/src/route/dartness_router_handler.dart index 69d5253a..0e7cc744 100644 --- a/packages/dartness_server/lib/src/route/dartness_router_handler.dart +++ b/packages/dartness_server/lib/src/route/dartness_router_handler.dart @@ -46,12 +46,20 @@ class DartnessRouterHandler { } else { if (param.isPath) { final pathParam = _getPathParam(request, param); - final value = pathParam.stringToType(param.type); - namedArguments[Symbol(param.name)] = value; + if (pathParam is String) { + final value = pathParam.stringToType(param.type); + namedArguments[Symbol(param.name)] = value; + } else { + namedArguments[Symbol(param.name)] = pathParam; + } } else { - final String? queryParam = _getQueryParam(request, param); - final value = queryParam?.stringToType(param.type); - namedArguments[Symbol(param.name)] = value; + final Object? queryParam = _getQueryParam(request, param); + if (queryParam is String) { + final value = queryParam.stringToType(param.type); + namedArguments[Symbol(param.name)] = value; + } else { + namedArguments[Symbol(param.name)] = queryParam; + } } } } @@ -87,9 +95,15 @@ class DartnessRouterHandler { ); } - dynamic _getQueryParam(Request request, DartnessParam param) => - request.url.queryParameters[param.name] ?? param.defaultValue; + Object? _getQueryParam(final Request request, final DartnessParam param) { + final all = request.url.queryParametersAll; + final foundAll = all[param.name]; + if (foundAll != null && foundAll.length > 1) { + return all[param.name]; + } + return request.url.queryParameters[param.name] ?? param.defaultValue; + } - dynamic _getPathParam(Request request, DartnessParam param) => + Object? _getPathParam(final Request request, final DartnessParam param) => request.params[param.name] ?? param.defaultValue; }