Commit 6e74cbc3 by Antti Jaakkola

Merge branch 'productrest' into 'master'

Product rest

Fetch all products over rest

See merge request !312
2 parents 89cff9f2 c7024c7e
package fi.codecrew.moya.rest.v2;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.wordnik.swagger.annotations.Api;
import fi.codecrew.moya.beans.ProductBeanLocal;
import fi.codecrew.moya.rest.v2.pojo.ProductPojo;
@RequestScoped
@Path("/v2/product")
@Api(value = "/v2/product", description = "Product operations")
public class ProductRestView {
@EJB
private ProductBeanLocal prodbean;
@GET
@Path("/all")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllProducts() {
List<ProductPojo> ret = ProductPojo.convert(prodbean.findProductsForEvent());
return Response.ok(ret).build();
}
}
package fi.codecrew.moya.rest.v2.pojo;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import com.wordnik.swagger.annotations.ApiModel;
import fi.codecrew.moya.model.Product;
@XmlRootElement()
@ApiModel(description = "Product")
public class ProductPojo {
public Integer id;
public String description;
public BigDecimal price;
public String name;
public static ProductPojo convert(Product prod) {
ProductPojo ret = new ProductPojo();
ret.id = prod.getId();
ret.name = prod.getName();
ret.price = prod.getPrice();
ret.description = prod.getDescription();
return ret;
}
public static List<ProductPojo> convert(List<Product> prods) {
ArrayList<ProductPojo> ret = new ArrayList<>();
for (Product p : prods) {
ret.add(convert(p));
}
return ret;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!