Skip to content

Commit

Permalink
Merge pull request #72 from JimTheCat/CU-8696y76jy_EPIC---API-v3_King…
Browse files Browse the repository at this point in the history
…a-Traczyk

feature: Creating database models with reverse database engineering provided by jpa buddy
  • Loading branch information
KinTrae authored Dec 11, 2024
2 parents dd0a4a2 + 0364984 commit e42fb28
Show file tree
Hide file tree
Showing 58 changed files with 2,217 additions and 318 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package -Dspring.profiles.active=dev --file pom.xml
run: mvn -B package -Dspring.profiles.active=test --file pom.xml
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
Engineering Thesis

## Database
If you don't have a created database yet, run script `database/install.sql`.
For production environment, you need to have an oracle database.
If you don't have a created an oracle database yet, run script `database/install.sql`.

## Profiles
`d​ev` - to run application with H2 database and enabled swagger
`swagger` - to run application with Swagger

## Swagger
To run swagger use `d​ev` profile.
To run swagger use `swagger` profile.
Link to swagger documentation: http://localhost:8080/swagger-ui/index.html

## Environment variables
`DB_URL` - database url
`DB_USERNAME` - database username
`DB_PASSWORD` - database password
`JWT_SECRET` - secret key for JWT token
`JWT_EXPIRATION_MS` - expiration time for JWT token in milliseconds

With production environment, you need to set all of these variables.
5 changes: 5 additions & 0 deletions backend/src/main/java/meowhub/backend/constants/Genders.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package meowhub.backend.constants;

