package com.example.helloworld.resources;

import com.codahale.metrics.annotation.Timed;
import com.example.helloworld.api.Saying;
import com.example.helloworld.core.Template;
import com.google.common.base.Optional;
import io.dropwizard.jersey.caching.CacheControl;
import io.dropwizard.jersey.params.DateTimeParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

@Path("/hello-world")
@Produces(MediaType.APPLICATION_JSON)
public class HelloWorldResource {
    private static final Logger LOGGER = LoggerFactory.getLogger(HelloWorldResource.class);

    private final Template template;
    private final AtomicLong counter;

    public HelloWorldResource(Template template) {
        this.template = template;
        this.counter = new AtomicLong();
    }

    @GET
    @Timed(name = "get-requests")
    @CacheControl(maxAge = 1, maxAgeUnit = TimeUnit.DAYS)
    public Saying sayHello(@QueryParam("name") Optional<String> name) {
        return new Saying(counter.incrementAndGet(), template.render(name));
    }

    @POST
    public void receiveHello(@Valid Saying saying) {
        LOGGER.info("Received a saying: {}", saying);
    }
    
    @GET
    @Path("/date")
    public void receiveDate(@QueryParam("date") DateTimeParam dateTimeParam) {
        LOGGER.info("Received a saying: {}", dateTimeParam.get());
    }
}

@@ -1321,13 +1321,9 @@
   %7D%0A
-    
 %0A
+
     
@@ -1346,16 +1346,52 @@
 /date%22)%0A
+    @Produces(MediaType.TEXT_PLAIN)%0A
     publ
@@ -1385,36 +1385,38 @@
 AIN)%0A    public 
-void
+String
  receiveDate(@Qu
@@ -1432,16 +1432,25 @@
 %22date%22) 
+Optional%3C
 DateTime
@@ -1454,16 +1454,17 @@
 imeParam
+%3E
  dateTim
@@ -1469,24 +1469,144 @@
 imeParam) %7B%0A
+        if (dateTimeParam.isPresent()) %7B%0A            final DateTimeParam actualDateTimeParam = dateTimeParam.get();%0A    
         LOGG
@@ -1629,42 +1629,194 @@
 d a 
-saying
+date
 : %7B%7D%22, 
-dateTimeParam.get());
+actualDateTimeParam);%0A            return actualDateTimeParam.get().toString();%0A        %7D else %7B%0A            LOGGER.warn(%22No received date%22);%0A            return null;%0A        %7D
 %0A   

Update an example of using query parameters