Commit 33d9de06 by Patryk Czarnik

"application/pdf" w RProducts

parent eccb0d84
...@@ -16,6 +16,7 @@ import sklep.db.DBException; ...@@ -16,6 +16,7 @@ import sklep.db.DBException;
import sklep.db.ProductDAO; import sklep.db.ProductDAO;
import sklep.db.RecordNotFound; import sklep.db.RecordNotFound;
import sklep.model.Product; import sklep.model.Product;
import sklep.model.ProductList;
/* W tej klasie wejdziemy nawet do wnętrza produktów i udostępnimy osobno cenę /* W tej klasie wejdziemy nawet do wnętrza produktów i udostępnimy osobno cenę
* /products/2/price * /products/2/price
...@@ -32,11 +33,11 @@ import sklep.model.Product; ...@@ -32,11 +33,11 @@ import sklep.model.Product;
public class RProducts { public class RProducts {
@GET @GET
@Produces({"application/json", "application/xml", "text/plain"}) @Produces({"application/json", "application/xml", "text/plain", "application/pdf"})
public List<Product> readAll() throws DBException { public ProductList readAll() throws DBException {
try(DBConnection db = DBConnection.open()) { try(DBConnection db = DBConnection.open()) {
ProductDAO productDAO = db.productDAO(); ProductDAO productDAO = db.productDAO();
return productDAO.readAll(); return new ProductList(productDAO.readAll());
} }
} }
...@@ -45,7 +46,7 @@ public class RProducts { ...@@ -45,7 +46,7 @@ public class RProducts {
@GET @GET
@Produces("text/html;charset=UTF-8") @Produces("text/html;charset=UTF-8")
public String readAllHTML() throws DBException { public String readAllHTML() throws DBException {
List<Product> products = readAll(); List<Product> products = readAll().getProducts();
StringBuilder txt = new StringBuilder("<!DOCTYPE html>\n<html><body>\n"); StringBuilder txt = new StringBuilder("<!DOCTYPE html>\n<html><body>\n");
txt.append("<h1>Lista produktów</h1>\n"); txt.append("<h1>Lista produktów</h1>\n");
for(Product product : products) { for(Product product : products) {
...@@ -56,7 +57,7 @@ public class RProducts { ...@@ -56,7 +57,7 @@ public class RProducts {
} }
@GET @GET
@Produces({"application/json", "application/xml", "text/plain"}) @Produces({"application/json", "application/xml", "text/plain", "application/pdf"})
@Path("/{id}") @Path("/{id}")
public Product readOne(@PathParam("id") int productId) throws DBException, RecordNotFound { public Product readOne(@PathParam("id") int productId) throws DBException, RecordNotFound {
try(DBConnection db = DBConnection.open()) { try(DBConnection db = DBConnection.open()) {
......
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