diff --git a/src/main/java/com/waa/project/entity/AcademicResource.java b/src/main/java/com/waa/project/entity/AcademicResource.java index 8da2e985..d9a61ff3 100644 --- a/src/main/java/com/waa/project/entity/AcademicResource.java +++ b/src/main/java/com/waa/project/entity/AcademicResource.java @@ -5,15 +5,17 @@ @Entity @Data +@Table(name = "academic_resources") public class AcademicResource { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(name = "name", nullable = false) private String name; private String body; - // files + private String files; @ManyToOne private AcademicResourceType resourceType; diff --git a/src/main/java/com/waa/project/entity/AcademicResourceType.java b/src/main/java/com/waa/project/entity/AcademicResourceType.java index 0142dd5c..cf98d5f6 100644 --- a/src/main/java/com/waa/project/entity/AcademicResourceType.java +++ b/src/main/java/com/waa/project/entity/AcademicResourceType.java @@ -5,12 +5,14 @@ @Entity @Data +@Table(name = "academic_resource_types") public class AcademicResourceType { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(name = "name", nullable = false) private String name; @Embedded diff --git a/src/main/java/com/waa/project/entity/Admin.java b/src/main/java/com/waa/project/entity/Admin.java index e5b35d3d..84b3d0e7 100644 --- a/src/main/java/com/waa/project/entity/Admin.java +++ b/src/main/java/com/waa/project/entity/Admin.java @@ -1,11 +1,14 @@ package com.waa.project.entity; -import jakarta.persistence.*; +import jakarta.persistence.Embedded; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; import lombok.Data; @Entity @Data -public class Admin extends User{ +@Table(name = "admins") +public class Admin extends User { @Embedded diff --git a/src/main/java/com/waa/project/entity/Course.java b/src/main/java/com/waa/project/entity/Course.java index 0c1285f7..3c040d51 100644 --- a/src/main/java/com/waa/project/entity/Course.java +++ b/src/main/java/com/waa/project/entity/Course.java @@ -5,12 +5,17 @@ @Entity @Data +@Table(name = "courses") public class Course { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + + @Column(name = "name", nullable = false) private String name; + + @Column(name = "code", nullable = false) private String code; @ManyToOne diff --git a/src/main/java/com/waa/project/entity/Discussion.java b/src/main/java/com/waa/project/entity/Discussion.java index c0a3b952..87a2043b 100644 --- a/src/main/java/com/waa/project/entity/Discussion.java +++ b/src/main/java/com/waa/project/entity/Discussion.java @@ -5,11 +5,14 @@ @Entity @Data +@Table(name = "discussions") public class Discussion { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + + @Column(name = "title", nullable = false) private String title; private String body; diff --git a/src/main/java/com/waa/project/entity/DiscussionCategory.java b/src/main/java/com/waa/project/entity/DiscussionCategory.java index 0129339d..2a0841b7 100644 --- a/src/main/java/com/waa/project/entity/DiscussionCategory.java +++ b/src/main/java/com/waa/project/entity/DiscussionCategory.java @@ -5,13 +5,17 @@ @Entity @Data +@Table(name = "discussion_categories") public class DiscussionCategory { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(name = "name", nullable = false) private String name; + + @Column(name = "description") private String description; @Embedded diff --git a/src/main/java/com/waa/project/entity/DiscussionComments.java b/src/main/java/com/waa/project/entity/DiscussionComments.java index 6e83d1a5..e1a86b9d 100644 --- a/src/main/java/com/waa/project/entity/DiscussionComments.java +++ b/src/main/java/com/waa/project/entity/DiscussionComments.java @@ -7,12 +7,14 @@ @Entity @Data +@Table(name = "discussion_comments") public class DiscussionComments { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(name = "comments", nullable = false) private String comment; @ManyToOne @@ -22,6 +24,6 @@ public class DiscussionComments { private Student student; @OneToMany - @JoinTable(name = "subCommentList") + @JoinTable(name = "sub_comment_list") private List commentsList; } diff --git a/src/main/java/com/waa/project/entity/Event.java b/src/main/java/com/waa/project/entity/Event.java index e508721c..846a7398 100644 --- a/src/main/java/com/waa/project/entity/Event.java +++ b/src/main/java/com/waa/project/entity/Event.java @@ -9,23 +9,32 @@ @Entity @Data +@Table(name = "events") public class Event { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(name = "name", nullable = false) private String name; + + @Column(name = "body", nullable = false) private String body; + + @Column(nullable = false) private LocalDate eventDate; + + @Column(nullable = false) private LocalTime eventTime; + private String files; // @ManyToOne // private Admin createdByAdmin; - - @ManyToOne - private DiscussionCategory category; +// +// @ManyToOne +// private DiscussionCategory category; @ManyToMany private List attendedStudents; diff --git a/src/main/java/com/waa/project/entity/Feedback.java b/src/main/java/com/waa/project/entity/Feedback.java index a5660c24..fa24bf6d 100644 --- a/src/main/java/com/waa/project/entity/Feedback.java +++ b/src/main/java/com/waa/project/entity/Feedback.java @@ -5,13 +5,17 @@ @Entity @Data +@Table(name = "feedbacks") public class Feedback { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(name = "title", nullable = false) private String title; + + @Column(name = "body") private String body; @ManyToOne diff --git a/src/main/java/com/waa/project/entity/FeedbackCategory.java b/src/main/java/com/waa/project/entity/FeedbackCategory.java index 527d7996..163b8305 100644 --- a/src/main/java/com/waa/project/entity/FeedbackCategory.java +++ b/src/main/java/com/waa/project/entity/FeedbackCategory.java @@ -5,13 +5,17 @@ @Entity @Data +@Table(name = "feedback_categories") public class FeedbackCategory { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(name = "name", nullable = false) private String name; + + @Column(name = "description") private String description; @Embedded diff --git a/src/main/java/com/waa/project/entity/Major.java b/src/main/java/com/waa/project/entity/Major.java index ca4262d3..55474687 100644 --- a/src/main/java/com/waa/project/entity/Major.java +++ b/src/main/java/com/waa/project/entity/Major.java @@ -5,12 +5,17 @@ @Entity @Data +@Table(name = "majors") public class Major { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + + @Column(name = "name", nullable = false) private String name; + + @Column(name = "description") private String description; @Embedded diff --git a/src/main/java/com/waa/project/entity/Student.java b/src/main/java/com/waa/project/entity/Student.java index 18eda55c..af9d927a 100644 --- a/src/main/java/com/waa/project/entity/Student.java +++ b/src/main/java/com/waa/project/entity/Student.java @@ -1,6 +1,7 @@ package com.waa.project.entity; import jakarta.persistence.*; +import jakarta.validation.constraints.Size; import lombok.Data; import java.util.List; @@ -8,10 +9,16 @@ @Entity @Data -public class Student extends User{ +@Table(name = "students") +public class Student extends User { + + @Column(name = "student_code") + @Size(min = 6, max = 6, message = "Student code should be 6 digits") + private String studentCode; + + @Column(name = "academic_years") + private String academicYears; - private String student_id; - private String academicYear; private String picture; @ElementCollection diff --git a/src/main/java/com/waa/project/entity/User.java b/src/main/java/com/waa/project/entity/User.java index 1ad7b349..cfd44a74 100644 --- a/src/main/java/com/waa/project/entity/User.java +++ b/src/main/java/com/waa/project/entity/User.java @@ -1,7 +1,11 @@ package com.waa.project.entity; +import com.waa.project.enums.AccountStatusType; +import com.waa.project.enums.GenderType; import com.waa.project.enums.RoleType; import jakarta.persistence.*; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.Size; import lombok.Data; import java.time.LocalDate; @@ -9,21 +13,41 @@ @Entity @Data @Inheritance(strategy = InheritanceType.JOINED) +@Table(name = "users") public abstract class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + + @Column(name = "username") + @Size(min = 3, max = 10, message = "Name must be between 3 and 10 characters long") private String username; + + @Column(name = "password") + @Size(min = 5, max = 15, message = "Name must be between 5 and 15 characters long") private String password; + @Column(name = "first_name", nullable = false) private String firstName; + + @Column(name = "last_name", nullable = false) private String lastName; + + @Column(name = "email") + @Email private String email; + + @Column(name = "birth_date") private LocalDate birthDate; - private String gender; - private boolean acccount_Status; + @Column(name = "gender_type") + @Enumerated(EnumType.STRING) + private GenderType genderType; + + @Column(name = "account_status") + @Enumerated(EnumType.STRING) + private AccountStatusType accountStatus; @Enumerated(EnumType.STRING) private RoleType roleType; diff --git a/src/main/java/com/waa/project/enums/AccountStatusType.java b/src/main/java/com/waa/project/enums/AccountStatusType.java new file mode 100644 index 00000000..69391e47 --- /dev/null +++ b/src/main/java/com/waa/project/enums/AccountStatusType.java @@ -0,0 +1,8 @@ +package com.waa.project.enums; + +public enum AccountStatusType { + + Active, + Banned, + Inactive +} diff --git a/src/main/java/com/waa/project/enums/GenderType.java b/src/main/java/com/waa/project/enums/GenderType.java new file mode 100644 index 00000000..128ee4c5 --- /dev/null +++ b/src/main/java/com/waa/project/enums/GenderType.java @@ -0,0 +1,7 @@ +package com.waa.project.enums; + +public enum GenderType { + + Male, + Female +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 13bcf4d7..3da17a36 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,14 +1,10 @@ spring.application.name=project - spring.datasource.url=jdbc:mysql://localhost:3306/waa-demo spring.datasource.username=root -spring.datasource.password= - +spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect - spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.show-sql=true - spring.jpa.defer-datasource-initialization=true spring.sql.init.mode=always diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 00000000..62761729 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,22 @@ +spring: + application: + name: project + + datasource: + url: jdbc:mysql://localhost:3306/waa-demo + username: root + password: root + driver-class-name: com.mysql.jdbc.Driver + + jpa: + properties: + hibernate: + dialect: org.hibernate.dialect.MySQLDialect + hibernate: + ddl-auto: create-drop + show-sql: true + defer-datasource-initialization: true + + sql: + init: + mode: always diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql new file mode 100644 index 00000000..259dc6eb --- /dev/null +++ b/src/main/resources/data.sql @@ -0,0 +1,26 @@ +insert into majors (id,name,description) value (1, 'Compro', 'IT and Computer Science'); +insert into majors (id,name,description) value (2, 'MBA', 'Business Management'); + +INSERT into feedback_categories(name, description) VALUES ("University Feedback", "Feedback on University in general"); +INSERT into feedback_categories(name, description) VALUES ("Faculity Feedback", "Feedback to Faculity in general"); + +INSERT into discussion_categories(name, description) VALUES("Life in USA", "Personal experiences sharing being in USA"); +INSERT into discussion_categories(name, description) VALUES("Persoanl Health", "Importantce of personal health"); + +-- temp +insert into users(id,username,password,first_name,last_name,email,birth_date,gender_type,account_status,role_type) +values (1,"student1","123","Student","1","student1@gmail.com",null,"Male","Active","STUDENT"); + +-- temp +insert into students(id,student_code,major_id,academic_years,picture) values (1,"159880", 1 , "2024", "1234"); + +--temp +insert into achievements(student_id,achievements) values (1, "Successfully completed 4 Subject Master Course on Campus"); + +--temp +insert into interests(student_id,interest) values (1, "Coding"); +insert into interests(student_id,interest) values (1, "Swimming"); +insert into interests(student_id,interest) values (1, "Learning New Technology"); + +--temp +insert into extra_activities(student_id,extra_activities) values (1, "Social Party"); \ No newline at end of file