From 438e1ed4d46aaabd75d38b3f0212d8605c573b36 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Mon, 27 Mar 2023 17:34:32 +0400 Subject: [PATCH] =?UTF-8?q?3=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D1=8B=D0=B5?= =?UTF-8?q?=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8.=20=D0=94?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0=20=D1=81=D0=B2?= =?UTF-8?q?=D1=8F=D0=B7=D0=B8=20=D0=BC=D0=BD=D0=BE=D0=B3=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BA=D0=BE=20=D0=BC=D0=BD=D0=BE=D0=B3=D0=B8=D0=BC=20=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=B2=D1=83=D1=85=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B5=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/jpa-buddy.xml | 6 + .idea/misc.xml | 3 + .idea/uiDesigner.xml | 124 ++++++++++++++++++ spring_online_calculator/build.gradle | 7 +- .../labWork/premium_store/model/Client.java | 86 ++++++++++++ .../labWork/premium_store/model/Level.java | 61 +++++++++ .../labWork/premium_store/model/Nation.java | 61 +++++++++ .../labWork/premium_store/model/Tank.java | 87 ++++++++++++ .../src/main/resources/application.properties | 7 +- 9 files changed, 439 insertions(+), 3 deletions(-) create mode 100644 .idea/jpa-buddy.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 spring_online_calculator/src/main/java/labWork/premium_store/model/Client.java create mode 100644 spring_online_calculator/src/main/java/labWork/premium_store/model/Level.java create mode 100644 spring_online_calculator/src/main/java/labWork/premium_store/model/Nation.java create mode 100644 spring_online_calculator/src/main/java/labWork/premium_store/model/Tank.java diff --git a/.idea/jpa-buddy.xml b/.idea/jpa-buddy.xml new file mode 100644 index 0000000..d08f400 --- /dev/null +++ b/.idea/jpa-buddy.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index f5db0c5..eb814e6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -2,4 +2,7 @@ + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring_online_calculator/build.gradle b/spring_online_calculator/build.gradle index 0607477..f87e110 100644 --- a/spring_online_calculator/build.gradle +++ b/spring_online_calculator/build.gradle @@ -4,7 +4,7 @@ plugins { id 'io.spring.dependency-management' version '1.0.15.RELEASE' } -group = 'com.example' +group = 'labWork' version = '0.0.1-SNAPSHOT' sourceCompatibility = '17' @@ -14,8 +14,11 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' - developmentOnly 'org.springframework.boot:spring-boot-devtools' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'com.h2database:h2:2.1.210' + implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5' testImplementation 'org.springframework.boot:spring-boot-starter-test' + implementation 'org.springframework.boot:spring-boot-starter-validation' } tasks.named('test') { diff --git a/spring_online_calculator/src/main/java/labWork/premium_store/model/Client.java b/spring_online_calculator/src/main/java/labWork/premium_store/model/Client.java new file mode 100644 index 0000000..88b3f07 --- /dev/null +++ b/spring_online_calculator/src/main/java/labWork/premium_store/model/Client.java @@ -0,0 +1,86 @@ +package labWork.premium_store.model; + +import javax.persistence.*; +import javax.persistence.criteria.CriteriaBuilder; +import java.util.List; +import java.util.Objects; + +@Entity +public class Client { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + @Column(nullable = false, length = 255) + private String nickName; + @Column(nullable = false, length = 255) + private String email; + private Integer balance; + @ManyToMany(mappedBy = "clients") + private List tanks; + + public Client(){ } + + public Client(String nickName, String email, Integer balance){ + this.nickName = nickName; + this.email = email; + this.balance = balance; + } + + public Long getId(){ + return id; + } + + public String getNickName(){ + return nickName; + } + + public void setNickName(String nickName){ + this.nickName = nickName; + } + + public String getEmail(){ + return email; + } + + public void setEmail(String email){ + this.email = email; + } + + public Integer getBalance(){ + return balance; + } + + public void setBalance(Integer balance){ + this.balance = balance; + } + + //метод для сравнения + @Override + public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + Client client = (Client) o; + + return Objects.equals(id, client.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } + + //преобразование данных по объекту в строчку + @Override + public String toString() { + return "Student{" + + "id=" + id + + ", nickName='" + nickName + '\'' + + ", email='" + email + '\'' + + ", balance='" + balance + '\'' + + '}'; + } +} diff --git a/spring_online_calculator/src/main/java/labWork/premium_store/model/Level.java b/spring_online_calculator/src/main/java/labWork/premium_store/model/Level.java new file mode 100644 index 0000000..2b11cf2 --- /dev/null +++ b/spring_online_calculator/src/main/java/labWork/premium_store/model/Level.java @@ -0,0 +1,61 @@ +package labWork.premium_store.model; + +import javax.persistence.*; +import java.util.Objects; + +@Entity +public class Level { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + @Column(nullable = false) + private int level; + + public Level() { + } + + public Level(int level) { + this.level = level; + } + + //возвращает id + public Long getId() { + return id; + } + + //возвращает нацию + public int getLevel() { + return level; + } + + public void setLevel(int level) { + this.level = level; + } + + //метод для сравнения + @Override + public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + Level level = (Level) o; + + return Objects.equals(id, level.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } + + //преобразование данных по объекту в строчку + @Override + public String toString() { + return "Nation{" + + "id=" + id + + ", level='" + level + '}'; + } +} diff --git a/spring_online_calculator/src/main/java/labWork/premium_store/model/Nation.java b/spring_online_calculator/src/main/java/labWork/premium_store/model/Nation.java new file mode 100644 index 0000000..2b2b19d --- /dev/null +++ b/spring_online_calculator/src/main/java/labWork/premium_store/model/Nation.java @@ -0,0 +1,61 @@ +package labWork.premium_store.model; + +import javax.persistence.*; +import java.util.Objects; + +@Entity +public class Nation { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + @Column(nullable = false) + private String nation; + + public Nation() { + } + + public Nation(String nation) { + this.nation = nation; + } + + //возвращает id + public Long getId() { + return id; + } + + //возвращает нацию + public String getNation() { + return nation; + } + + public void setNation(String nation) { + this.nation = nation; + } + + //метод для сравнения + @Override + public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + Nation nation = (Nation) o; + + return Objects.equals(id, nation.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } + + //преобразование данных по объекту в строчку + @Override + public String toString() { + return "Nation{" + + "id=" + id + + ", nation='" + nation + '}'; + } +} diff --git a/spring_online_calculator/src/main/java/labWork/premium_store/model/Tank.java b/spring_online_calculator/src/main/java/labWork/premium_store/model/Tank.java new file mode 100644 index 0000000..ea271e8 --- /dev/null +++ b/spring_online_calculator/src/main/java/labWork/premium_store/model/Tank.java @@ -0,0 +1,87 @@ +package labWork.premium_store.model; + +import javax.persistence.*; +import java.util.List; + +@Entity +public class Tank { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @Column(nullable = false) + private String name; + + @ManyToOne + @JoinColumn(name = "nation_id") + private Nation nation; + + @ManyToOne + @JoinColumn(name = "level_id") + private Level level; + + @ManyToMany + @JoinTable(name = "tanks_of_clients", + joinColumns = @JoinColumn(name = "tank_fk"), + inverseJoinColumns = @JoinColumn(name = "client_fk")) + private List clients; + + @Column(nullable = false) + private int cost; + + public Tank() { + } + + public Tank(String name, int cost) { + this.name = name; + this.cost = cost; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getCost() { + return cost; + } + + public void setCost(int cost) { + this.cost = cost; + } + + public List getProducts() { + return products; + } + + public void setProducts(List products) { + this.products = products; + } + + public void addProduct(OrderProducts orderProducts){ + if (products == null){ + this.products = new ArrayList<>(); + } + if (!products.contains(orderProducts)) + this.products.add(orderProducts); + } + public void removeProducts(OrderProducts orderProducts){ + if (products.contains(orderProducts)) + this.products.remove(orderProducts); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Order order)) return false; + return Objects.equals(getId(), order.getId()) && Objects.equals(getDate(), order.getDate()) && Objects.equals(getPrice(), order.getPrice()); + } + + @Override + public int hashCode() { + return Objects.hash(getId(), getDate(), getPrice()); + } +} diff --git a/spring_online_calculator/src/main/resources/application.properties b/spring_online_calculator/src/main/resources/application.properties index 8b13789..f09bd03 100644 --- a/spring_online_calculator/src/main/resources/application.properties +++ b/spring_online_calculator/src/main/resources/application.properties @@ -1 +1,6 @@ - +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password=password +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +spring.jpa.hibernate.ddl-auto=create-drop