Merge pull request 'check if article.image is null' (#44) from fix/image_null into master
Reviewed-by: Jannik Seiler <seil0@mosad.xyz>
This commit is contained in:
commit
b04d627695
|
@ -148,9 +148,9 @@ public class InternArticleController {
|
||||||
File tmpFile = new File(defaultImagePath);
|
File tmpFile = new File(defaultImagePath);
|
||||||
// test if default img file exits
|
// test if default img file exits
|
||||||
if (!tmpFile.exists()) {
|
if (!tmpFile.exists()) {
|
||||||
// fallback if the file not exists
|
// fallback if the file not exists
|
||||||
// create new file
|
// create new file
|
||||||
BufferedImage bufferedImage = new BufferedImage(422, 428, BufferedImage.TYPE_INT_RGB);
|
BufferedImage bufferedImage = new BufferedImage(422, 428, BufferedImage.TYPE_INT_RGB);
|
||||||
try {
|
try {
|
||||||
ImageIO.write(bufferedImage, "jpg", new File(defaultImagePath)); // save new file on disk
|
ImageIO.write(bufferedImage, "jpg", new File(defaultImagePath)); // save new file on disk
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -208,7 +208,10 @@ public class InternArticleController {
|
||||||
public long id;
|
public long id;
|
||||||
|
|
||||||
void addListedArticle(Article article, int stock) {
|
void addListedArticle(Article article, int stock) {
|
||||||
this.imgPath = article.image.path;
|
|
||||||
|
if (article.image != null) {
|
||||||
|
this.imgPath = article.image.path;
|
||||||
|
}
|
||||||
this.title = article.title;
|
this.title = article.title;
|
||||||
this.price_netto = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100));
|
this.price_netto = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100));
|
||||||
this.price = String.format("%.2f", ((float) article.getPriceGross() / 100));
|
this.price = String.format("%.2f", ((float) article.getPriceGross() / 100));
|
||||||
|
@ -338,7 +341,9 @@ public class InternArticleController {
|
||||||
}
|
}
|
||||||
|
|
||||||
void addArticle(Article article, int stock) {
|
void addArticle(Article article, int stock) {
|
||||||
this.imgPath = article.image.path;
|
if (article.image != null) {
|
||||||
|
this.imgPath = article.image.path;
|
||||||
|
}
|
||||||
this.title = article.title;
|
this.title = article.title;
|
||||||
this.price_netto = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100));
|
this.price_netto = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100));
|
||||||
this.price = String.format("%.2f", ((float) article.getPriceGross() / 100));
|
this.price = String.format("%.2f", ((float) article.getPriceGross() / 100));
|
||||||
|
|
|
@ -100,8 +100,11 @@ public class ShopArticleController {
|
||||||
@PathVariable("id") Long id
|
@PathVariable("id") Long id
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
Article article = articleRepository.findArticleById(id);
|
Article article = articleRepository.findArticleById(id);
|
||||||
InputStream in = new FileInputStream(article.image.path);
|
|
||||||
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
|
if(article.image != null) {
|
||||||
IOUtils.copy(in, response.getOutputStream());
|
InputStream in = new FileInputStream(article.image.path);
|
||||||
|
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
|
||||||
|
IOUtils.copy(in, response.getOutputStream());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue