package edu.utah.nanofab.coralapiserver.resources;

import edu.utah.nanofab.coralapiserver.auth.User;
import edu.utah.nanofab.coralapiserver.core.ReservationRequest;
import edu.utah.nanofab.coralapiserver.resources.operations.EnableOperationPost;
import edu.utah.nanofab.coralapiserver.resources.operations.ReservationOperationPost;

import org.slf4j.Logger;

import com.google.common.base.Optional;

import io.dropwizard.auth.Auth;

import com.codahale.metrics.annotation.Timed;

import javax.validation.Valid;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.slf4j.LoggerFactory;

import java.util.concurrent.atomic.AtomicLong;

@Path("/v0/reservation")
@Produces(MediaType.APPLICATION_JSON)
public class CoralApiReservationResource {
  
  private String coralConfigUrl;
  public static final Logger logger = LoggerFactory.getLogger(CoralApiReservationResource.class);

  public CoralApiReservationResource(String coralConfigUrl ) {
      this.coralConfigUrl = coralConfigUrl;
      new AtomicLong();
  }

  @POST
  @Timed
  public ReservationRequest createRequest(@Valid ReservationRequest request, @Auth User user) {
    ReservationOperationPost operation = new ReservationOperationPost();
    operation.init(
        this.coralConfigUrl, 
        Optional.<String> absent(), 
        Optional.<Object>of( request ), 
        user);
    return (ReservationRequest) (operation.perform());
  }
    
}

@@ -45,16 +45,165 @@
 urces;%0A%0A
+import edu.utah.nanofab.coralapi.CoralAPI;%0Aimport edu.utah.nanofab.coralapi.resource.Project;%0Aimport edu.utah.nanofab.coralapi.resource.Reservation;%0A
 import e
@@ -244,16 +244,16 @@
 h.User;%0A
-
 import e
@@ -385,24 +385,105 @@
 rationPost;%0A
+import edu.utah.nanofab.coralapiserver.resources.operations.ProjectOperationGet;%0A
 import edu.u
@@ -735,16 +735,40 @@
 .Valid;%0A
+import javax.ws.rs.GET;%0A
 import j
@@ -838,16 +838,47 @@
 oduces;%0A
+import javax.ws.rs.QueryParam;%0A
 import j
@@ -938,16 +938,39 @@
 ctory;%0A%0A
+import java.util.Date;%0A
 import j
@@ -1715,16 +1715,16 @@
  user);%0A
-
     retu
@@ -1774,15 +1774,506 @@
 ));%0A  %7D%0A
+  %0A  @GET%0A  @Timed%0A  public Reservation%5B%5D getRequest(@QueryParam(%22machine%22) Optional%3CString%3E machine, @Auth User user) throws Exception %7B%0A%09  CoralAPI coralApiInstance = new CoralAPI(user.getUsername(), this.coralConfigUrl);%0A%09  Date bdate = new Date();%0A%09  Date edate = new Date();%0A%09  long edateMS = bdate.getTime();%0A%09  edateMS += (30L * 24L * 60L * 60L * 1000L);%0A%09  edate.setTime(edateMS); //30 days in the future;%0A%09  return coralApiInstance.getReservations(machine.get(), bdate, edate);%0A  %7D%0A
     %0A%7D%0A

Add GET request for reservation resource