package fr.pizzeria.admin.jaxrs;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import fr.pizzeria.admin.metier.PizzaService;
import fr.pizzeria.exception.DaoException;
import fr.pizzeria.model.Pizza;

@Path("/pizzas")
public class PizzaResource {
	@Inject private PizzaService pizzaService;

	public PizzaResource() {
		// TODO Auto-generated constructor stub
	}

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public List<Pizza> findAllPizzas() throws DaoException {
		// pizze : pluriel de pizza (italien)
		return pizzaService.findAllPizzas();
		 
		
	}
	
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	public void savePizza(Pizza newPizza) throws DaoException {
		pizzaService.savePizza(newPizza);
//		return newPizza;
	}
	
	@PUT
	@Consumes(MediaType.APPLICATION_JSON)
	public void updatePizza(Pizza updatePizza) throws DaoException {
		pizzaService.updatePizza(updatePizza.getCode(), updatePizza);
//		return updatePizza;
	}
	
	@DELETE
	@Path("/{code}")
	public void deletePizza(@PathParam("code") String codePizza) throws DaoException {
		pizzaService.deletePizza(codePizza);
	}
	
	
}

@@ -354,16 +354,100 @@
 diaType;
+%0Aimport javax.ws.rs.core.Response;%0Aimport javax.ws.rs.core.Response.ResponseBuilder;
 %0A%0Aimport
@@ -782,19 +782,16 @@
 lic 
-List%3CPizza%3E
+Response
  fin
@@ -831,55 +831,74 @@
 %7B%0A%09%09
-// pizze : pluriel de pizza (italien)%0A%09%09return 
+ResponseBuilder respBuilder = Response.ok();%0A%09%09respBuilder.entity(
 pizz
@@ -925,16 +925,114 @@
 as()
+)
 ;%0A%09%09
- %0A%09%09
+respBuilder.header(%22Access-Control-Allow-Origin%22, %22http://localhost%22);%0A%09%09return respBuilder.build();%0A
 %0A%09%7D%0A

{List<Pizza> -> Response} findAllPizzas()