From 8dd4cc4459152ff0d9306d9858f508850ed30729 Mon Sep 17 00:00:00 2001 From: Seil0 Date: Sat, 9 May 2020 19:31:57 +0200 Subject: [PATCH 01/19] use application.properties when run via bootRun --- prototype/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prototype/build.gradle b/prototype/build.gradle index 2769783..ad8b14c 100644 --- a/prototype/build.gradle +++ b/prototype/build.gradle @@ -35,5 +35,5 @@ group 'org.hso' version '0.1.0' bootRun { - args = ["--spring.profiles.active=dev"] + args = ["--spring.profiles.active=dev --spring.config.location=classpath:/application.properties\""] } From 69b5b33af80d96d2d42ef991e6241a5f8a68af45 Mon Sep 17 00:00:00 2001 From: Seil0 Date: Sat, 9 May 2020 19:58:31 +0200 Subject: [PATCH 02/19] fix typo in 8dd4cc4459 --- prototype/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prototype/build.gradle b/prototype/build.gradle index ad8b14c..c7defd9 100644 --- a/prototype/build.gradle +++ b/prototype/build.gradle @@ -35,5 +35,5 @@ group 'org.hso' version '0.1.0' bootRun { - args = ["--spring.profiles.active=dev --spring.config.location=classpath:/application.properties\""] + args = ["--spring.profiles.active=dev --spring.config.location=classpath:/application.properties"] } From 731f4761fab17d3e8df39c43a99f6285e7b4b4b0 Mon Sep 17 00:00:00 2001 From: CodeSteak Date: Sun, 10 May 2020 14:29:08 +0200 Subject: [PATCH 03/19] Show error if articles are not avail during checkout. --- .../action/shop/CreateOrderAction.java | 22 +++++++++++++++++-- .../shop/ShopCheckoutController.java | 20 ++++++++++++----- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/action/shop/CreateOrderAction.java b/prototype/src/main/java/org/hso/ecommerce/action/shop/CreateOrderAction.java index ed1066c..8b35be8 100644 --- a/prototype/src/main/java/org/hso/ecommerce/action/shop/CreateOrderAction.java +++ b/prototype/src/main/java/org/hso/ecommerce/action/shop/CreateOrderAction.java @@ -68,7 +68,8 @@ public class CreateOrderAction { totalVatCent += article.getVat() * quantity; } - public Result finish() { + + public Result finish() throws ArticleNotInStockException { CustomerOrder order = createOrder(); CustomerPayment payment = createPayment(); @@ -86,7 +87,7 @@ public class CreateOrderAction { ); } - private WarehouseBooking createWarehouseBooking(CustomerOrder order) { + private WarehouseBooking createWarehouseBooking(CustomerOrder order) throws ArticleNotInStockException { WarehouseBooking booking = new WarehouseBooking(); booking.created = new Timestamp(new Date().getTime()); booking.reason = new BookingReason(order); @@ -111,6 +112,10 @@ public class CreateOrderAction { break; } } + + if (needed > 0) { + throw new ArticleNotInStockException(item.article); + } } return booking; @@ -174,4 +179,17 @@ public class CreateOrderAction { this.quantity = quantity; } } + + public static class ArticleNotInStockException extends Exception { + private Article article; + + public ArticleNotInStockException(Article article) { + super("The quantity of article '" + article.title + "' is not in stock."); + this.article = article; + } + + public Article getArticle() { + return article; + } + } } diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopCheckoutController.java b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopCheckoutController.java index ab4827f..c2c1c3a 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopCheckoutController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopCheckoutController.java @@ -98,6 +98,7 @@ public class ShopCheckoutController { @PostMapping("/checkoutFinish") public String shopCheckoutFinish( + HttpSession session, HttpServletRequest request, HttpServletResponse response, @RequestAttribute(value = "user") User user, @@ -132,15 +133,22 @@ public class ShopCheckoutController { action.addArticle(article, item.getAmount(), wbeseRepo.getByArticle(article.id)); } - CreateOrderAction.Result result = action.finish(); + CreateOrderAction.Result result = null; + try { + result = action.finish(); + EnableTrackingAction.addTrackingInfo(result.customerOrder); - EnableTrackingAction.addTrackingInfo(result.customerOrder); + customerOderRepository.save(result.customerOrder); + bookingRepository.saveAll(result.bookings); + warehouseBookingRepository.save(result.warehouseBooking); - customerOderRepository.save(result.customerOrder); - bookingRepository.saveAll(result.bookings); - warehouseBookingRepository.save(result.warehouseBooking); + shoppingCart.clear(); + + } catch (CreateOrderAction.ArticleNotInStockException e) { + request.setAttribute("error", "Der Artikel '" + e.getArticle().title + "' ist leider nicht mehr in ausreichender Menge verfügbar. Bitte passen Sie die Artikelmenge an."); + return shopCheckout(session, request, shoppingCart); + } - shoppingCart.clear(); return "shop/checkoutFinish"; } From d1301f69887829139044a059721b58797c7cf4e6 Mon Sep 17 00:00:00 2001 From: CodeSteak Date: Sun, 10 May 2020 14:30:00 +0200 Subject: [PATCH 04/19] Fix naming-convension-error in ArticleOffer --- .../org/hso/ecommerce/entities/supplier/ArticleOffer.java | 2 +- .../hso/ecommerce/entities/warehouse/WarehouseBooking.java | 1 + .../java/org/hso/ecommerce/repos/shop/ArticleRepository.java | 4 +--- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java index ce02d13..ae86659 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java @@ -20,5 +20,5 @@ public class ArticleOffer { public int vatPercent; - public boolean should_be_advertised; + public boolean shouldBeAdvertised; } diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/warehouse/WarehouseBooking.java b/prototype/src/main/java/org/hso/ecommerce/entities/warehouse/WarehouseBooking.java index cf60734..08eaa40 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/warehouse/WarehouseBooking.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/warehouse/WarehouseBooking.java @@ -27,6 +27,7 @@ public class WarehouseBooking { ) public List positions = new ArrayList<>(); + // TODO FIX ME @OneToOne(optional = false, cascade = CascadeType.ALL) public BookingReason reason; } diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java index 2a88b7e..90b6d11 100644 --- a/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java +++ b/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java @@ -1,14 +1,12 @@ package org.hso.ecommerce.repos.shop; import org.hso.ecommerce.entities.shop.Article; -import org.hso.ecommerce.entities.user.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; -import java.util.Optional; @Repository public interface ArticleRepository extends JpaRepository { @@ -17,7 +15,7 @@ public interface ArticleRepository extends JpaRepository { Article findArticleById(@Param("articleId") long articleId); - @Query("SELECT a FROM Article a JOIN a.related ao WHERE ao.should_be_advertised = true") + @Query("SELECT a FROM Article a JOIN a.related ao WHERE ao.shouldBeAdvertised = true") List
getAdvertisedArticles(); From d4d1426438de504f09201ac75c914df086e9f57f Mon Sep 17 00:00:00 2001 From: CodeSteak Date: Sun, 10 May 2020 14:34:20 +0200 Subject: [PATCH 05/19] Fix decimals in checkout page --- prototype/src/main/resources/templates/shop/checkout.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/prototype/src/main/resources/templates/shop/checkout.html b/prototype/src/main/resources/templates/shop/checkout.html index 9962649..786885f 100644 --- a/prototype/src/main/resources/templates/shop/checkout.html +++ b/prototype/src/main/resources/templates/shop/checkout.html @@ -49,7 +49,7 @@ + th:text="${#numbers.formatDecimal(item.article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"> EUR x
@@ -106,7 +106,7 @@ Musterstraße 4 Artikel (Netto) + th:text="${#numbers.formatDecimal(checkoutTotals.net * 0.01, 1, 'POINT', 2, 'COMMA')}"> EUR @@ -114,7 +114,7 @@ Musterstraße 4 Umsatzsteuer (%) + th:text="${#numbers.formatDecimal(item.getValue() * 0.01, 1, 'POINT', 2, 'COMMA')}"> EUR @@ -122,7 +122,7 @@ Musterstraße 4 Gesamt: + th:text="${#numbers.formatDecimal(checkoutTotals.total * 0.01, 1, 'POINT', 2, 'COMMA')}"> EUR From 95e52cc79dc4037806e823b8758d8bef0f67be3b Mon Sep 17 00:00:00 2001 From: Hannes Date: Sun, 10 May 2020 14:57:02 +0200 Subject: [PATCH 06/19] fix non-formatted and non-vatted price --- .../src/main/resources/templates/shop/articles/id.html | 6 +++--- prototype/src/main/resources/templates/shop/index.html | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/prototype/src/main/resources/templates/shop/articles/id.html b/prototype/src/main/resources/templates/shop/articles/id.html index 73de367..588b5be 100644 --- a/prototype/src/main/resources/templates/shop/articles/id.html +++ b/prototype/src/main/resources/templates/shop/articles/id.html @@ -23,7 +23,7 @@
-

+

EUR

@@ -32,7 +32,7 @@
-

+

EUR