-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathPostsController.java
More file actions
145 lines (109 loc) · 3.35 KB
/
PostsController.java
File metadata and controls
145 lines (109 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package controller;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import model.database.MySQL;
import model.Post;
@ManagedBean(name = "postsController", eager = true)
@SessionScoped
public class PostsController implements Serializable {
private int active_id;
private String active_title;
private long active_date;
private String active_content;
private boolean active_status;
/**
* Creates a new instance of PostsController
*/
public PostsController() {
}
public int getActive_id() {
return active_id;
}
public void setActive_id(int active_id) {
this.active_id = active_id;
}
public String getActive_title() {
return active_title;
}
public void setActive_title(String active_title) {
this.active_title = active_title;
}
public long getActive_date() {
return active_date;
}
public void setActive_date(long active_date) {
this.active_date = active_date;
}
public String getActive_content() {
return active_content;
}
public void setActive_content(String active_content) {
this.active_content = active_content;
}
public boolean isActive_status() {
return active_status;
}
public void setActive_status(boolean active_status) {
this.active_status = active_status;
}
public void createPost(String title, long date, String content) throws IOException {
MySQL mysql = new MySQL();
mysql.createPost(title, date, content);
FacesContext.getCurrentInstance().getExternalContext().redirect("index.xhtml");
}
public List<Post> getAllPosts() {
MySQL mysql = new MySQL();
return mysql.getAllPosts();
}
public List<Post> getAllPublishedPosts() {
MySQL mysql = new MySQL();
return mysql.getAllPublishedPosts();
}
public List<Post> getAllUnpublishedPosts() {
MySQL mysql = new MySQL();
return mysql.getAllUnpublishedPosts();
}
public List<Post> getAllDeletedPosts() {
MySQL mysql = new MySQL();
return mysql.getAllDeletedPosts();
}
public Post getPost(int id) {
MySQL mysql = new MySQL();
return mysql.getPost(id);
}
public void updatePost(int id, String title, long date, String content, boolean status) throws IOException {
MySQL mysql = new MySQL();
mysql.updatePost(id, title, date, content, status);
FacesContext.getCurrentInstance().getExternalContext().redirect("index.xhtml");
}
public void deletePost(int id) {
MySQL mysql = new MySQL();
mysql.deletePost(id);
}
public void viewPost(int id) throws IOException {
active_id = id;
FacesContext.getCurrentInstance().getExternalContext().redirect("view_post.xhtml");
}
public void editPost(int id, String title, long date, String content, boolean status) throws IOException {
active_id = id;
active_title = title;
active_date = date;
active_content = content;
active_status = status;
FacesContext.getCurrentInstance().getExternalContext().redirect("edit_post.xhtml");
}
public void restorePost(int id) throws IOException {
MySQL mysql = new MySQL();
mysql.restorePost(id);
FacesContext.getCurrentInstance().getExternalContext().redirect("index.xhtml");
}
}