From b5495bda3d5c521c5a42d0a979b9935824be331d Mon Sep 17 00:00:00 2001 From: Hannes Date: Tue, 19 May 2020 11:52:41 +0200 Subject: [PATCH] show all Orders --- .../action/user/ChangeUserAction.java | 7 +++ .../ecommerce/controller/UserController.java | 59 ++++++++++++++++++- .../shop/ShopCheckoutController.java | 4 +- .../entities/shop/CustomerOrder.java | 13 ++++ .../entities/shop/CustomerOrderPosition.java | 4 ++ .../org/hso/ecommerce/entities/user/User.java | 4 ++ .../repos/shop/CustomerOderRepository.java | 11 ---- .../repos/shop/CustomerOrderRepository.java | 17 ++++++ .../templates/user/orders/index.html | 46 +++++---------- .../resources/templates/user/settings.html | 2 +- 10 files changed, 121 insertions(+), 46 deletions(-) create mode 100644 prototype/src/main/java/org/hso/ecommerce/action/user/ChangeUserAction.java delete mode 100644 prototype/src/main/java/org/hso/ecommerce/repos/shop/CustomerOderRepository.java create mode 100644 prototype/src/main/java/org/hso/ecommerce/repos/shop/CustomerOrderRepository.java diff --git a/prototype/src/main/java/org/hso/ecommerce/action/user/ChangeUserAction.java b/prototype/src/main/java/org/hso/ecommerce/action/user/ChangeUserAction.java new file mode 100644 index 0000000..af9ef9e --- /dev/null +++ b/prototype/src/main/java/org/hso/ecommerce/action/user/ChangeUserAction.java @@ -0,0 +1,7 @@ +package org.hso.ecommerce.action.user; + +import org.hso.ecommerce.entities.user.User; + +public class ChangeUserAction { + +} diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/UserController.java b/prototype/src/main/java/org/hso/ecommerce/controller/UserController.java index c462bd0..fee6946 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/UserController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/UserController.java @@ -1,14 +1,19 @@ package org.hso.ecommerce.controller; +import org.hso.ecommerce.entities.shop.CustomerOrder; import org.hso.ecommerce.entities.user.User; +import org.hso.ecommerce.repos.shop.CustomerOrderRepository; import org.hso.ecommerce.repos.user.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpSession; +import java.util.List; @Controller @RequestMapping("/user") @@ -17,6 +22,9 @@ public class UserController { @Autowired private final UserRepository userRepository = null; + @Autowired + private final CustomerOrderRepository customerOrderRepository = null; + @GetMapping("/") public String user() { return "redirect:/user/settings"; @@ -37,14 +45,63 @@ public class UserController { @GetMapping("/notifications/") public String userNotifications() { + + //TODO: implement this + return "user/notifications/index"; } @GetMapping("/orders/") - public String userOrdeers() { + public String userOrdeers(HttpSession session, + Model model) { + + List orders = customerOrderRepository.getOrdersByUserId((long) session.getAttribute("userId")); + + model.addAttribute("orders", orders); + return "user/orders/index"; } + @PostMapping("/settings/changeMail") + public String changeMail(@RequestParam("email") String email){ + + //TODO: implement this + + return "user/settings"; + } + + @PostMapping("/settings/changePwd") + public String changePwd(){ + + //TODO: implement this + + return "user/settings"; + } + + @PostMapping("/settings/changeAddress") + public String changeAddress(){ + + //TODO: implement this + + return "user/settings"; + } + + @PostMapping("/settings/changeAdSettings") + public String changeAdSettings(){ + + //TODO: implement this + + return "user/settings"; + } + + @PostMapping("/settings/changePaymentInfo") + public String changePaymentInfo(){ + + //TODO: implement this + + return "user/settings"; + } + // @GetMapping("/bonuspoints") // public String userBonuspoints() { // return "user/bonuspoints"; 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 c2c1c3a..e9d9e68 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 @@ -11,7 +11,7 @@ import org.hso.ecommerce.entities.user.User; import org.hso.ecommerce.repos.booking.BookingAccountEntryRepository; import org.hso.ecommerce.repos.booking.BookingRepository; import org.hso.ecommerce.repos.shop.ArticleRepository; -import org.hso.ecommerce.repos.shop.CustomerOderRepository; +import org.hso.ecommerce.repos.shop.CustomerOrderRepository; import org.hso.ecommerce.repos.user.UserRepository; import org.hso.ecommerce.repos.warehouse.WarehouseBookingPositionSlotEntryRepository; import org.hso.ecommerce.repos.warehouse.WarehouseBookingRepository; @@ -45,7 +45,7 @@ public class ShopCheckoutController { private final WarehouseBookingRepository warehouseBookingRepository = null; @Autowired - private final CustomerOderRepository customerOderRepository = null; + private final CustomerOrderRepository customerOderRepository = null; @Autowired private final WarehouseBookingPositionSlotEntryRepository wbeseRepo = null; diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/shop/CustomerOrder.java b/prototype/src/main/java/org/hso/ecommerce/entities/shop/CustomerOrder.java index 1b20bb2..d9410f7 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/shop/CustomerOrder.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/shop/CustomerOrder.java @@ -4,6 +4,7 @@ import org.hso.ecommerce.entities.user.User; import javax.persistence.*; import javax.validation.constraints.NotNull; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; @@ -43,4 +44,16 @@ public class CustomerOrder { public int totalNetCent; public int totalGrossCent; public int totalVatCent; + + public String formatInDeliverySince(){ + return new SimpleDateFormat("dd.MM.yyyy HH:mm").format(inDeliverySince); + } + + public String formatCreated(){ + return new SimpleDateFormat("dd.MM.yyyy HH:mm").format(created); + } + + public String formatDeliveredAt(){ + return new SimpleDateFormat("dd.MM.yyyy HH:mm").format(deliveredAt); + } } diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/shop/CustomerOrderPosition.java b/prototype/src/main/java/org/hso/ecommerce/entities/shop/CustomerOrderPosition.java index dbe53f7..2569158 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/shop/CustomerOrderPosition.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/shop/CustomerOrderPosition.java @@ -19,4 +19,8 @@ public class CustomerOrderPosition { public int pricePerUnit; public int quantity; + + public int getSumPrice(){ + return article.getPriceGross() * quantity; + } } diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/user/User.java b/prototype/src/main/java/org/hso/ecommerce/entities/user/User.java index c36b629..40196c7 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/user/User.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/user/User.java @@ -45,6 +45,10 @@ public class User { return id; } + public void setEmail(String email) { + this.email = email; + } + public boolean validatePassword(String password) { return BCrypt.checkpw(password, passwordHash); } diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/shop/CustomerOderRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/shop/CustomerOderRepository.java deleted file mode 100644 index 407f45c..0000000 --- a/prototype/src/main/java/org/hso/ecommerce/repos/shop/CustomerOderRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.hso.ecommerce.repos.shop; - -import org.hso.ecommerce.entities.shop.CustomerOrder; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface CustomerOderRepository extends JpaRepository { - -} - diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/shop/CustomerOrderRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/shop/CustomerOrderRepository.java new file mode 100644 index 0000000..da42f26 --- /dev/null +++ b/prototype/src/main/java/org/hso/ecommerce/repos/shop/CustomerOrderRepository.java @@ -0,0 +1,17 @@ +package org.hso.ecommerce.repos.shop; + +import org.hso.ecommerce.entities.shop.CustomerOrder; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface CustomerOrderRepository extends JpaRepository { + + @Query("SELECT co FROM CustomerOrder co WHERE co.customer.id = :userId") + List getOrdersByUserId(long userId); + +} + diff --git a/prototype/src/main/resources/templates/user/orders/index.html b/prototype/src/main/resources/templates/user/orders/index.html index 5e24e4a..b746f52 100644 --- a/prototype/src/main/resources/templates/user/orders/index.html +++ b/prototype/src/main/resources/templates/user/orders/index.html @@ -21,26 +21,22 @@
-
-

Bestellung vom 27.01.2020

+
+

- + + - + - +
LieferstatusUnterwegs
Vorraussichtliche Ankunft: 29.01.2020
Unterwegs
Vorraussichtliche Ankunft: TODO TODO TODO TODO
Angekommen
Ankunft:
SendeverfolgungsnummerXE51451436DE
- Hans Maier
- Hauptstraße 12
- 74880 Musterstadt
- Deutschland
-