feat: add class for models: user, achievments, benefints, exam and exam_result. Add relationship between their.

This commit is contained in:
Володя 2024-12-07 13:43:48 +04:00
parent cb9a204d08
commit 1fbc4460ad
7 changed files with 197 additions and 0 deletions

View File

@ -0,0 +1,31 @@
package putBit.app.models;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "achievements")
public class Achievement {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "title", unique = true, nullable = false, length = 50)
private String title ;
@Column(name = "points", nullable = false, length = 3)
private int points ;
@ManyToMany(mappedBy = "achievements")
List<User> users;
}

View File

@ -0,0 +1,28 @@
package putBit.app.models;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "benefits")
public class Benefit {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "title", unique = true,nullable = false, length = 50)
private String title ;
@ManyToMany(mappedBy = "benefits")
List<User> users;
}

View File

@ -0,0 +1,29 @@
package putBit.app.models;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.UUID;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "exams")
public class Exam {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "title", unique = true, nullable = false, length = 50)
private String title ;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "exam")
List<ExamResult> users;
}

View File

@ -0,0 +1,31 @@
package putBit.app.models;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "exam_results")
public class ExamResult {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private User user ;
@ManyToOne
@JoinColumn(name = "exam_id", nullable = false)
private Exam exam ;
@Column(name = "points", unique = true, nullable = false, length = 3)
private int points ;
}

View File

@ -0,0 +1,61 @@
package putBit.app.models;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import putBit.app.models.enums.Role;
import java.util.List;
import java.util.UUID;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "users")
public class User {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Enumerated(EnumType.STRING)
@Column(name = "role", nullable = false)
private Role role;
@Column(name = "email", nullable = false)
private String email;
@Column(name = "password", nullable = false, length = 20)
private String password;
@Column(name = "phone", length = 12)
private String phone;
@Column(name = "name", nullable = false, length = 30)
private String name;
@Column(name = "snils", unique = true, length = 11)
private String snils;
@ManyToMany
@JoinTable(
name = "user_achievements",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "achievements_id"))
List<Achievement> achievements;
@ManyToMany
@JoinTable(
name = "user_benefits",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "benefits_id"))
List<Benefit> benefits;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
List<ExamResult> exams;
}

View File

@ -0,0 +1,6 @@
package putBit.app.models.enums;
public enum Role {
USER,
ADMIN,
}

View File

@ -1 +1,12 @@
spring.application.name=app
spring.main.banner-mode=off
#server.port=8081
spring.datasource.url=jdbc:h2:file:./data
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=update
spring.h2.console.enabled=true
spring.h2.console.settings.trace=false
spring.h2.console.settings.web-allow-others=false