Skip to content

Instantly share code, notes, and snippets.

@tfennelly
Last active December 25, 2015 02:19
Show Gist options
  • Save tfennelly/6902232 to your computer and use it in GitHub Desktop.
Save tfennelly/6902232 to your computer and use it in GitHub Desktop.
package com.cloudbees.weave.sample.shopping;
import com.cloudbees.weave.sample.shopping.model.Customer;
import com.cloudbees.weave.sample.shopping.model.Response;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.util.ArrayList;
import java.util.List;
@Path("/api/customer")
@Produces("application/json")
@Consumes("application/json")
public class CustomerService {
private static List<Customer> customerDatabase = new ArrayList<Customer>();
@POST
@Path("/created")
public void created(Customer customer) {
System.out.println("\n*****************************************************************");
System.out.println("Customer added to CustomerService: [" + customer + "].");
System.out.println("*****************************************************************\n");
customerDatabase.add(customer);
}
/**
* Get a list of all customers.
* @return All customers response.
*/
@GET
public Response getAll() {
Response response = Response.success(null);
response.data = customerDatabase;
return response;
}
static {
customerDatabase.add(Customer.newCustomer("1", "Winston", "Churchill", "[email protected]"));
customerDatabase.add(Customer.newCustomer("2", "Charles", "de Gaulle", "[email protected]"));
customerDatabase.add(Customer.newCustomer("3", "Franklin D", "Roosevelt", "[email protected]"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment