From ba29a321f0ece59ab60804debe6100170e559df2 Mon Sep 17 00:00:00 2001 From: dasha Date: Wed, 15 Mar 2023 23:52:50 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D1=83=20=D0=B2=D1=80=D0=BE=D0=B4=D0=B5?= =?UTF-8?q?=20=D1=87=D1=82=D0=BE-=D1=82=D0=BE=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data.mv.db | Bin 40960 -> 36864 bytes .../java/com/labwork1/app/AppApplication.java | 36 +--- .../app/calc/controller/CalcController.java | 44 ---- .../com/labwork1/app/calc/domain/CalcNum.java | 46 ---- .../com/labwork1/app/calc/domain/CalcStr.java | 46 ---- .../com/labwork1/app/calc/domain/ICalc.java | 11 - .../app/calc/service/CalcService.java | 52 ----- .../controller/CustomerController.java | 45 ---- .../labwork1/app/student/model/Customer.java | 56 +++-- .../com/labwork1/app/student/model/Order.java | 66 +++--- .../labwork1/app/student/model/Ticket.java | 79 +++---- .../app/student/service/CustomerService.java | 11 +- .../app/student/service/OrderService.java | 42 ++-- .../app/student/service/TicketService.java | 26 +-- src/main/resources/application.properties | 1 - .../com/labwork1/app/AppApplicationTests.java | 56 ----- .../com/labwork1/app/JpaCustomerTests.java | 199 ++++++++---------- 17 files changed, 242 insertions(+), 574 deletions(-) delete mode 100644 src/main/java/com/labwork1/app/calc/controller/CalcController.java delete mode 100644 src/main/java/com/labwork1/app/calc/domain/CalcNum.java delete mode 100644 src/main/java/com/labwork1/app/calc/domain/CalcStr.java delete mode 100644 src/main/java/com/labwork1/app/calc/domain/ICalc.java delete mode 100644 src/main/java/com/labwork1/app/calc/service/CalcService.java delete mode 100644 src/main/java/com/labwork1/app/student/controller/CustomerController.java delete mode 100644 src/test/java/com/labwork1/app/AppApplicationTests.java diff --git a/data.mv.db b/data.mv.db index bc80d1b8773734b3d3c479a313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2qcZ=H0uZ%R2XAQ@<4BPjLJOa9wE&E8FwcrBD0m2vXol@W| zFz^)13=NBW4J2LzPr-dcWhUz8r%*6B1SFp_ZVbz$$-8VUcJNq%k06#$E0#<<6BR6; zhP%aMVP6KQ2Z2b6!;FydA??!PLz>F;_#qFTNc<3x?8JOSUV&gQKcJY5iS+`Q zwt745L2F}rw3p>5rcHNcXLG9uwa|x{FVQ!&7Fht6os~5fEoN?E9%8z@SGrQPT%Dw4 z!+}>8Agas5;#x_iEfv=Vo^`yqE?V_lB|_&6+DmJ#K{+U^(xAQ3f&efZoAU+>lv5&> z4#>R(*srX2n}c~>U6@mXjID*r{ znOC9O|0EXIdjdjreBDow44P`U*J@wyMB$v~*_2o5(@$e9SVt;3Y2>7nlR-`_w`XZJ)Qlv^=+ zi#Ug|`IIs5M@frJKJ4J`dG_R;bpVHQh)#FOT|s6ASrud_f#NDiuOOp>)C$rdWE}C* z{hwF=KEX@3MZI*}6KzYF7w2(%pvSHJA2Z%2H2|3E#ktTPT79~`bTbGOa-z@1 zj@)%?^cpFe?EpRYF_?OMhTV0Gm%oJjYr@QL{tRdMzx*9>+l_Ddfg`{X;0SO8I0762 jjsQpCQ4t{P|H=A0TmN@b{{JB4yy}K#W-0uHZsz_6*N9Y( diff --git a/src/main/java/com/labwork1/app/AppApplication.java b/src/main/java/com/labwork1/app/AppApplication.java index d5d2762..dc1f0af 100644 --- a/src/main/java/com/labwork1/app/AppApplication.java +++ b/src/main/java/com/labwork1/app/AppApplication.java @@ -2,42 +2,12 @@ package com.labwork1.app; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication @RestController public class AppApplication { - public static void main(String[] args) { - SpringApplication.run(AppApplication.class, args); - } - /*@GetMapping("/hello") - public String hello(@RequestParam(value = "name", defaultValue = "World") String name) { - return String.format("Hello %s!", name); - } - @GetMapping("/plus") - public String plus(@RequestParam(required = false, defaultValue = "0") double first, - @RequestParam(required = false, defaultValue = "0") double second) { - return Double.toString(first + second); - } - @GetMapping("/minus") - public String minus(@RequestParam(required = false, defaultValue = "0") double first, - @RequestParam(required = false, defaultValue = "0") double second) { - return Double.toString(first - second); - } - @GetMapping("/mult") - public String mult(@RequestParam(required = false, defaultValue = "1") double first, - @RequestParam(required = false, defaultValue = "1") double second) { - return Double.toString(first * second); - } - @GetMapping("/div") - public String div(@RequestParam(required = false, defaultValue = "1") double first, - @RequestParam(required = false, defaultValue = "1") double second) { - if(second == 0) - { - return null; - } - return Double.toString(first/second); - }*/ + public static void main(String[] args) { + SpringApplication.run(AppApplication.class, args); + } } diff --git a/src/main/java/com/labwork1/app/calc/controller/CalcController.java b/src/main/java/com/labwork1/app/calc/controller/CalcController.java deleted file mode 100644 index 0ad5ae4..0000000 --- a/src/main/java/com/labwork1/app/calc/controller/CalcController.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.labwork1.app.calc.controller; - -import com.labwork1.app.calc.service.CalcService; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class CalcController { - private final CalcService calcService; - - public CalcController(CalcService calcService) { - this.calcService = calcService; - } - - @GetMapping("/plus") - public String plus(@RequestParam(required = false, defaultValue = "0") Object first, - @RequestParam(required = false, defaultValue = "0") Object second, - @RequestParam(required = false, defaultValue = "num") String type) { - return calcService.plus((Object) first, (Object) second, type); - } - @GetMapping("/minus") - public String minus(@RequestParam(required = false, defaultValue = "0") Object first, - @RequestParam(required = false, defaultValue = "0") Object second, - @RequestParam(required = false, defaultValue = "num") String type) { - return calcService.minus((Object) first, (Object) second, type); - } - @GetMapping("/mult") - public String mult(@RequestParam(required = false, defaultValue = "1") Object first, - @RequestParam(required = false, defaultValue = "1") Object second, - @RequestParam(required = false, defaultValue = "num") String type) { - return calcService.mult((Object) first, (Object) second, type); - } - @GetMapping("/div") - public String div(@RequestParam(required = false, defaultValue = "1") Object first, - @RequestParam(required = false, defaultValue = "1") Object second, - @RequestParam(required = false, defaultValue = "num") String type) { - if(Integer.parseInt(second.toString()) == 0) - { - return null; - } - return calcService.div((Object) first, (Object) second, type); - } -} diff --git a/src/main/java/com/labwork1/app/calc/domain/CalcNum.java b/src/main/java/com/labwork1/app/calc/domain/CalcNum.java deleted file mode 100644 index b7b90ac..0000000 --- a/src/main/java/com/labwork1/app/calc/domain/CalcNum.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.labwork1.app.calc.domain; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.stereotype.Component; - -@Component(value = "num") -public class CalcNum implements ICalc, InitializingBean, DisposableBean { - private final Logger log = LoggerFactory.getLogger(CalcNum.class); - - @Override - public void afterPropertiesSet() { - log.info("CalcNum.afterPropertiesSet()"); - } - - @Override - public void destroy() { - log.info("CalcNum.destroy()"); - } - - @Override - public Integer Plus(Integer first, Integer second) { - return first + second; - } - - @Override - public Integer Mult(Integer first, Integer second) { - return first * second; - } - - @Override - public Integer Minus(Integer first, Integer second) { - return first - second; - } - - @Override - public Integer Div(Integer first, Integer second) { - if (second == 0){ - return null; - }else{ - return first / second; - } - } -} diff --git a/src/main/java/com/labwork1/app/calc/domain/CalcStr.java b/src/main/java/com/labwork1/app/calc/domain/CalcStr.java deleted file mode 100644 index ac5aa4a..0000000 --- a/src/main/java/com/labwork1/app/calc/domain/CalcStr.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.labwork1.app.calc.domain; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.stereotype.Component; - -@Component(value = "str") -public class CalcStr implements ICalc, InitializingBean, DisposableBean { - private final Logger log = LoggerFactory.getLogger(CalcStr.class); - - @Override - public void afterPropertiesSet() { - log.info("CalcStr.afterPropertiesSet()"); - } - - @Override - public void destroy() { - log.info("CalcStr.destroy()"); - } - - @Override - public String Plus(String first, String second) { - return first.concat(second); - } - - @Override - public String Mult(String first, String second) { - String temp = first; - for (int i = 0; i < Integer.parseInt(second) - 1; i++) { - temp = Plus(temp, first); - } - return temp; - } - - @Override - public String Minus(String first, String second) { - return first.replaceFirst(second, ""); - } - - @Override - public String Div(String first, String second) { - return first.replaceAll(second, ""); - } -} diff --git a/src/main/java/com/labwork1/app/calc/domain/ICalc.java b/src/main/java/com/labwork1/app/calc/domain/ICalc.java deleted file mode 100644 index a839a8d..0000000 --- a/src/main/java/com/labwork1/app/calc/domain/ICalc.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.labwork1.app.calc.domain; - -public interface ICalc { - T Plus(T first, T second); - - T Mult(T first, T second); - - T Minus(T first, T second); - - T Div(T first, T second); -} diff --git a/src/main/java/com/labwork1/app/calc/service/CalcService.java b/src/main/java/com/labwork1/app/calc/service/CalcService.java deleted file mode 100644 index c20295b..0000000 --- a/src/main/java/com/labwork1/app/calc/service/CalcService.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.labwork1.app.calc.service; - -import com.labwork1.app.calc.domain.CalcNum; -import com.labwork1.app.calc.domain.CalcStr; -import com.labwork1.app.calc.domain.ICalc; -import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Service; - -@Service -public class CalcService { - private final ApplicationContext applicationContext; - - public CalcService(ApplicationContext applicationContext) { - this.applicationContext = applicationContext; - } - - public String plus(Object first, Object second, String type) { - final ICalc temp = (ICalc) applicationContext.getBean(type); - if (temp instanceof CalcStr) { - return String.format("%s", temp.Plus(first, second)); - }else{ - return String.format("%s", temp.Plus(Integer.parseInt(first.toString()), Integer.parseInt(second.toString()))); - } - } - - public String minus(Object first, Object second, String type) { - final ICalc temp = (ICalc) applicationContext.getBean(type); - if (temp instanceof CalcStr) { - return String.format("%s", temp.Minus(first, second)); - }else{ - return String.format("%s", temp.Minus(Integer.parseInt(first.toString()), Integer.parseInt(second.toString()))); - } - } - - public String mult(Object first, Object second, String type) { - final ICalc temp = (ICalc) applicationContext.getBean(type); - if (temp instanceof CalcStr) { - return String.format("%s", temp.Mult(first, second)); - }else{ - return String.format("%s", temp.Mult(Integer.parseInt(first.toString()), Integer.parseInt(second.toString()))); - } - } - - public String div(Object first, Object second, String type) { - final ICalc temp = (ICalc) applicationContext.getBean(type); - if (temp instanceof CalcStr) { - return String.format("%s", temp.Div(first, second)); - }else{ - return String.format("%s", temp.Div(Integer.parseInt(first.toString()), Integer.parseInt(second.toString()))); - } - } -} diff --git a/src/main/java/com/labwork1/app/student/controller/CustomerController.java b/src/main/java/com/labwork1/app/student/controller/CustomerController.java deleted file mode 100644 index 163312c..0000000 --- a/src/main/java/com/labwork1/app/student/controller/CustomerController.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.labwork1.app.student.controller; - -import com.labwork1.app.student.model.Customer; -import com.labwork1.app.student.service.CustomerService; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequestMapping("/customer") -public class CustomerController { - private final CustomerService customerService; - - public CustomerController(CustomerService studentService) { - this.customerService = studentService; - } - - @GetMapping("/{id}") - public Customer getCustomer(@PathVariable Long id) { - return customerService.findCustomer(id); - } - - @GetMapping("/") - public List gesCustomers() { - return customerService.findAllCustomers(); - } - - @PostMapping("/") - public Customer createCustomer(@RequestParam("login") String login, - @RequestParam("password") String password) { - return customerService.addCustomer(login, password); - } - - @PatchMapping("/{id}") - public Customer updateStudent(@PathVariable Long id, - @RequestParam("login") String login, - @RequestParam("password") String password) { - return customerService.updateCustomer(id, login, password); - } - - @DeleteMapping("/{id}") - public Customer deleteCustomer(@PathVariable Long id) { - return customerService.deleteCustomer(id); - } -} \ No newline at end of file diff --git a/src/main/java/com/labwork1/app/student/model/Customer.java b/src/main/java/com/labwork1/app/student/model/Customer.java index 2d366b5..247efea 100644 --- a/src/main/java/com/labwork1/app/student/model/Customer.java +++ b/src/main/java/com/labwork1/app/student/model/Customer.java @@ -15,20 +15,44 @@ public class Customer { private String login; @Column private String password; - @OneToMany(fetch = FetchType.EAGER, mappedBy = "customer", cascade = CascadeType.ALL) + @OneToMany(fetch = FetchType.EAGER, mappedBy = "customer", cascade = CascadeType.REMOVE) private List orders; public Customer() { } - public Customer(String firstName, String password) { - this.login = firstName; + public Customer(String login, String password) { + this.login = login; this.password = password; this.orders = new ArrayList<>(); } - public List getOrders() { - return orders; + + public void addOrder(Order order) { + orders.add(order); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Customer customer = (Customer) o; + return Objects.equals(id, customer.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } + + @Override + public String toString() { + return "Customer {" + + "id=" + id + + ", login='" + login + '\'' + + ", password='" + password + '\'' + + '}'; + } + public Long getId() { return id; } @@ -49,25 +73,11 @@ public class Customer { this.password = password; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Customer customer = (Customer) o; - return Objects.equals(id, customer.id); + public List getOrders() { + return orders; } - @Override - public int hashCode() { - return Objects.hash(id); - } - - @Override - public String toString() { - return "Customer{" + - "id=" + id + - ", login='" + login + '\'' + - ", password='" + password + '\'' + - '}'; + public void setOrders(List orders) { + this.orders = orders; } } diff --git a/src/main/java/com/labwork1/app/student/model/Order.java b/src/main/java/com/labwork1/app/student/model/Order.java index fe07af9..2967209 100644 --- a/src/main/java/com/labwork1/app/student/model/Order.java +++ b/src/main/java/com/labwork1/app/student/model/Order.java @@ -2,8 +2,7 @@ package com.labwork1.app.student.model; import jakarta.persistence.*; -import java.util.ArrayList; -import java.util.Date; +import java.sql.Date; import java.util.List; import java.util.Objects; @@ -17,30 +16,49 @@ public class Order { @Temporal(TemporalType.DATE) private Date dateOfPurchase; @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name="customer_fk") + @JoinColumn(name = "customer_fk") private Customer customer; - @ManyToMany(mappedBy = "orders") + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "order_ticket", + joinColumns = @JoinColumn(name = "order_fk"), + inverseJoinColumns = @JoinColumn(name = "ticket_fk")) private List tickets; - public Order(Customer customer, Date dateOfPurchase) { + + public Order() { + } + + public Order(Customer customer, Date dateOfPurchase, List tickets) { this.customer = customer; this.dateOfPurchase = dateOfPurchase; - this.tickets = new ArrayList<>(); + this.tickets = tickets; } + public void addTicket(Ticket ticket) { - if (tickets == null){ - tickets = new ArrayList<>(); - } - this.tickets.add(ticket); + tickets.add(ticket); if (ticket.getOrders() == null) { ticket.setOrder(this); } } - public Order() { + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Order order = (Order) o; + return Objects.equals(id, order.id); } - public void setId(Long id) { - this.id = id; + @Override + public int hashCode() { + return Objects.hash(id); + } + + @Override + public String toString() { + return "Order {" + + "id=" + id + + ", date='" + dateOfPurchase.toString() + '\'' + + ", customer='" + customer.toString() + '\''; } public Long getId() { @@ -70,26 +88,4 @@ public class Order { public void setTickets(List tickets) { this.tickets = tickets; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Order customer = (Order) o; - return Objects.equals(id, customer.id); - } - - @Override - public int hashCode() { - return Objects.hash(id); - } - - @Override - public String toString() { - return "OrderItem={" + - "id=" + id + - ", date='" + dateOfPurchase.toString() + '\'' + - ", customer='" + customer.toString() + '\'' + - ", tickets='" + tickets.toString() + '\'' + - '}'; - } } diff --git a/src/main/java/com/labwork1/app/student/model/Ticket.java b/src/main/java/com/labwork1/app/student/model/Ticket.java index c69d1f6..e99fdc8 100644 --- a/src/main/java/com/labwork1/app/student/model/Ticket.java +++ b/src/main/java/com/labwork1/app/student/model/Ticket.java @@ -2,8 +2,7 @@ package com.labwork1.app.student.model; import jakarta.persistence.*; -import java.util.ArrayList; -import java.util.Date; +import java.sql.Timestamp; import java.util.List; import java.util.Objects; @@ -18,37 +17,46 @@ public class Ticket { private Double price; @Column @Temporal(TemporalType.TIMESTAMP) - private Date date; - @ManyToMany - @JoinTable(name = "tickets_orders", - joinColumns = @JoinColumn(name = "ticket_fk"), - inverseJoinColumns = @JoinColumn(name = "order_fk")) + private Timestamp timestamp; + @ManyToMany(fetch = FetchType.EAGER, mappedBy = "tickets") private List orders; - public Ticket(String name, Double price, Date date) { + + public Ticket() { + } + + public Ticket(String name, Double price, Timestamp timestamp) { this.name = name; this.price = price; - this.date = date; - this.orders = new ArrayList<>(); + this.timestamp = timestamp; } + public void setOrder(Order order) { - if (orders == null){ - orders = new ArrayList<>(); - } - this.orders.add(order); if (!order.getTickets().contains(this)) { order.getTickets().add(this); } } - public Ticket() { + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Ticket ticket = (Ticket) o; + return Objects.equals(id, ticket.id); } - public List getOrders() { - return orders; + @Override + public int hashCode() { + return Objects.hash(id); } - public void setId(Long id) { - this.id = id; + @Override + public String toString() { + return "Ticket {" + + "id=" + id + + ", name='" + name + '\'' + + ", price='" + price + '\'' + + ", timestamp='" + timestamp.toString() + '\'' + + '}'; } public Long getId() { @@ -63,41 +71,24 @@ public class Ticket { this.name = name; } - public double getPrice() { + public Double getPrice() { return price; } - public void setPrice(double price) { + public void setPrice(Double price) { this.price = price; } - public Date getDate() { - return date; + public Timestamp getTimestamp() { + return timestamp; } - public void setDate(Date date) { - this.date = date; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Ticket customer = (Ticket) o; - return Objects.equals(id, customer.id); + public void setTimestamp(Timestamp timestamp) { + this.timestamp = timestamp; } - @Override - public int hashCode() { - return Objects.hash(id); + public List getOrders() { + return orders; } - @Override - public String toString() { - return "Ticket={" + - "id=" + id + - ", name='" + name + '\'' + - ", price='" + price + '\'' + - ", date='" + date.toString() + '\'' + - '}'; - } } diff --git a/src/main/java/com/labwork1/app/student/service/CustomerService.java b/src/main/java/com/labwork1/app/student/service/CustomerService.java index a749406..00a7d1c 100644 --- a/src/main/java/com/labwork1/app/student/service/CustomerService.java +++ b/src/main/java/com/labwork1/app/student/service/CustomerService.java @@ -8,6 +8,7 @@ import org.springframework.util.StringUtils; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityNotFoundException; import jakarta.persistence.PersistenceContext; + import java.util.List; @Service @@ -36,7 +37,7 @@ public class CustomerService { @Transactional(readOnly = true) public List findAllCustomers() { - return em.createQuery("select s from Customer s", Customer.class) + return em.createQuery("select c from Customer c", Customer.class) .getResultList(); } @@ -45,10 +46,10 @@ public class CustomerService { if (!StringUtils.hasText(login) || !StringUtils.hasText(password)) { throw new IllegalArgumentException("Customer login/password is null or empty"); } - final Customer currentStudent = findCustomer(id); - currentStudent.setLogin(login); - currentStudent.setPassword(password); - return em.merge(currentStudent); + final Customer currentCustomer = findCustomer(id); + currentCustomer.setLogin(login); + currentCustomer.setPassword(password); + return em.merge(currentCustomer); } @Transactional diff --git a/src/main/java/com/labwork1/app/student/service/OrderService.java b/src/main/java/com/labwork1/app/student/service/OrderService.java index d59879a..88c4ac5 100644 --- a/src/main/java/com/labwork1/app/student/service/OrderService.java +++ b/src/main/java/com/labwork1/app/student/service/OrderService.java @@ -9,7 +9,7 @@ import jakarta.persistence.PersistenceContext; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Date; +import java.sql.Date; import java.util.List; @Service @@ -18,51 +18,63 @@ public class OrderService { private EntityManager em; @Transactional - public Order addOrder(Customer customer, Date dateOfPurchase) { - if (customer==null || dateOfPurchase==null ) { + public Order addOrder(Customer customer, List tickets) { + if (customer == null || tickets.size() == 0) { throw new IllegalArgumentException("addOrder empty fields"); } - final Order order = new Order(customer, dateOfPurchase); + final Order order = new Order(customer, + new Date(System.currentTimeMillis()), tickets); em.persist(order); return order; } + @Transactional + public Order addTicket(Long id, Ticket ticket) { + if (ticket == null) { + throw new IllegalArgumentException("addOrder empty fields"); + } + final Order currentOrder = findOrder(id); + currentOrder.addTicket(ticket); + return em.merge(currentOrder); + } + @Transactional(readOnly = true) public Order findOrder(Long id) { final Order order = em.find(Order.class, id); if (order == null) { - throw new EntityNotFoundException(String.format("OrderItem with id [%s] is not found", id)); + throw new EntityNotFoundException(String.format("Order with id [%s] is not found", id)); } return order; } @Transactional(readOnly = true) public List findAllOrders() { - return em.createQuery("select s from Order s", Order.class) + return em.createQuery("select o from Order o", Order.class) .getResultList(); } @Transactional public Order updateOrder(Long id, Date dateOfPurchase, List tickets) { - if (id==null || dateOfPurchase==null || tickets==null) { + if (dateOfPurchase == null || tickets == null) { throw new IllegalArgumentException("updateOrder empty fields"); } - final Order currentStudent = findOrder(id); - currentStudent.setDateOfPurchase(dateOfPurchase); - currentStudent.setTickets(tickets); - return em.merge(currentStudent); + if (tickets.size() == 0) + return deleteOrder(id); + final Order currentOrder = findOrder(id); + currentOrder.setDateOfPurchase(dateOfPurchase); + currentOrder.setTickets(tickets); + return em.merge(currentOrder); } @Transactional public Order deleteOrder(Long id) { - final Order currentCustomer = findOrder(id); - em.remove(currentCustomer); - return currentCustomer; + final Order currentOrder = findOrder(id); + em.remove(currentOrder); + return currentOrder; } @Transactional public void deleteAllOrders() { em.createQuery("delete from Order").executeUpdate(); } - } diff --git a/src/main/java/com/labwork1/app/student/service/TicketService.java b/src/main/java/com/labwork1/app/student/service/TicketService.java index 0885fa5..9a02d67 100644 --- a/src/main/java/com/labwork1/app/student/service/TicketService.java +++ b/src/main/java/com/labwork1/app/student/service/TicketService.java @@ -1,13 +1,15 @@ package com.labwork1.app.student.service; +import com.labwork1.app.student.model.Order; import com.labwork1.app.student.model.Ticket; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityNotFoundException; import jakarta.persistence.PersistenceContext; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; -import java.util.Date; +import java.sql.Timestamp; import java.util.List; @Service @@ -16,8 +18,8 @@ public class TicketService { private EntityManager em; @Transactional - public Ticket addTicket(String name, Double price, Date date) { - if (name==null|| name.equals("") || price==null || price<=0 || date==null) { + public Ticket addTicket(String name, Double price, Timestamp date) { + if (!StringUtils.hasText(name) || price <= 0 || date == null) { throw new IllegalArgumentException("addTicket empty fields"); } final Ticket ticket = new Ticket(name, price, date); @@ -36,26 +38,26 @@ public class TicketService { @Transactional(readOnly = true) public List findAllTickets() { - return em.createQuery("select s from Ticket s", Ticket.class) + return em.createQuery("select t from Ticket t", Ticket.class) .getResultList(); } @Transactional public Ticket updateTicket(Long id, String name, Double price) { - if (id==null || name==null || name.equals("") || price == null || price==0) { + if (!StringUtils.hasText(name) || price <= 0) { throw new IllegalArgumentException("updateTicket empty fields"); } - final Ticket currentStudent = findTicket(id); - currentStudent.setName(name); - currentStudent.setPrice(price); - return em.merge(currentStudent); + final Ticket currentTicket = findTicket(id); + currentTicket.setName(name); + currentTicket.setPrice(price); + return em.merge(currentTicket); } @Transactional public Ticket deleteTicket(Long id) { - final Ticket currentCustomer = findTicket(id); - em.remove(currentCustomer); - return currentCustomer; + final Ticket currentTicket = findTicket(id); + em.remove(currentTicket); + return currentTicket; } @Transactional diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ccc05e8..b7f20f7 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,4 @@ spring.main.banner-mode=off -#server.port=8080 spring.datasource.url=jdbc:h2:file:./data spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa diff --git a/src/test/java/com/labwork1/app/AppApplicationTests.java b/src/test/java/com/labwork1/app/AppApplicationTests.java deleted file mode 100644 index 357b11b..0000000 --- a/src/test/java/com/labwork1/app/AppApplicationTests.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.labwork1.app; - -import com.labwork1.app.calc.service.CalcService; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class AppApplicationTests { - - @Autowired - CalcService calcService; - - @Test - void testPlusNum() { - final String res = calcService.plus(10, 10, "num"); - Assertions.assertEquals(20, Integer.parseInt(res)); - } - @Test - void testMinusNum() { - final String res = calcService.minus(5, 2, "num"); - Assertions.assertEquals(3, Integer.parseInt(res)); - } - @Test - void testMultNum() { - final String res = calcService.mult(10, 10, "num"); - Assertions.assertEquals(100, Integer.parseInt(res)); - } - @Test - void testDivNum() { - final String res = calcService.div(20, 10, "num"); - Assertions.assertEquals(2, Integer.parseInt(res)); - } - @Test - void testPlusStr() { - final String res = calcService.plus("10", "10", "str"); - Assertions.assertEquals("1010", res); - } - @Test - void testMinusStr() { - final String res = calcService.minus("5252", "2", "str"); - Assertions.assertEquals("552", res); - } - @Test - void testMultStr() { - final String res = calcService.mult("5", "3", "str"); - Assertions.assertEquals("555", res); - } - @Test - void testDivStr() { - final String res = calcService.div("5252", "2", "str"); - Assertions.assertEquals("55", res); - } - -} diff --git a/src/test/java/com/labwork1/app/JpaCustomerTests.java b/src/test/java/com/labwork1/app/JpaCustomerTests.java index 82d79b8..71ac3b8 100644 --- a/src/test/java/com/labwork1/app/JpaCustomerTests.java +++ b/src/test/java/com/labwork1/app/JpaCustomerTests.java @@ -14,13 +14,13 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import java.util.Date; +import java.sql.Timestamp; +import java.util.ArrayList; import java.util.List; @SpringBootTest public class JpaCustomerTests { private static final Logger log = LoggerFactory.getLogger(JpaCustomerTests.class); - @Autowired private CustomerService customerService; @Autowired @@ -28,122 +28,109 @@ public class JpaCustomerTests { @Autowired private OrderService orderService; - @Test - void testCustomerCreate() { - customerService.deleteAllCustomers(); - final Customer customer = customerService.addCustomer("Иван", "Иванов"); - log.info(customer.toString()+"testCustomerCreate"); - Assertions.assertNotNull(customer.getId()); - } - - @Test - void testCustomerRead() { - customerService.deleteAllCustomers(); - final Customer customer = customerService.addCustomer("Иван", "Иванов"); - log.info(customer.toString()+"testCustomerRead1"); - final Customer findCustomer = customerService.findCustomer(customer.getId()); - log.info(findCustomer.toString()+"testCustomerRead2"); - Assertions.assertEquals(customer, findCustomer); - } - - @Test - void testCustomerReadNotFound() { - customerService.deleteAllCustomers(); - Assertions.assertThrows(EntityNotFoundException.class, () -> customerService.findCustomer(-1L)); - log.info("testCustomerReadNotFound"); - } - - @Test - void testCustomerReadAll() { - customerService.deleteAllCustomers(); - customerService.addCustomer("Иван", "Иванов"); - customerService.addCustomer("Петр", "Петров"); - final List customers = customerService.findAllCustomers(); - log.info(customers.toString()+"testCustomerReadAll"); - Assertions.assertEquals(customers.size(), 2); - } - - @Test - void testCustomerReadAllEmpty() { - customerService.deleteAllCustomers(); - final List customers = customerService.findAllCustomers(); - log.info(customers.toString()+"testCustomerReadAllEmpty"); - Assertions.assertEquals(customers.size(), 0); - } - - @Test - void testTicketCreate() { - ticketService.deleteAllTickets(); - final Ticket ticket = ticketService.addTicket("Первый", 100.0, new Date()); - log.info(ticket.toString()+"testTicketCreate"); - Assertions.assertNotNull(ticket.getId()); - } - - @Test - void testTicketRead() { - ticketService.deleteAllTickets(); - final Ticket ticket = ticketService.addTicket("Первый", 100.0, new Date()); - log.info(ticket.toString()+"testTicketRead1"); - final Ticket findTicket = ticketService.findTicket(ticket.getId()); - log.info(findTicket.toString()+"testTicketRead2"); - Assertions.assertEquals(ticket, findTicket); - } - - @Test - void testTicketReadNotFound() { - ticketService.deleteAllTickets(); - Assertions.assertThrows(EntityNotFoundException.class, () -> ticketService.findTicket(-1L)); - log.info("testTicketReadNotFound"); - } - - @Test - void testTicketReadAll() { - ticketService.deleteAllTickets(); - ticketService.addTicket("Первый", 100.0, new Date()); - ticketService.addTicket("Второй", 100.0, new Date()); - final List tickets = ticketService.findAllTickets(); - log.info(tickets.toString()+"testTicketReadAll"); - Assertions.assertEquals(tickets.size(), 2); - } - - @Test - void testTicketReadAllEmpty() { - ticketService.deleteAllTickets(); - final List tickets = ticketService.findAllTickets(); - log.info(tickets.toString()+"testTicketReadAllEmpty"); - Assertions.assertEquals(tickets.size(), 0); - } - @Test void testOrder() { - customerService.deleteAllCustomers(); - orderService.deleteAllOrders(); ticketService.deleteAllTickets(); + orderService.deleteAllOrders(); + customerService.deleteAllCustomers(); - final Ticket ticket1 = ticketService.addTicket("раз", 300.0, new Date()); - final Ticket ticket2 = ticketService.addTicket("два", 200.0, new Date()); + final Ticket ticket1 = ticketService.addTicket("Меню", 300.0, new Timestamp(System.currentTimeMillis())); + final Ticket ticket2 = ticketService.addTicket("Аватар", 200.0, new Timestamp(System.currentTimeMillis())); + List tickets = new ArrayList<>(); + tickets.add(ticket1); + tickets.add(ticket2); - final Customer customer1 = customerService.addCustomer("Иван", "Иванов"); - final Customer customer2 = customerService.addCustomer("Петр", "Иванов"); + final Customer customer1 = customerService.addCustomer("Родион", "Иванов"); - final Order order = orderService.addOrder(customer1, new Date()); - /*order.addTicket(ticket1); - order.addTicket(ticket2); - log.info(order.toString()); - - final OrderItem order1 = orderService.findOrder(order.getId()); - Assertions.assertEquals(true, order1.getTickets().contains(ticket1)); + final Order order = orderService + .addOrder(customerService.findCustomer(customer1.getId()), tickets); + final Order order1 = orderService.findOrder(order.getId()); Assertions.assertEquals(order, order1); - Assertions.assertEquals(order1.getTickets().size(), 2); + Assertions.assertEquals(customerService + .findCustomer(customer1.getId()).getOrders().size(), 1); orderService.deleteAllOrders(); Assertions.assertThrows(EntityNotFoundException.class, () -> orderService.findOrder(-1L)); - final OrderItem order2 = orderService.addOrder(customer2, new Date()); - order2.addTicket(ticket1); - order2.addTicket(ticket2); - log.info(order2.toString());*/ + final Customer customer2 = customerService.addCustomer("Иннокентий", "Иванов"); + final Ticket ticket3 = ticketService.addTicket("Чебурашка", 300.0, new Timestamp(System.currentTimeMillis())); + tickets.clear(); + tickets.add(ticket3); + final Order order2 = orderService + .addOrder(customerService.findCustomer(customer2.getId()), tickets); + + orderService.addTicket(order2.getId(), ticket1); + orderService.addTicket(order2.getId(), ticket2); + + Assertions.assertEquals(orderService + .findOrder(order2.getId()).getTickets().size(), 3); + + customerService.deleteCustomer(customer2.getId()); + Assertions.assertThrows(EntityNotFoundException.class, () -> orderService.findOrder(order2.getId())); + Assertions.assertEquals(orderService.findAllOrders().size(), 0); } + + /*@Test() + void testCustomer() { + customerService.deleteAllCustomers(); + final Customer customer = customerService.addCustomer("Иван", "Иванов"); + log.info(customer.toString() + "testCustomerCreate"); + Assertions.assertNotNull(customer.getId()); + + customerService.deleteAllCustomers(); + final Customer customer1 = customerService.addCustomer("Иван", "Иванов"); + log.info(customer1.toString() + "testCustomerRead1"); + final Customer findCustomer = customerService.findCustomer(customer1.getId()); + log.info(findCustomer.toString() + "testCustomerRead2"); + Assertions.assertEquals(customer1, findCustomer); + + customerService.deleteAllCustomers(); + Assertions.assertThrows(EntityNotFoundException.class, () -> customerService.findCustomer(-1L)); + log.info("testCustomerReadNotFound"); + + customerService.deleteAllCustomers(); + customerService.addCustomer("Иван", "Иванов"); + customerService.addCustomer("Петр", "Петров"); + final List customers1 = customerService.findAllCustomers(); + log.info(customers1.toString() + "testCustomerReadAll"); + Assertions.assertEquals(customers1.size(), 2); + + customerService.deleteAllCustomers(); + final List customers2 = customerService.findAllCustomers(); + log.info(customers2.toString() + "testCustomerReadAllEmpty"); + Assertions.assertEquals(customers2.size(), 0); + } + + @Test + void testTicket() { + ticketService.deleteAllTickets(); + final Ticket ticket1 = ticketService.addTicket("Ледниковый период", 100.0, new Timestamp(System.currentTimeMillis())); + log.info(ticket1.toString() + "testTicketCreate"); + Assertions.assertNotNull(ticket1.getId()); + + ticketService.deleteAllTickets(); + final Ticket ticket2 = ticketService.addTicket("Выживший", 100.0, new Timestamp(System.currentTimeMillis())); + log.info(ticket2.toString() + "testTicketRead1"); + final Ticket findTicket = ticketService.findTicket(ticket2.getId()); + log.info(findTicket.toString() + "testTicketRead2"); + Assertions.assertEquals(ticket2, findTicket); + + ticketService.deleteAllTickets(); + Assertions.assertThrows(EntityNotFoundException.class, () -> ticketService.findTicket(-1L)); + log.info("testTicketReadNotFound"); + + ticketService.deleteAllTickets(); + ticketService.addTicket("1+1", 100.0, new Timestamp(System.currentTimeMillis())); + ticketService.addTicket("Титаник", 100.0, new Timestamp(System.currentTimeMillis())); + final List tickets1 = ticketService.findAllTickets(); + log.info(tickets1.toString() + "testTicketReadAll"); + Assertions.assertEquals(tickets1.size(), 2); + + ticketService.deleteAllTickets(); + final List tickets2 = ticketService.findAllTickets(); + log.info(tickets2.toString() + "testTicketReadAllEmpty"); + Assertions.assertEquals(tickets2.size(), 0); + }*/ }