Skip to content

Commit

Permalink
Merge pull request #1 from hariclerry/entity-edit
Browse files Browse the repository at this point in the history
entity-edit
  • Loading branch information
phurpawangchuk authored Jul 1, 2024
2 parents f7f13b8 + 9140726 commit 927f137
Show file tree
Hide file tree
Showing 18 changed files with 150 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/main/java/com/waa/project/entity/AcademicResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/waa/project/entity/Admin.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/waa/project/entity/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/waa/project/entity/Discussion.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/waa/project/entity/DiscussionCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/waa/project/entity/DiscussionComments.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +24,6 @@ public class DiscussionComments {
private Student student;

@OneToMany
@JoinTable(name = "subCommentList")
@JoinTable(name = "sub_comment_list")
private List<DiscussionComments> commentsList;
}
15 changes: 12 additions & 3 deletions src/main/java/com/waa/project/entity/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Student> attendedStudents;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/waa/project/entity/Feedback.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/waa/project/entity/FeedbackCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/waa/project/entity/Major.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/com/waa/project/entity/Student.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package com.waa.project.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.Size;
import lombok.Data;

import java.util.List;
import java.util.Set;

@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
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/com/waa/project/entity/User.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
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;

@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;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/waa/project/enums/AccountStatusType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.waa.project.enums;

public enum AccountStatusType {

Active,
Banned,
Inactive
}
7 changes: 7 additions & 0 deletions src/main/java/com/waa/project/enums/GenderType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.waa.project.enums;

public enum GenderType {

Male,
Female
}
6 changes: 1 addition & 5 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -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");

0 comments on commit 927f137

Please sign in to comment.