Commit b6b5a89d by Patryk Czarnik

PDFWriter dla wielu produktów

parent 469aa517
......@@ -13,9 +13,10 @@ import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.ext.MessageBodyWriter;
import jakarta.ws.rs.ext.Provider;
import sklep.model.Product;
import sklep.model.ProductList;
@Provider
public class PDFWriter implements MessageBodyWriter<Product> {
public class PDFWriter implements MessageBodyWriter<Object> {
private static final MediaType PDF_TYPE = new MediaType("application", "pdf");
@Context
......@@ -23,16 +24,16 @@ public class PDFWriter implements MessageBodyWriter<Product> {
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return type == Product.class && PDF_TYPE.isCompatible(mediaType);
return (type == ProductList.class || type == Product.class) && PDF_TYPE.isCompatible(mediaType);
}
@Override
public void writeTo(Product product, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
public void writeTo(Object obj, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream output)
throws IOException, WebApplicationException {
ObslugaXSL obslugaXSL = new ObslugaXSL(servletContext);
obslugaXSL.wypiszPDF(product, output);
obslugaXSL.wypiszPDF(obj, output);
}
......
......@@ -11,16 +11,17 @@ import sklep.db.DBException;
import sklep.db.ProductDAO;
import sklep.db.RecordNotFound;
import sklep.model.Product;
import sklep.model.ProductList;
@Path("/products.pdf")
@Produces("application/pdf")
public class RProductsPDF {
@GET
public List<Product> readAll() throws DBException {
public ProductList readAll() throws DBException {
try(DBConnection db = DBConnection.open()) {
ProductDAO productDAO = db.productDAO();
return productDAO.readAll();
return new ProductList(productDAO.readAll());
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment