From 3f0ef60a473b54c0ecf6a14bf73ef1a4111a3863 Mon Sep 17 00:00:00 2001 From: joshua bauer Date: Fri, 7 Apr 2017 16:35:52 -0700 Subject: [PATCH] Date and list working. --- src/main/java/com/wurrly/controllers/Users.java | 3 ++- src/main/java/com/wurrly/server/Extractors.java | 6 ++++++ .../com/wurrly/server/handlers/HandlerGenerator.java | 9 +++++++-- .../swagger/swagger-ui-standalone-preset.js.map | 0 4 files changed, 15 insertions(+), 3 deletions(-) mode change 100644 => 100755 src/main/resources/swagger/swagger-ui-standalone-preset.js.map diff --git a/src/main/java/com/wurrly/controllers/Users.java b/src/main/java/com/wurrly/controllers/Users.java index 0f83ebd..e02eb32 100644 --- a/src/main/java/com/wurrly/controllers/Users.java +++ b/src/main/java/com/wurrly/controllers/Users.java @@ -72,7 +72,7 @@ public Any userType( @QueryParam("optionalQueryString") Optional optionalQueryString, @QueryParam("optionalLong") Optional optionalLong, @QueryParam("longValue") Long longValue, - @QueryParam("date") @ApiParam(format="date") Date dateValue, + @QueryParam("dateValue") @ApiParam(format="date") Optional dateValue, @QueryParam("numbers") List numbers, @QueryParam("queryFromString") UUID queryFromString, @@ -95,6 +95,7 @@ public Any userType( log.debug("queryEnum: " + queryEnum); log.debug("optionalQueryEnum: " + optionalQueryEnum); log.debug("userId: " + userId); + log.debug("numbers: " + numbers); // diff --git a/src/main/java/com/wurrly/server/Extractors.java b/src/main/java/com/wurrly/server/Extractors.java index a3bd2e5..92edcfd 100644 --- a/src/main/java/com/wurrly/server/Extractors.java +++ b/src/main/java/com/wurrly/server/Extractors.java @@ -67,6 +67,12 @@ public static java.util.Optional typed(final HttpServerExchange exchange }); } + public static java.util.Optional date(final HttpServerExchange exchange,final String name) { + + + return string(exchange, name).map( ZonedDateTime::parse ).map(ZonedDateTime::toInstant).map(Date::from); + + } public static java.util.Optional any(final HttpServerExchange exchange ) { diff --git a/src/main/java/com/wurrly/server/handlers/HandlerGenerator.java b/src/main/java/com/wurrly/server/handlers/HandlerGenerator.java index 2ee0d14..506587e 100644 --- a/src/main/java/com/wurrly/server/handlers/HandlerGenerator.java +++ b/src/main/java/com/wurrly/server/handlers/HandlerGenerator.java @@ -110,7 +110,8 @@ public enum TypeHandler OptionalFloatType("$T $L = $T.floatValue(exchange,$S)", false, Optional.class, StatementParameterType.LITERAL, com.wurrly.server.Extractors.Optional.class, StatementParameterType.STRING), OptionalDoubleType("$T $L = $T.doubleValue(exchange,$S)", false, Optional.class, StatementParameterType.LITERAL, com.wurrly.server.Extractors.Optional.class, StatementParameterType.STRING), - + OptionalDateType("$T<$T> $L = $T.date(exchange,$S)", false, Optional.class, java.util.Date.class, StatementParameterType.LITERAL, com.wurrly.server.Extractors.Optional.class, StatementParameterType.STRING), + OptionalModelType("java.util.Optional<$L> $L = $T.typed(exchange,$L)", true, StatementParameterType.LITERAL, StatementParameterType.LITERAL, com.wurrly.server.Extractors.Optional.class, StatementParameterType.LITERAL), OptionalValueOfType("$T<$T> $L = $T.string(exchange,$S).map($T::valueOf)", false, Optional.class, StatementParameterType.RAW, StatementParameterType.LITERAL,com.wurrly.server.Extractors.Optional.class, StatementParameterType.STRING, StatementParameterType.RAW), @@ -182,7 +183,7 @@ else if (handler.parameterTypes[i] instanceof Class) } } - log.debug("type: " + parameter.getParameterizedType().getTypeName() + " : " + handler); + log.info("type: " + parameter.getParameterizedType().getTypeName() + " : " + handler); builder.addStatement(handler.statement, args); } @@ -281,6 +282,10 @@ else if (type.getTypeName().contains("java.lang.String")) { return OptionalStringType; } + else if (type.getTypeName().contains("java.util.Date")) + { + return OptionalDateType; + } else if (type.getTypeName().contains("java.lang.Boolean")) { return OptionalBooleanType; diff --git a/src/main/resources/swagger/swagger-ui-standalone-preset.js.map b/src/main/resources/swagger/swagger-ui-standalone-preset.js.map old mode 100644 new mode 100755