Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BL-897 created migrate and seed for inboxes-table #4

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ out/

### VS Code ###
.vscode/

### application properties ###
application-dev.properties
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ repositories {
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.bloomtechlabs.coderheroesbea.entities;

import javax.persistence.*;

@Entity
@Table(name = "conversations")

public class Conversations {
private int conversation_id;
private Profiles profile;

/**
* Constructor.
* Default constructor is required to have Hibernate initialize the entity.
*/
public Conversations() {

}

/**
* Constructor with conversation_id.
* @param conversation_id - primary key (auto-increments, generated by database)
*/
public Conversations(int conversation_id) {
this.conversation_id = conversation_id;
}

/**
* Constructor with all fields.
* @param conversation_id - primary key (auto-increments, generated by database)
* @param profile - foreign key (table 'profiles')
*/
public Conversations(int conversation_id, Profiles profile) {
this.conversation_id = conversation_id;
this.profile = profile;
}

@Id
@Column(name = "conversation_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getConversation_id() {
return conversation_id;
}

public void setConversation_id(int conversation_id) {
this.conversation_id = conversation_id;
}

@ManyToOne(cascade = CascadeType.REMOVE)
@JoinColumn(name = "profile_id", nullable = false)
public Profiles getProfile() {
return profile;
}

public void setProfile(Profiles profile) {
this.profile = profile;
}
}
116 changes: 116 additions & 0 deletions src/main/java/com/bloomtechlabs/coderheroesbea/entities/Messages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.bloomtechlabs.coderheroesbea.entities;

import javax.persistence.*;
import java.util.Date;

@Entity
@Table(name = "messages")
public class Messages {
private int messages_id;
private Date sent_at;
private String title;
private boolean read;
private String message;
private Profiles profile;
private Conversations conversation;

/**
* Constructor.
* Default constructor is required to have Hibernate initialize the entity.
*/
public Messages() {

}

/**
* Constructor with messages_id
* @param messages_id - primary key, auto-increments, generated by database
*/
public Messages(int messages_id) {
this.messages_id = messages_id;
}

/**
* Constructor with all fields.
* @param messages_id - primary key (auto-increments, generated by database)
* @param sent_at - timestamp (auto-generated)
* @param title - string (not nullable)
* @param read - boolean (default - false)
* @param message - string (not nullable)
* @param profile - foreign key (table 'profiles')
* @param conversation - foreign key (table 'conversations')
*/
public Messages(int messages_id, Date sent_at, String title, boolean read, String message, Profiles profile,
Conversations conversation) {
this.messages_id = messages_id;
this.sent_at = sent_at;
this.title = title;
this.read = read;
this.message = message;
this.profile = profile;
this.conversation = conversation;
}
@Id
@Column(name = "messages_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getMessages_id() {
return messages_id;
}

public void setMessages_id(int messages_id) {
this.messages_id = messages_id;
}

@Column(name = "sent_at", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
public Date getSent_at() {
return sent_at;
}

public void setSent_at(Date sent_at) {
this.sent_at = sent_at;
}

@Column(name = "title", nullable = false)
public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}
@Column(name = "read", columnDefinition = "boolean default false")
public boolean getRead() {
return read;
}

public void setRead(boolean read) {
this.read = read;
}

@Column(name = "message", columnDefinition = "text", nullable = false)
public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
@ManyToOne(cascade = CascadeType.REMOVE)
@JoinColumn(name ="sent_by_profile_id", referencedColumnName = "profile_id", nullable = false)
public Profiles getProfile() {
return profile;
}

public void setProfile(Profiles profile) {
this.profile = profile;
}
@ManyToOne(cascade = CascadeType.REMOVE)
@JoinColumn(name ="conversation_id", referencedColumnName = "conversation_id", nullable = false)
public Conversations getConversation() {
return conversation;
}

public void setConversation(Conversations conversation) {
this.conversation = conversation;
}
}
118 changes: 118 additions & 0 deletions src/main/java/com/bloomtechlabs/coderheroesbea/entities/Profiles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package com.bloomtechlabs.coderheroesbea.entities;

import javax.persistence.*;

@Entity
@Table(name = "profiles")
public class Profiles {
private int profile_id;
private String email;
private String name;
private String okta_id;
private Roles role;
private String avatarUrl;
private String pending;

/**
* Constructor.
* Default constructor is required to have Hibernate initialize the entity.
*/
public Profiles() {

}

/**
* Constructor with profile_id.
* @param profile_id - primary key (auto-increments, generated by database)
*/
public Profiles(int profile_id) {
this.profile_id = profile_id;
}

/**
* Constructor with all fields.
* @param profile_id - primary key (auto-increments, generated by database)
* @param email - string
* @param name - string
* @param okta_id - string (unique)
* @param role - foreign key (table 'roles')
* @param avatarUrl - string (defaults to: 'https://i.stack.imgur.com/frlIf.png')
* @param pending - string
*/
public Profiles(int profile_id, String email, String name, String okta_id, Roles role,
String avatarUrl, String pending) {
this.profile_id = profile_id;
this.email = email;
this.name = name;
this.okta_id = okta_id;
this.role = role;
this.avatarUrl = avatarUrl;
this.pending = pending;
}

@Id
@Column(name = "profile_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getProfile_id() {
return profile_id;
}

public void setProfile_id(int profile_id) {
this.profile_id = profile_id;
}

@Column(name = "email")
public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

@Column(name = "name")
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Column(name = "okta_id", unique = true)
public String getOkta_id() {
return okta_id;
}

public void setOkta_id(String okta_id) {
this.okta_id = okta_id;
}

@ManyToOne(cascade = CascadeType.REMOVE)
@JoinColumn(name ="role_id", nullable = false)
public Roles getRole() {
return role;
}

public void setRole(Roles role) {
this.role = role;
}

@Column(name = "avatarurl", columnDefinition = "varchar(255) default 'https://i.stack.imgur.com/frlIf.png'")
public String getAvatarUrl() {
return avatarUrl;
}

public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}

@Column(name = "pending")
public String getPending() {
return pending;
}

public void setPending(String pending) {
this.pending = pending;
}
}
55 changes: 55 additions & 0 deletions src/main/java/com/bloomtechlabs/coderheroesbea/entities/Roles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.bloomtechlabs.coderheroesbea.entities;

