From cf22eb790c5dde7b723d0eea5ee4bb87577cdb2d Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 24 Apr 2023 15:25:38 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=BD=D1=83=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B7=D0=B0=D0=B4=20=D1=81=D1=83=D1=89=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data.mv.db | Bin 40960 -> 32768 bytes .../repair/controller/ReportController.java | 30 +++--- .../is/sbapp/repair/model/Component.java | 16 ++-- .../sbapp/repair/model/Component_Favor.java | 68 ------------- .../ru/ulstu/is/sbapp/repair/model/Favor.java | 35 +++---- .../ru/ulstu/is/sbapp/repair/model/Order.java | 16 ++-- .../is/sbapp/repair/model/Order_Favor.java | 89 ------------------ .../repository/Component_FavorRepository.java | 7 -- .../repository/Order_FavorRepository.java | 7 -- .../service/Component_FavorService.java | 65 ------------- .../is/sbapp/repair/service/FavorService.java | 14 +-- .../is/sbapp/repair/service/OrderService.java | 6 +- .../repair/service/Order_FavorService.java | 80 ---------------- .../ulstu/is/sbapp/SbappApplicationTests.java | 76 +-------------- 14 files changed, 47 insertions(+), 462 deletions(-) delete mode 100644 src/main/java/ru/ulstu/is/sbapp/repair/model/Component_Favor.java delete mode 100644 src/main/java/ru/ulstu/is/sbapp/repair/model/Order_Favor.java delete mode 100644 src/main/java/ru/ulstu/is/sbapp/repair/repository/Component_FavorRepository.java delete mode 100644 src/main/java/ru/ulstu/is/sbapp/repair/repository/Order_FavorRepository.java delete mode 100644 src/main/java/ru/ulstu/is/sbapp/repair/service/Component_FavorService.java delete mode 100644 src/main/java/ru/ulstu/is/sbapp/repair/service/Order_FavorService.java diff --git a/data.mv.db b/data.mv.db index 083b577513522bebac023227631f382e6ba0d4b4..fd5ed79d80af394c37148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vOP>rsn+rw3#ct zNOAr@p5?>&|2unQe~Dj7hTQ(g_W#$M|IhjVaC!tgT$c0P{^$1p;0Y|8|G&=+AI|@W zbAkr2{5k)>yVK?T|NcpA1E~9>Fe`_c=`cLAlJoz&<_(5?_kCwPB%&LCSMTLjbN+uZ zKVTlgi|~Q7oc|wU%K86jE_8JzmAc>4ui^<6od4g-r+cibE2-4|9yDJv|Npy@`2W}T z=l=^s^Zz^j{QuAT`TxJ{=l_4v&;P&1^8XVy%AlM>_YgUUX+&_A2Hv&PL+U0@hqYry z#Q%?(t>LB=@s1g(q9*v8($<@bw)H^Xr#|Mo8#|=p1*sV7dKdpc_P~v>dB$+O*hoyY zJyxHXjNdFG&N5O;AmSYM?$Sl)QY7;KUvT%XKJge7qYb@S@euzX?*&E{^(5{=yr?G) zphZ2Y;}9+CNdst6PaGhNdg1_C)RQE`i+Yj(UeuEY@S>j2IsYHImH6NH2?65&kNxkF z|KDTQ|Mzss)qSPc8-DOG_5b@lO9wOl|I|f-4Yb%YdgtjTL9ic&8<>&(-YlQ40eo;d zX%3kGzs>Uh2dQAHi#@K3L;gS4#S#A>Z&lf+?7r{1IO6}u9ZL7GD|w@`k(oYyz%j3V zO#Weq32-&>zTLlw0)NQ^1*jf4{~s>j`AQt!ucXkiuT?kp47vZG`~Ug+f3cUF`~Ug+ ze|-HvwA2n+rjD=wH-=R`)4lxZSHeYl@Vcy|CZf;gB>F(>{}KB?w!azcIp+WShUFT* LPOaea9cTXw9j{)p diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/controller/ReportController.java b/src/main/java/ru/ulstu/is/sbapp/repair/controller/ReportController.java index 385d990..9802475 100644 --- a/src/main/java/ru/ulstu/is/sbapp/repair/controller/ReportController.java +++ b/src/main/java/ru/ulstu/is/sbapp/repair/controller/ReportController.java @@ -2,11 +2,9 @@ package ru.ulstu.is.sbapp.repair.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import ru.ulstu.is.sbapp.repair.service.Order_FavorService; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.time.LocalDate; import java.util.Date; import java.util.Map; @@ -14,18 +12,18 @@ import java.util.Map; @RestController public class ReportController { - private final Order_FavorService orderFavorService; - @Autowired - public ReportController(Order_FavorService orderFavorService) { - this.orderFavorService = orderFavorService; - } - @GetMapping("/report") - public Map GetReport (@RequestParam(value = "from") Object value1, - @RequestParam(value = "to") Object value2) throws ParseException { - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); - - Date d1 = formatter.parse(value1.toString()); - Date d2 = formatter.parse(value2.toString()); - return orderFavorService.makereport(d1, d2); - } +// private final Order_FavorService orderFavorService; +// @Autowired +// public ReportController(Order_FavorService orderFavorService) { +// this.orderFavorService = orderFavorService; +// } +// @GetMapping("/report") +// public Map GetReport (@RequestParam(value = "from") Object value1, +// @RequestParam(value = "to") Object value2) throws ParseException { +// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); +// +// Date d1 = formatter.parse(value1.toString()); +// Date d2 = formatter.parse(value2.toString()); +// return orderFavorService.makereport(d1, d2); +// } } \ No newline at end of file diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/model/Component.java b/src/main/java/ru/ulstu/is/sbapp/repair/model/Component.java index 2c0c696..c53f188 100644 --- a/src/main/java/ru/ulstu/is/sbapp/repair/model/Component.java +++ b/src/main/java/ru/ulstu/is/sbapp/repair/model/Component.java @@ -18,12 +18,12 @@ public class Component { @Column(name = "amount") private Integer amount; - @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) - @JoinColumn(name = "component_fk") - private List favorsListFromComponents; + @ManyToMany(fetch = FetchType.EAGER, mappedBy = "componentsList", cascade = CascadeType.REMOVE) + private List favorsListFromComponents; public Component() { favorsListFromComponents = new ArrayList<>(); + } public Component(String componentName, Integer amount) { @@ -52,21 +52,19 @@ public class Component { this.amount = amount; } - public List getFavors() { + public List getFavors() { return favorsListFromComponents; } - - public void addFavor(Component_Favor favor) { + public void addFavor(Favor favor) { if (favorsListFromComponents == null) favorsListFromComponents = new ArrayList<>(); if (!favorsListFromComponents.contains(favor)){ favorsListFromComponents.add(favor); } - /* if (!favor.getComponents().contains(this)) { favor.addComponent(this); - }*/ + } } @Override @@ -90,4 +88,4 @@ public class Component { ", amount='" + amount + '\'' + '}'; } -} +} \ No newline at end of file diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/model/Component_Favor.java b/src/main/java/ru/ulstu/is/sbapp/repair/model/Component_Favor.java deleted file mode 100644 index 63c8604..0000000 --- a/src/main/java/ru/ulstu/is/sbapp/repair/model/Component_Favor.java +++ /dev/null @@ -1,68 +0,0 @@ -package ru.ulstu.is.sbapp.repair.model; - -import javax.persistence.*; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -@Entity -@Table(name = "components_favors") -public class Component_Favor { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private Long id; - @Column(name = "amount") - private Integer amount; - - public Component_Favor() { - } - - public Component_Favor(Integer amount) { - this.amount = amount; - } - - public Long getId() { - return id; - } - - public Integer getAmount() { - return amount; - } - - public void setAmount(Integer amount) { - this.amount = amount; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Component_Favor cf = (Component_Favor) o; - return Objects.equals(id, cf.id); - } - - /* - public void addComponent(Component component){ - if (componentsList == null) - componentsList = new ArrayList<>(); - if (!componentsList.contains(component)){ - componentsList.add(component); - } - if (!component.getFavors().contains(this)) { - component.addFavor(this); - } - } -*/ - @Override - public int hashCode() { - return Objects.hash(id); - } - - @Override - public String toString() { - return "Product{" + - "id=" + id + - '}'; - } - -} diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/model/Favor.java b/src/main/java/ru/ulstu/is/sbapp/repair/model/Favor.java index a2fb953..dc54cf8 100644 --- a/src/main/java/ru/ulstu/is/sbapp/repair/model/Favor.java +++ b/src/main/java/ru/ulstu/is/sbapp/repair/model/Favor.java @@ -20,14 +20,12 @@ public class Favor { @Column(name = "price") private Integer price; - @OneToMany (cascade = CascadeType.ALL) - @JoinColumn(name = "favor_fk") - private List ordersList; + @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE) + private List ordersList; - @OneToMany (cascade = CascadeType.ALL) + @ManyToMany(cascade = CascadeType.REMOVE) @LazyCollection(LazyCollectionOption.FALSE) - @JoinColumn(name = "favor_fk") - private List componentsList; + private List componentsList; public Favor() { componentsList = new ArrayList<>(); @@ -61,31 +59,21 @@ public class Favor { this.price = price; } - public List getOrders() { + public List getOrders() { return ordersList; } - public List getComponents() {return componentsList;} + public List getComponents() {return componentsList;} - public void addOrder(Order_Favor of) { + public void addOrder(Order order) { if (ordersList == null) ordersList = new ArrayList<>(); - if (!ordersList.contains(of)){ - ordersList.add(of); - of.setFavor_id(this); + if (!ordersList.contains(order)){ + ordersList.add(order); } - } - - public void addCF(Component_Favor cf) { - if (componentsList == null) - componentsList = new ArrayList<>(); - if (!componentsList.contains(cf)){ - componentsList.add(cf); - } - /* if (!order.getFavorsList().contains(this)) { order.addFavor(this); - }*/ + } } @@ -97,7 +85,6 @@ public class Favor { return Objects.equals(id, favor.id); } - /* public void addComponent(Component component){ if (componentsList == null) componentsList = new ArrayList<>(); @@ -108,7 +95,7 @@ public class Favor { component.addFavor(this); } } -*/ + @Override public int hashCode() { return Objects.hash(id); diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/model/Order.java b/src/main/java/ru/ulstu/is/sbapp/repair/model/Order.java index ea8e857..3da0ffe 100644 --- a/src/main/java/ru/ulstu/is/sbapp/repair/model/Order.java +++ b/src/main/java/ru/ulstu/is/sbapp/repair/model/Order.java @@ -17,9 +17,8 @@ public class Order { @Column(name = "date") private Date date; - @OneToMany (cascade = CascadeType.ALL) - @JoinColumn(name = "order_fk") - private List favorsList; + @ManyToMany (fetch = FetchType.EAGER, mappedBy = "ordersList", cascade = CascadeType.REMOVE) + private List favorsList; public Order(){ } @@ -49,18 +48,17 @@ public class Order { return Objects.equals(getId(), order.getId()) && Objects.equals(getDate(), order.getDate()); } - public List getFavorsList() { + public List getFavorsList() { return favorsList; } - public void addFavor(Order_Favor of){ + public void addFavor(Favor favor){ if (favorsList == null) favorsList = new ArrayList<>(); - if (!favorsList.contains(of)) { - favorsList.add(of); - of.setOrder_id(this); + if (!favorsList.contains(favor)) { + favorsList.add(favor); } - //favor.addOrder(this); + favor.addOrder(this); } diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/model/Order_Favor.java b/src/main/java/ru/ulstu/is/sbapp/repair/model/Order_Favor.java deleted file mode 100644 index 13e4794..0000000 --- a/src/main/java/ru/ulstu/is/sbapp/repair/model/Order_Favor.java +++ /dev/null @@ -1,89 +0,0 @@ -package ru.ulstu.is.sbapp.repair.model; - -import javax.persistence.*; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -@Entity -@Table(name = "orders_favors") -public class Order_Favor { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private Long id; - @Column(name = "amount") - private Integer amount; - - @ManyToOne - private Order Order_id; - @ManyToOne - private Favor Favor_id; - - public Order_Favor() { - } - - public Order_Favor(Integer amount) { - this.amount = amount; - } - - public Long getId() { - return id; - } - - public Integer getAmount() { - return amount; - } - - public void setAmount(Integer amount) { - this.amount = amount; - } - - public Favor getFavor_id() { - return Favor_id; - } - - public void setFavor_id(Favor favor_id) { - Favor_id = favor_id; - } - - public Order getOrder_id() { - return Order_id; - } - - public void setOrder_id(Order order_id) { - Order_id = order_id; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Order_Favor of = (Order_Favor) o; - return Objects.equals(id, of.id); - } - - /* - public void addComponent(Component component){ - if (componentsList == null) - componentsList = new ArrayList<>(); - if (!componentsList.contains(component)){ - componentsList.add(component); - } - if (!component.getFavors().contains(this)) { - component.addFavor(this); - } - } -*/ - @Override - public int hashCode() { - return Objects.hash(id); - } - - @Override - public String toString() { - return "Product{" + - "id=" + id + - '}'; - } - -} diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/repository/Component_FavorRepository.java b/src/main/java/ru/ulstu/is/sbapp/repair/repository/Component_FavorRepository.java deleted file mode 100644 index b4ec019..0000000 --- a/src/main/java/ru/ulstu/is/sbapp/repair/repository/Component_FavorRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.ulstu.is.sbapp.repair.repository; - -import org.springframework.data.jpa.repository.JpaRepository; -import ru.ulstu.is.sbapp.repair.model.Component_Favor; - -public interface Component_FavorRepository extends JpaRepository { -} diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/repository/Order_FavorRepository.java b/src/main/java/ru/ulstu/is/sbapp/repair/repository/Order_FavorRepository.java deleted file mode 100644 index f3aaa08..0000000 --- a/src/main/java/ru/ulstu/is/sbapp/repair/repository/Order_FavorRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.ulstu.is.sbapp.repair.repository; - -import org.springframework.data.jpa.repository.JpaRepository; -import ru.ulstu.is.sbapp.repair.model.Order_Favor; - -public interface Order_FavorRepository extends JpaRepository { -} diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/service/Component_FavorService.java b/src/main/java/ru/ulstu/is/sbapp/repair/service/Component_FavorService.java deleted file mode 100644 index a7434d1..0000000 --- a/src/main/java/ru/ulstu/is/sbapp/repair/service/Component_FavorService.java +++ /dev/null @@ -1,65 +0,0 @@ -package ru.ulstu.is.sbapp.repair.service; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; -import ru.ulstu.is.sbapp.repair.model.Component; -import ru.ulstu.is.sbapp.repair.model.Component_Favor; -import ru.ulstu.is.sbapp.repair.model.Favor; - -import javax.persistence.EntityManager; -import javax.persistence.EntityNotFoundException; -import javax.persistence.PersistenceContext; -import java.util.List; - -@Service -public class Component_FavorService { - @PersistenceContext - private EntityManager em; - @Transactional - public Component_Favor addComponent_Favor(Integer amount) { - if (amount == 0) { - throw new IllegalArgumentException("amount cant be 0"); - } - final Component_Favor cf = new Component_Favor(amount); - em.persist(cf); - - return cf; - } - - @Transactional(readOnly = true) - public Component_Favor findComponent_Favor(Long id) { - final Component_Favor cf = em.find(Component_Favor.class, id); - if (cf == null) { - throw new EntityNotFoundException(String.format("cf with id [%s] is not found", id)); - } - return cf; - } - - @Transactional(readOnly = true) - public List findAllComponentFavors() { - return em.createQuery("select p from Component_Favor p", Component_Favor.class).getResultList(); - } - - @Transactional - public Component_Favor updateComponentFavor(Long id, Integer amount) { - if (amount == 0) { - throw new IllegalArgumentException("amount = 0"); - } - final Component_Favor cf = findComponent_Favor(id); - cf.setAmount(amount); - em.merge(cf); - return cf; - } - - @Transactional - public Component_Favor deleteFavor(Long id) { - final Component_Favor cf = findComponent_Favor(id); - em.remove(cf); - return cf; - } - @Transactional - public void deleteAllComponentFavor() { - em.createQuery("delete from Component_Favor ").executeUpdate(); - } -} diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/service/FavorService.java b/src/main/java/ru/ulstu/is/sbapp/repair/service/FavorService.java index b9e5f87..90b2688 100644 --- a/src/main/java/ru/ulstu/is/sbapp/repair/service/FavorService.java +++ b/src/main/java/ru/ulstu/is/sbapp/repair/service/FavorService.java @@ -5,18 +5,13 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import ru.ulstu.is.sbapp.repair.model.Component; -import ru.ulstu.is.sbapp.repair.model.Component_Favor; import ru.ulstu.is.sbapp.repair.model.Favor; -import ru.ulstu.is.sbapp.repair.model.Order; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.EntityNotFoundException; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.Objects; @Service public class FavorService { @@ -69,7 +64,7 @@ public class FavorService { } @Transactional - public Favor addComponentToFavor(Long id, Component component, Component_Favor cf){ + public Favor addComponentToFavor(Long id, Component component){ final Favor currentFavor = findFavor(id); if (currentFavor == null){ throw new IllegalArgumentException("Favor with id: " + id + " not found"); @@ -77,13 +72,8 @@ public class FavorService { if (component == null){ throw new IllegalArgumentException("favor not found"); } - //currentFavor.addComponent(component); + currentFavor.addComponent(component); //component.addFavor(currentFavor); - - //final Component_Favor cf = new Component_Favor(amount); - currentFavor.addCF(cf); - component.addFavor(cf); - em.merge(component); return em.merge(currentFavor); } diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/service/OrderService.java b/src/main/java/ru/ulstu/is/sbapp/repair/service/OrderService.java index 675af54..a993e2b 100644 --- a/src/main/java/ru/ulstu/is/sbapp/repair/service/OrderService.java +++ b/src/main/java/ru/ulstu/is/sbapp/repair/service/OrderService.java @@ -6,7 +6,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import ru.ulstu.is.sbapp.repair.model.Favor; import ru.ulstu.is.sbapp.repair.model.Order; -import ru.ulstu.is.sbapp.repair.model.Order_Favor; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; @@ -77,7 +76,7 @@ public class OrderService { } @Transactional - public Order addFavorToOrder(Long id, Favor favor, Order_Favor of){ + public Order addFavorToOrder(Long id, Favor favor){ final Order currentOrder = findOrder(id); if (currentOrder == null){ throw new IllegalArgumentException("Order with id: " + id + " not found"); @@ -85,8 +84,7 @@ public class OrderService { if (favor == null){ throw new IllegalArgumentException("favor not found"); } - currentOrder.addFavor(of); - favor.addOrder(of); + currentOrder.addFavor(favor); em.merge(favor); return em.merge(currentOrder); } diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/service/Order_FavorService.java b/src/main/java/ru/ulstu/is/sbapp/repair/service/Order_FavorService.java deleted file mode 100644 index 0202ba9..0000000 --- a/src/main/java/ru/ulstu/is/sbapp/repair/service/Order_FavorService.java +++ /dev/null @@ -1,80 +0,0 @@ -package ru.ulstu.is.sbapp.repair.service; - -import org.aspectj.weaver.ast.Or; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import ru.ulstu.is.sbapp.repair.model.Component_Favor; -import ru.ulstu.is.sbapp.repair.model.Order_Favor; - -import javax.persistence.EntityManager; -import javax.persistence.EntityNotFoundException; -import javax.persistence.PersistenceContext; -import javax.persistence.Tuple; - -import java.time.LocalDate; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - - -@Service -public class Order_FavorService { - @PersistenceContext - private EntityManager em; - @Transactional - public Order_Favor addOrder_Favor(Integer amount) { - if (amount == 0) { - throw new IllegalArgumentException("amount cant be 0"); - } - final Order_Favor cf = new Order_Favor(amount); - em.persist(cf); - - return cf; - } - - @Transactional(readOnly = true) - public Order_Favor findOrder_Favor(Long id) { - final Order_Favor cf = em.find(Order_Favor.class, id); - if (cf == null) { - throw new EntityNotFoundException(String.format("cf with id [%s] is not found", id)); - } - return cf; - } - - @Transactional(readOnly = true) - public List findAllOrderFavors() { - return em.createQuery("select p from Order_Favor p", Order_Favor.class).getResultList(); - } - - @Transactional - public Order_Favor updateOrderFavor(Long id, Integer amount) { - if (amount == 0) { - throw new IllegalArgumentException("amount = 0"); - } - final Order_Favor cf = findOrder_Favor(id); - cf.setAmount(amount); - em.merge(cf); - return cf; - } - - @Transactional - public Order_Favor deleteFavor(Long id) { - final Order_Favor cf = findOrder_Favor(id); - em.remove(cf); - return cf; - } - @Transactional - public void deleteAllComponentFavor() { - em.createQuery("delete from Order_Favor ").executeUpdate(); - } - - @Transactional - public Map makereport(Date d1, Date d2){ - - Map answ = em.createQuery("SELECT f.favorName as n, sum(off.amount) * f.price as s from Order_Favor off join off.Favor_id f join off.Order_id o where o.date > :date1 and o.date < :date2 group by f.favorName", Tuple.class).setParameter("date1", d1).setParameter("date2", d2).getResultStream().collect(Collectors.toMap(tuple -> ((String)tuple.get("n")).toString(), tuple -> ((Number) tuple.get("s")).intValue())); - - return answ; - } -} diff --git a/src/test/java/ru/ulstu/is/sbapp/SbappApplicationTests.java b/src/test/java/ru/ulstu/is/sbapp/SbappApplicationTests.java index bcdc6b5..d07bd45 100644 --- a/src/test/java/ru/ulstu/is/sbapp/SbappApplicationTests.java +++ b/src/test/java/ru/ulstu/is/sbapp/SbappApplicationTests.java @@ -18,53 +18,9 @@ class SbappApplicationTests { private FavorService favorService; @Autowired private OrderService orderService; - @Autowired - private Component_FavorService cfService; - @Autowired - private Order_FavorService ofService; - @Test - void testReport(){ - ofService.deleteAllComponentFavor(); - cfService.deleteAllComponentFavor(); - componentService.deleteAllComponent(); - orderService.deleteAllOrder(); - favorService.deleteAllFavor(); - - - - - final Favor favor = favorService.addFavor("Favor1", 100); - final Favor favor1 = favorService.addFavor("Favor2", 200); - final Favor favor2 = favorService.addFavor("Favor3", 300); - - - - final Order order0 = orderService.addOrder("11.02.2023"); - final Order order1 = orderService.addOrder("12.02.2023"); - final Order order2 = orderService.addOrder("13.02.2023"); - - final Order_Favor of = ofService.addOrder_Favor(10); - final Order_Favor of1 = ofService.addOrder_Favor(11); - final Order_Favor of2 = ofService.addOrder_Favor(12); - final Order_Favor of3 = ofService.addOrder_Favor(13); - - - orderService.addFavorToOrder(order0.getId(), favor, of); - orderService.addFavorToOrder(order0.getId(), favor1, of1); - orderService.addFavorToOrder(order1.getId(), favor, of2); - orderService.addFavorToOrder(order1.getId(), favor2, of3); - - - - - //final List lst = ofService.makereport(); - //Assertions.assertEquals(lst.get(0).getAmount(), 10); - } @Test void testOrder(){ - cfService.deleteAllComponentFavor(); - ofService.deleteAllComponentFavor(); componentService.deleteAllComponent(); orderService.deleteAllOrder(); favorService.deleteAllFavor(); @@ -73,13 +29,11 @@ class SbappApplicationTests { final Order order0 = orderService.addOrder("11.02.2023"); final Order order1 = orderService.findOrder(order0.getId()); + final Component component1 = componentService.addComponent("comp", 10); + favor.addComponent(component1); Assertions.assertEquals(order0, order1); - final Order_Favor of = ofService.addOrder_Favor(10); - - - orderService.addFavorToOrder(order0.getId(), favor, of); - + orderService.addFavorToOrder(order0.getId(), favor); Assertions.assertEquals(favorService.findFavor(favor.getId()).getOrders().size(), 1); Assertions.assertEquals(orderService.findOrder(order0.getId()).getFavorsList().size(), 1); @@ -87,26 +41,20 @@ class SbappApplicationTests { Assertions.assertThrows(EntityNotFoundException.class, () -> orderService.findOrder(order0.getId())); } - @Test void testFavor(){ - cfService.deleteAllComponentFavor(); - ofService.deleteAllComponentFavor(); componentService.deleteAllComponent(); orderService.deleteAllOrder(); favorService.deleteAllFavor(); - final Component component = componentService.addComponent("Favor1", 100); final Favor favor0 = favorService.addFavor("fvr", 100); final Favor favor1 = favorService.findFavor(favor0.getId()); - Assertions.assertEquals(favor0, favor1); - final Component_Favor cf = cfService.addComponent_Favor(10); - favorService.addComponentToFavor(favor0.getId(), component, cf); + favorService.addComponentToFavor(favor0.getId(), component); Assertions.assertEquals(favorService.findFavor(favor0.getId()).getComponents().size(), 1); Assertions.assertEquals(componentService.findComponent(component.getId()).getFavors().size(), 1); @@ -114,20 +62,4 @@ class SbappApplicationTests { Assertions.assertThrows(EntityNotFoundException.class, () -> favorService.findFavor(favor0.getId())); } - @Test - void testComponent(){ - cfService.deleteAllComponentFavor(); - ofService.deleteAllComponentFavor(); - favorService.deleteAllFavor(); - componentService.deleteAllComponent(); - orderService.deleteAllOrder(); - - final Component component0 = componentService.addComponent("comp", 111); - final Component component1 = componentService.findComponent(component0.getId()); - Assertions.assertEquals(component0, component1); - - componentService.deleteComponent(component0.getId()); - Assertions.assertThrows(EntityNotFoundException.class, () -> componentService.findComponent(component0.getId())); - - } }