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