import javax.persistence.*;

@Entity
@Table(name = "roles")
public class Roles {
private int role_id;
private String role_name;

/**
* Constructor.
* Default constructor is required to have Hibernate initialize the entity.
*/
public Roles() {

}

/**
* Constructor with role_id.
* @param role_id - primary key (auto-increments, generated by database)
*/
public Roles(int role_id) {
this.role_id = role_id;
}

/**
* Constructor with all fields.
* @param role_id - primary key (auto-increments, generated by database)
* @param role_name - string (not nullable, unique)
*/
public Roles(int role_id, String role_name) {
this.role_id = role_id;
this.role_name = role_name;
}

@Id
@Column(name = "role_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getRole_id() {
return role_id;
}

public void setRole_id(int role_id) {
this.role_id = role_id;
}
@Column(name = "role_name", nullable = false, unique = true)
public String getRole_name() {
return role_name;
}

public void setRole_name(String role_name) {
this.role_name = role_name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.bloomtechlabs.coderheroesbea.repositories;

import com.bloomtechlabs.coderheroesbea.entities.Conversations;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

/**
* Provides data exchange with the table 'conversations'
*/
@Repository
public interface ConversationsRepository extends JpaRepository<Conversations, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.bloomtechlabs.coderheroesbea.repositories;

import com.bloomtechlabs.coderheroesbea.entities.Messages;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Provides data exchange with the table 'messages'
*/
@Repository
public interface MessagesRepository extends JpaRepository<Messages, Long> {
}
Loading