Skip to content

Commit

Permalink
feat: database models
Browse files Browse the repository at this point in the history
Co-authored-by: Vicente <v.gonzalez.2020@alumnos.urjc.es>
  • Loading branch information
skuzow and Vicente1215 committed Feb 21, 2023
1 parent 8ce8ed8 commit 0513473
Show file tree
Hide file tree
Showing 6 changed files with 393 additions and 0 deletions.
4 changes: 4 additions & 0 deletions back/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mustache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
70 changes: 70 additions & 0 deletions back/src/main/java/net/daw/alist/models/Comment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package net.daw.alist.models;

import java.sql.Blob;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
public class Comment {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private Date date;
private User author;
private String content;

@Lob
@JsonIgnore
private Blob image;

public Comment() { }

public Comment(
User author,
String content,
Blob image
) {
this.date = new Date();
this.author = author;
this.content = content;
this.image = image;
}

public void setAuthor(User author) {
this.author = author;
}

public void setContent(String content) {
this.content = content;
}

public void setImage(Blob image) {
this.image = image;
}

public Date getDate() {
return date;
}

public User getAuthor() {
return author;
}

public String getContent() {
return content;
}

public Blob getImage() {
return image;
}

}
105 changes: 105 additions & 0 deletions back/src/main/java/net/daw/alist/models/Post.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package net.daw.alist.models;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

@Entity
public class Post {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private Date date;
private String title;

@OneToMany
private Set<User> upVotes = new HashSet<>();

@OneToMany
private Set<User> downVotes = new HashSet<>();

@OneToMany
private List<Topic> topics = new ArrayList<>();

@OneToMany
private List<PostItem> items = new ArrayList<>();

@OneToMany
private List<Comment> comments = new ArrayList<>();

public Post() { }

public Post(
String title,
List<Topic> topics,
List<PostItem> items
) {
this.date = new Date();
this.title = title;
this.topics = topics;
this.items = items;
}

public void setTitle(String title) {
this.title = title;
}

public void setUpVotes(Set<User> upVotes) {
this.upVotes = upVotes;
}

public void setDownVotes(Set<User> downVotes) {
this.downVotes = downVotes;
}

public void setTopics(List<Topic> topics) {
this.topics = topics;
}

public void setItems(List<PostItem> items) {
this.items = items;
}

public void setComments(List<Comment> comments) {
this.comments = comments;
}

public Date getDate() {
return date;
}

public String getTitle() {
return title;
}

public Set<User> getUpVotes() {
return upVotes;
}

public Set<User> getDownVotes() {
return downVotes;
}

public List<Topic> getTopics() {
return topics;
}

public List<PostItem> getItems() {
return items;
}

public List<Comment> getComments() {
return comments;
}

}
52 changes: 52 additions & 0 deletions back/src/main/java/net/daw/alist/models/PostItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package net.daw.alist.models;

import java.sql.Blob;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
public class PostItem {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String description;

@Lob
@JsonIgnore
private Blob image;

public PostItem() { }

public PostItem(
String description,
Blob image
) {
this.description = description;
this.image = image;
}

public void setDescription(String description) {
this.description = description;
}

public void setImage(Blob image) {
this.image = image;
}

public String getDescription() {
return description;
}

public Blob getImage() {
return image;
}

}
44 changes: 44 additions & 0 deletions back/src/main/java/net/daw/alist/models/Topic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.daw.alist.models;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Topic {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String name;
private String description;

public Topic() { }

public Topic(
String name,
String description
) {
this.name = name;
this.description = description;
}

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

public void setDescription(String description) {
this.description = description;
}

public String getName() {
return name;
}

public String getDescription() {
return description;
}

}
Loading

0 comments on commit 0513473

Please sign in to comment.