Refactor Article class to extend Publication and add views attribute
This commit is contained in:
@@ -2,53 +2,23 @@ package com.humanbooster.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Entity
|
||||
public class Article {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "title", nullable = false, length = 100)
|
||||
private String title;
|
||||
|
||||
@Column(name = "content", nullable = false)
|
||||
private String content;
|
||||
public class Article extends Publication {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="author_id", nullable=false)
|
||||
@JoinColumn(name="author_id", nullable = false)
|
||||
private User author;
|
||||
|
||||
private int views = 0;
|
||||
|
||||
public Article() {}
|
||||
|
||||
public Article (String title, String content, User author){
|
||||
this.title = title;
|
||||
this.content = content;
|
||||
public Article (String title, String content, LocalDate publishDate, User author, int views) {
|
||||
super(title, content, publishDate);
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
this.views = views;
|
||||
}
|
||||
|
||||
public User getAuthor() {
|
||||
@@ -63,9 +33,9 @@ public class Article {
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("Article ID: ").append(id).append("\n");
|
||||
sb.append("Title: ").append(title).append("\n");
|
||||
sb.append("Content: ").append(content).append("\n");
|
||||
sb.append("Article ID: ").append(super.getId()).append("\n");
|
||||
sb.append("Title: ").append(super.getTitle()).append("\n");
|
||||
sb.append("Content: ").append(super.getContent()).append("\n");
|
||||
sb.append("Author: ").append(author != null ? author.getName() : "Unknown").append("\n");
|
||||
|
||||
return sb.toString();
|
||||
|
||||
Reference in New Issue
Block a user