public enum Genders {
FEMALE, MALE, OTHER
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package meowhub.backend.constants;

public enum PrivacySettings {
PUBLIC, FRIENDS_ONLY, PRIVATE
}
5 changes: 5 additions & 0 deletions backend/src/main/java/meowhub/backend/constants/Roles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package meowhub.backend.constants;

public enum Roles {
ROLE_USER, ROLE_ADMIN
}
11 changes: 5 additions & 6 deletions backend/src/main/java/meowhub/backend/dtos/UserDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import lombok.Builder;
import lombok.Data;
import meowhub.backend.models.ApplicationRole;
import meowhub.backend.models.Gender;
import meowhub.backend.constants.Genders;
import meowhub.backend.constants.Roles;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
@Builder
Expand All @@ -17,8 +16,8 @@ public class UserDto {
private String name;
private String surname;
private LocalDate birthdate;
private Gender gender;
private LocalDateTime createdAt;
private ApplicationRole applicationRole;
private Genders gender;
private LocalDate createdAt;
private Roles role;
private boolean isAccountNonExpired;
}
74 changes: 74 additions & 0 deletions backend/src/main/java/meowhub/backend/jpa_buddy/Chatroom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package meowhub.backend.jpa_buddy;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import java.time.LocalDate;
import java.util.LinkedHashSet;
import java.util.Set;

@Getter
@Setter
@Entity
@Table(name = "CHATROOMS", schema = "mh_chats")
public class Chatroom {
@Id
@Size(max = 36)
@ColumnDefault("sys_guid()")
@GeneratedValue(strategy = GenerationType.UUID)
@Column(name = "ID", nullable = false, length = 36)
private String id;

@NotNull
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@OnDelete(action = OnDeleteAction.RESTRICT)
@JoinColumn(name = "SENDER_ID", nullable = false)
private User sender;

@NotNull
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@OnDelete(action = OnDeleteAction.RESTRICT)
@JoinColumn(name = "RECEIVER_ID", nullable = false)
private User receiver;

@Size(max = 20)
@Column(name = "SENDER_NICK", length = 20)
private String senderNick;

@Size(max = 20)
@Column(name = "RECEIVER_NICK", length = 20)
private String receiverNick;

@Column(name = "CREATED_AT")
private LocalDate createdAt;

@Size(max = 36)
@Column(name = "CREATED_BY", length = 36)
private String createdBy;

@Column(name = "MODIFIED_AT")
private LocalDate modifiedAt;

@Size(max = 36)
@Column(name = "MODIFIED_BY", length = 36)
private String modifiedBy;

@OneToMany(mappedBy = "chatroom")
private Set<ChatroomMessage> chatroomMessages = new LinkedHashSet<>();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package meowhub.backend.jpa_buddy;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import java.time.LocalDate;
import java.util.LinkedHashSet;
import java.util.Set;

@Getter
@Setter
@Entity
@Table(name = "CHATROOM_MESSAGES", schema = "mh_chats")
public class ChatroomMessage {
@Id
@Size(max = 36)
@ColumnDefault("sys_guid()")
@GeneratedValue(strategy = GenerationType.UUID)
@Column(name = "ID", nullable = false, length = 36)
private String id;

@NotNull
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@OnDelete(action = OnDeleteAction.RESTRICT)
@JoinColumn(name = "CHATROOM_ID", nullable = false)
private Chatroom chatroom;

@NotNull
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@OnDelete(action = OnDeleteAction.RESTRICT)
@JoinColumn(name = "AUTHOR_ID", nullable = false)
private User author;

@Size(max = 2000)
@NotNull
@Column(name = "MESSAGE", nullable = false, length = 2000)
private String message;

@NotNull
@Column(name = "MSG_DATE", nullable = false)
private LocalDate msgDate;

@ManyToOne(fetch = FetchType.LAZY)
@OnDelete(action = OnDeleteAction.RESTRICT)
@JoinColumn(name = "ANSWERED_MESSAGE_ID")
private ChatroomMessage answeredMessage;

@Column(name = "CREATED_AT")
private LocalDate createdAt;

@Size(max = 36)
@Column(name = "CREATED_BY", length = 36)
private String createdBy;

@Column(name = "MODIFIED_AT")
private LocalDate modifiedAt;

@Size(max = 36)
@Column(name = "MODIFIED_BY", length = 36)
private String modifiedBy;

@OneToMany(mappedBy = "answeredMessage")
private Set<ChatroomMessage> chatroomMessages = new LinkedHashSet<>();

}
78 changes: 78 additions & 0 deletions backend/src/main/java/meowhub/backend/jpa_buddy/Comment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package meowhub.backend.jpa_buddy;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import java.time.LocalDate;
import java.util.LinkedHashSet;
import java.util.Set;

@Getter
@Setter
@Entity
@Table(name = "COMMENTS", schema = "mh_posts")
public class Comment {
@Id
@Size(max = 36)
@ColumnDefault("sys_guid()")
@GeneratedValue(strategy = GenerationType.UUID)
@Column(name = "ID", nullable = false, length = 36)
private String id;

@NotNull
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@OnDelete(action = OnDeleteAction.RESTRICT)
@JoinColumn(name = "POST_ID", nullable = false)
private Post post;

@NotNull
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@OnDelete(action = OnDeleteAction.RESTRICT)
@JoinColumn(name = "USER_ID", nullable = false)
private User user;

@Size(max = 2000)
@Column(name = "VALUE", length = 2000)
private String value;

@Column(name = "\"index\"")
private Long index;

@ManyToOne(fetch = FetchType.LAZY)
@OnDelete(action = OnDeleteAction.RESTRICT)
@JoinColumn(name = "ANSWERED_COMMENT_ID")
private Comment answeredComment;

@Column(name = "CREATED_AT")
private LocalDate createdAt;

@Size(max = 36)
@Column(name = "CREATED_BY", length = 36)
private String createdBy;

@Column(name = "MODIFIED_AT")
private LocalDate modifiedAt;

@Size(max = 36)
@Column(name = "MODIFIED_BY", length = 36)
private String modifiedBy;

@OneToMany(mappedBy = "answeredComment")
private Set<Comment> comments = new LinkedHashSet<>();

}
60 changes: 60 additions & 0 deletions backend/src/main/java/meowhub/backend/jpa_buddy/Gender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package meowhub.backend.jpa_buddy;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import meowhub.backend.constants.Genders;
import org.hibernate.annotations.ColumnDefault;

import java.time.LocalDate;
import java.util.LinkedHashSet;
import java.util.Set;

@Getter
@Setter
@Entity
@NoArgsConstructor
@Table(name = "GENDERS", schema = "mh_users")
public class Gender {
@Id
@Size(max = 36)
@ColumnDefault("sys_guid()")
@GeneratedValue(strategy = GenerationType.UUID)
@Column(name = "ID", nullable = false, length = 36)
private String id;

@Size(max = 20)
@NotNull
@Column(name = "CODE", nullable = false, length = 20)
private String code;

@Column(name = "CREATED_AT")
private LocalDate createdAt;

@Size(max = 36)
@Column(name = "CREATED_BY", length = 36)
private String createdBy;

@Column(name = "MODIFIED_AT")
private LocalDate modifiedAt;

@Size(max = 36)
@Column(name = "MODIFIED_BY", length = 36)
private String modifiedBy;

@OneToMany(mappedBy = "gender")
private Set<User> users = new LinkedHashSet<>();

public Gender(Genders genders) {
this.code = genders.name();
}
}
Loading

0 comments on commit e42fb28

Please sign in to comment.