4 |
7 |
42 |
43 |
44 |
45 |
46 |
47 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/src/main/webapp/views/news.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
4 | <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
5 | <%@ page import="com.ace.hexa.dto.user.UserResponseDto"%>
6 | <%@ page import="com.ace.hexa.dto.user.UserRequestDto"%>
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
News
15 |
16 |
19 |
20 |
21 |
24 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | <%
35 | response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
36 | if (session.getAttribute("userInfo") == null) {
37 | response.sendRedirect("/hexa/home");
38 | } else {
39 | UserResponseDto dto = (UserResponseDto) session.getAttribute("userInfo");
40 | if (dto.getUser_role() == 3) {
41 | response.sendRedirect("/hexa/home");
42 | }
43 | }
44 | %>
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
News Information
56 |
57 |
58 |
59 |
60 |
61 |
62 | | No. |
63 | Title |
64 | Category |
65 | Creater |
66 |
67 | Created Date |
68 | Action |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | | ${count} |
77 | ${news.news_name} |
78 | ${news.news_category_name} |
79 | ${news.creator_name } |
80 | ${news.created_date} |
81 |
82 | Update
83 | Delete
84 | |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
98 |
99 |
100 |
103 |
104 |
105 |
107 |
108 |
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/src/main/webapp/views/users.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
4 | <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
5 | <%@ page import="com.ace.hexa.dto.user.UserResponseDto"%>
6 | <%@ page import="com.ace.hexa.dto.user.UserRequestDto"%>
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
Users
15 |
16 |
19 |
20 |
21 |
24 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | <%
35 | response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
36 | if (session.getAttribute("userInfo") == null) {
37 | response.sendRedirect("/hexa/home");
38 | } else {
39 | UserResponseDto dto = (UserResponseDto) session.getAttribute("userInfo");
40 | if (dto.getUser_role() == 3) {
41 | response.sendRedirect("/hexa/home");
42 | }
43 | }
44 | %>
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
User Information
56 |
57 |
58 |
59 |
60 |
61 |
62 | | No. |
63 | Username |
64 | Email Address |
65 | Role |
66 |
67 | Action |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | | ${count} |
76 | ${user.user_name} |
77 | ${user.user_email} |
78 | ${user.user_role_name} |
79 |
80 |
81 | Ban ${user.user_id}
84 |
85 |
86 | Unban
89 |
90 | |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
105 |
106 |
107 |
110 |
111 |
112 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
--------------------------------------------------------------------------------
/src/main/webapp/views/search.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
4 | <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
5 |
6 |
7 |
8 |
9 |
10 |
11 |
Search
12 |
13 |
14 |
17 |
18 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
44 |
45 |
66 |
67 |
68 |

69 |
70 |
71 |
72 |
73 |
74 |

75 |
76 |
77 |
78 |
79 |
80 |
94 |
95 |
96 |
97 |
99 |
100 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/src/main/webapp/views/comments.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
4 | <%@ page import="com.ace.hexa.dto.user.UserResponseDto"%>
5 | <%@ page import="com.ace.hexa.dto.user.UserRequestDto"%>
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
Comments
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | <%
29 | response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
30 | if(session.getAttribute("userInfo") == null) {
31 | response.sendRedirect("/hexa/home");
32 | } else {
33 | UserResponseDto dto = (UserResponseDto) session.getAttribute("userInfo");
34 | if (dto.getUser_role() == 3) {
35 | response.sendRedirect("/hexa/home");
36 | }
37 | }
38 | %>
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
Interaction
51 |
52 |
53 |
54 |
55 |
56 |
57 | | Id |
58 | Comment |
59 | Commented User |
60 | Commented Date |
61 | Action |
62 |
63 |
64 |
65 | <% int id = 1; %>
66 |
67 |
68 | | <%= id %> |
69 | ${interactions.comments } |
70 | ${commenters[stus.index]} |
71 | ${interactions.commented_date } |
72 |
73 |
74 | |
75 |
76 | <% id++; %>
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 |
--------------------------------------------------------------------------------
/src/main/webapp/views/searchNews.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
4 | <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
5 |
6 |
7 |
8 |
9 |
10 |
11 |
Search News
12 |
13 |
14 |
17 |
18 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
50 |
51 |
52 |
61 |
62 |
63 | -
64 |
65 |
66 | News
67 |
86 |
87 |
88 |
89 |
90 |

91 |
92 |
93 |
94 |
95 |
108 |
109 |
110 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/src/main/webapp/views/categories.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
4 | <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
5 | <%@ page import="com.ace.hexa.dto.user.UserResponseDto"%>
6 | <%@ page import="com.ace.hexa.dto.user.UserRequestDto"%>
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
Categoires
15 |
16 |
19 |
20 |
21 |
24 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | <%
35 | response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
36 | if (session.getAttribute("userInfo") == null) {
37 | response.sendRedirect("/hexa/home");
38 | } else {
39 | UserResponseDto dto = (UserResponseDto) session.getAttribute("userInfo");
40 | if (dto.getUser_role() == 3) {
41 | response.sendRedirect("/hexa/home");
42 | }
43 | }
44 | %>
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
Categories
57 |
58 |
59 |
60 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | | No. |
71 | Category Name |
72 |
73 |
74 |
75 | <% int id = 1; %>
76 |
77 |
78 | | <%= id %> |
79 | ${category.news_category_name} |
80 |
81 | <% id++; %>
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
118 |
119 |
120 |
121 |
122 |
123 |
125 |
126 |
127 |
130 |
131 |
132 |
134 |
135 |
136 |
137 |
--------------------------------------------------------------------------------
/src/main/webapp/views/details.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
4 | <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
Details
13 |
14 |
15 |
18 |
19 |
20 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
"${newsDetails.news_name}"
42 |
43 |

44 |
46 |
47 |
48 | ${newsDetails.news_location}
49 |
50 |
${newsDetails.creator_name}
51 |
52 |
53 |
55 |
${newsDetails.descriptions}
56 |
57 |
58 |
59 |
60 |
Latest News
61 |
62 |
63 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
112 |
113 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
124 |
125 |
126 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
--------------------------------------------------------------------------------
/src/main/webapp/views/set-reporters.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
4 | <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
5 | <%@ page import="com.ace.hexa.dto.user.UserResponseDto"%>
6 | <%@ page import="com.ace.hexa.dto.user.UserRequestDto"%>
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
Set Reporters
16 |
17 |
20 |
21 |
22 |
25 |
26 |
27 |
29 |
30 |
31 |
32 |
33 |
40 |
41 |
42 |
43 | <%
44 | response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
45 | if (session.getAttribute("userInfo") == null) {
46 | response.sendRedirect("/hexa/home");
47 | } else {
48 | UserResponseDto dto = (UserResponseDto) session.getAttribute("userInfo");
49 | if (dto.getUser_role() == 3) {
50 | response.sendRedirect("/hexa/home");
51 | }
52 | }
53 | %>
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
User Information
67 |
68 |
69 |
70 |
71 |
72 |
73 | | No. |
74 | Username |
75 | Email Address |
76 | Role |
77 | Action |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | | ${count} |
86 | ${user.user_name} |
87 | ${user.user_email} |
88 |
89 |
92 |
101 | |
102 |
103 |
104 | Ban
106 |
107 |
108 | Unban
110 |
111 | |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
125 |
126 |
127 |
130 |
131 |
132 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
--------------------------------------------------------------------------------
/src/main/webapp/views/adminDashboard.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
4 | <%@ page import="com.ace.hexa.dto.user.UserResponseDto"%>
5 | <%@ page import="com.ace.hexa.dto.user.UserRequestDto"%>
6 | <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
7 |
8 |
9 |
10 |
11 |
12 |
13 |
Dashboard
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | <%
25 | response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
26 | if(session.getAttribute("userInfo") == null) {
27 | response.sendRedirect("/hexa/home");
28 | } else {
29 | UserResponseDto dto = (UserResponseDto) session.getAttribute("userInfo");
30 | if (dto.getUser_role() == 3){
31 | response.sendRedirect("/hexa/home");
32 | }
33 | if (dto.getUser_role() == 2){
34 | response.sendRedirect("/hexa/admin/news");
35 | }
36 | }
37 | %>
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | Welcome ${sessionScope.userInfo.user_name}!
55 | ,
56 |
57 |
58 |
59 | Reporters
60 |
61 | ${reportersCount}
62 |
63 |
64 | Users
65 |
66 | ${usersCount}
67 |
68 |
69 | Total News
70 |
71 | ${newsCount}
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 |
--------------------------------------------------------------------------------
/src/main/webapp/views/adminCategories.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
4 | <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
5 | <%@ page import="com.ace.hexa.dto.user.UserResponseDto"%>
6 | <%@ page import="com.ace.hexa.dto.user.UserRequestDto"%>
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
Categories
15 |
16 |
19 |
20 |
21 |
24 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | <%
35 | response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
36 | if (session.getAttribute("userInfo") == null) {
37 | response.sendRedirect("/hexa/home");
38 | } else {
39 | UserResponseDto dto = (UserResponseDto) session.getAttribute("userInfo");
40 | if (dto.getUser_role() != 1) {
41 | response.sendRedirect("/hexa/home");
42 | }
43 | }
44 | %>
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
Categories
57 |
58 |
59 |
60 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | | No. |
71 | Category Name |
72 | News Count |
73 | Action |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | | ${count} |
82 | ${category.news_category_name} |
83 | ${category.news_count} |
84 |
85 |
86 | Delete
87 |
88 |
89 | -
90 |
91 | |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
130 |
131 |
132 |
133 |
134 |
135 |
137 |
138 |
139 |
142 |
143 |
144 |
146 |
147 |
148 |
149 |
150 |
151 |
--------------------------------------------------------------------------------
/src/main/webapp/views/create-news.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
2 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3 | <%@ page import="com.ace.hexa.dto.user.UserResponseDto" %>
4 | <%@ page import="com.ace.hexa.dto.user.UserRequestDto" %>
5 | <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
Create News
16 |
17 |
20 |
21 |
22 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | <% response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate" ); if
32 | (session.getAttribute("userInfo")==null) { response.sendRedirect("/hexa/home"); } else {
33 | UserResponseDto dto=(UserResponseDto) session.getAttribute("userInfo"); if
34 | (dto.getUser_role()==3) { response.sendRedirect("/hexa/home"); } } %>
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
CREATE NEWS
47 |
48 |
${post_msg}
49 |
50 |
51 |
Something
52 | messages
53 |
56 |
57 |
58 |
59 |
62 |
63 |
64 |
65 |
67 |
69 |
71 |
72 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
82 |
84 |
85 |
86 |
87 |
89 |
92 |
93 |
94 |
95 |
96 |
98 |
99 |
100 |
101 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
119 |
120 |
121 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/src/main/webapp/views/setup-news.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
2 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3 | <%@ page import="com.ace.hexa.dto.user.UserResponseDto" %>
4 | <%@ page import="com.ace.hexa.dto.user.UserRequestDto" %>
5 | <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
Setup News
16 |
17 |
20 |
21 |
22 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | <% response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate" ); if
34 | (session.getAttribute("userInfo")==null) { response.sendRedirect("/hexa/home"); } else {
35 | UserResponseDto dto=(UserResponseDto) session.getAttribute("userInfo"); if
36 | (dto.getUser_role()==3) { response.sendRedirect("/hexa/home"); } } %>
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
UPDATE NEWS
50 |
51 |
${post_msg}
52 |
53 |
54 |
Something
55 | messages
56 |
59 |
62 |
63 |
64 |
65 |
67 |
68 |
69 |
70 |
72 |
74 |
76 |
77 |
79 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
90 |
92 |
93 |
94 |
95 |
97 |
100 |
101 |
102 |
109 |
110 |
111 |
112 |
113 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
128 |
129 |
130 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/src/main/java/com/ace/hexa/dao/InteractionDao.java:
--------------------------------------------------------------------------------
1 | package com.ace.hexa.dao;
2 |
3 | import java.sql.Connection;
4 | import java.sql.PreparedStatement;
5 | import java.sql.ResultSet;
6 | import java.sql.SQLException;
7 | import java.util.ArrayList;
8 |
9 | import org.springframework.stereotype.Service;
10 |
11 | import com.ace.hexa.dto.interaction.InteractionRequestDto;
12 | import com.ace.hexa.dto.interaction.InteractionResponseDto;
13 |
14 | @Service
15 | public class InteractionDao {
16 |
17 | public static Connection con = null;
18 | static {
19 | try {
20 | con = JdbcConnection.getConnection();
21 | } catch (Exception e) {
22 | System.out.println(e);
23 | }
24 | }
25 |
26 | public ArrayList
selectInteractionByNewsId(long id) {
27 | ArrayList list = new ArrayList<>();
28 | String sql = "select interaction.news_id, interaction.user_id, interaction.comments, interaction.commented_date, interaction.comment_id, user_account.user_name from interaction join user_account on interaction.user_id = user_account.user_id where interaction.news_id = ?";
29 | try {
30 | PreparedStatement ps = con.prepareStatement(sql);
31 | ps.setLong(1, id);
32 | ResultSet rs = ps.executeQuery();
33 | while (rs.next()) {
34 | InteractionResponseDto res = new InteractionResponseDto();
35 | res.setNews_id(rs.getLong("news_id"));
36 | res.setUser_id(rs.getLong("user_id"));
37 | res.setComments(rs.getString("comments"));
38 | res.setUser_name(rs.getString("user_name"));
39 | res.setCommented_date(rs.getDate("commented_date").toLocalDate());
40 | res.setComment_id(rs.getLong("comment_id"));
41 | list.add(res);
42 | }
43 | } catch (Exception e) {
44 | System.out.println(e);
45 | }
46 | return list;
47 | }
48 |
49 | public int insertComment(InteractionRequestDto dto) {
50 | String sql = "insert into interaction (news_id, user_id, comments) values(?, ?, ?)";
51 | int i = 0;
52 | try {
53 | PreparedStatement ps = con.prepareStatement(sql);
54 | ps.setLong(1, dto.getNews_id());
55 | ps.setLong(2, dto.getUser_id());
56 | ps.setString(3, dto.getComments());
57 | i = ps.executeUpdate();
58 | } catch (Exception e) {
59 | System.out.println(e);
60 | }
61 | return i;
62 | }
63 |
64 | public int updateComment(InteractionRequestDto dto) {
65 | int result = 0;
66 | String sql = "UPDATE news_project.interaction SET comments = ? WHERE comment_id = ?";
67 | try {
68 | PreparedStatement ps = con.prepareStatement(sql);
69 | ps.setString(1, dto.getComments());
70 | ps.setLong(2, dto.getComment_id());
71 | result = ps.executeUpdate();
72 | } catch (SQLException e) {
73 | System.out.println("Database error");
74 | }
75 | return result;
76 | }
77 |
78 | public long getUniqueUserCount(long id) {
79 | ArrayList list = new ArrayList<>();
80 | String sql = "SELECT distinct user_id FROM interaction where news_id = ?;";
81 | try {
82 | PreparedStatement ps = con.prepareStatement(sql);
83 | ps.setLong(1, id);
84 | ResultSet rs = ps.executeQuery();
85 | while (rs.next()) {
86 | InteractionResponseDto res = new InteractionResponseDto();
87 | res.setUser_id(rs.getLong("user_id"));
88 | list.add(res);
89 | }
90 | } catch (Exception e) {
91 | System.out.println(e);
92 | }
93 | return list.size();
94 | }
95 |
96 | public InteractionResponseDto selectInteractionById(long id) {
97 | InteractionResponseDto res = new InteractionResponseDto();
98 | String sql = "select comment_id, interaction.news_id, interaction.user_id, interaction.comments, interaction.commented_date, user_account.user_name from interaction join user_account on interaction.user_id = user_account.user_id where interaction.comment_id = ?";
99 | try {
100 | PreparedStatement ps = con.prepareStatement(sql);
101 | ps.setLong(1, id);
102 | ResultSet rs = ps.executeQuery();
103 | while (rs.next()) {
104 | res.setComment_id(rs.getLong("comment_id"));
105 | res.setNews_id(rs.getLong("news_id"));
106 | res.setUser_id(rs.getLong("user_id"));
107 | res.setComments(rs.getString("comments"));
108 | res.setUser_name(rs.getString("user_name"));
109 | res.setCommented_date(rs.getDate("commented_date").toLocalDate());
110 | }
111 | } catch (Exception e) {
112 | System.out.println(e);
113 | }
114 | return res;
115 | }
116 |
117 | public ArrayList selectCommentedNewsId() {
118 | ArrayList list = new ArrayList<>();
119 | String sql = "select distinct news_id from interaction";
120 | try {
121 | PreparedStatement ps = con.prepareStatement(sql);
122 | ResultSet rs = ps.executeQuery();
123 | while (rs.next()) {
124 | list.add(rs.getLong("news_id"));
125 | }
126 | } catch (Exception e) {
127 | System.out.println(e);
128 | }
129 | return list;
130 | }
131 |
132 | public long selectCommentCountByNewsId(long news_id) {
133 | String sql = "select count(comments) as total from interaction where news_id= ?";
134 | long res = 0;
135 | try {
136 | PreparedStatement ps = con.prepareStatement(sql);
137 | ps.setLong(1, news_id);
138 | ResultSet rs = ps.executeQuery();
139 | while (rs.next()) {
140 | res = rs.getInt("total");
141 | }
142 | } catch (Exception e) {
143 | System.out.println(e);
144 | }
145 | return res;
146 | }
147 |
148 | public long selectCommentersByNewsId(long news_id) {
149 | String sql = "select count(distinct user_id) as users from interaction where news_id=?";
150 | long res = 0;
151 | try {
152 | PreparedStatement ps = con.prepareStatement(sql);
153 | ps.setLong(1, news_id);
154 | ResultSet rs = ps.executeQuery();
155 | while (rs.next()) {
156 | res = rs.getInt("users");
157 | }
158 | } catch (Exception e) {
159 | System.out.println(e);
160 | }
161 | return res;
162 | }
163 |
164 | public int deleteComment(long id) {
165 | int result = 0;
166 | String sql = "DELETE FROM `news_project`.`interaction` WHERE (`comment_id` = ?);";
167 | try {
168 | PreparedStatement ps = con.prepareStatement(sql);
169 | ps.setLong(1, id);
170 | result = ps.executeUpdate();
171 | } catch (SQLException e) {
172 | System.out.println("Database Error!!!");
173 | }
174 | return result;
175 | }
176 |
177 | public ArrayList selectCommentedNewsIdByCreatorId(long id) {
178 | ArrayList list = new ArrayList<>();
179 | String sql = "select distinct i.news_id from interaction as i inner join news as n on i.news_id = n.news_id and n.creator_id=?;";
180 | try {
181 | PreparedStatement ps = con.prepareStatement(sql);
182 | ps.setLong(1, id);
183 | ResultSet rs = ps.executeQuery();
184 | while (rs.next()) {
185 | list.add(rs.getLong("news_id"));
186 | }
187 | } catch (Exception e) {
188 | System.out.println(e);
189 | }
190 | return list;
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/src/main/resources/static/css/home.css:
--------------------------------------------------------------------------------
1 | @import url('https://fonts.googleapis.com/css2?family=Edu+SA+Beginner:wght@500;700&display=swap');
2 | :root {
3 | --text: rgba(245, 197, 125,1);
4 | --text-dark: rgba(0,0,0,0.75);
5 | --text-light: rgba(255,255,255,0.75);
6 | }
7 |
8 | * {
9 | scroll-behavior: smooth;
10 |
11 | }
12 |
13 | body {
14 | position: relative;
15 | }
16 |
17 | #navbar {
18 | -webkit-box-shadow: 0 0 15px rgba(0, 0, 0, 0.15);
19 | box-shadow: 0 0 15px rgba(0, 0, 0, 0.15);
20 | z-index: 30;
21 | background: #fff;
22 | }
23 |
24 | .navbar-nav, .navbar-nav .nav-item.dropdown {
25 | cursor: pointer;
26 |
27 | }
28 |
29 | .navbar-brand, .nav-item.active {
30 | color: var(--text);
31 | font-weight: bold;
32 | }
33 |
34 | #btn-menu, #btn-close {
35 | color: var(--text);
36 | font-size: 25px;
37 | }
38 |
39 | #btn-menu:hover, #btn-close:hover {
40 | cursor: pointer;
41 | }
42 |
43 | #btn-menu, #btn-close {
44 | display: none;
45 | }
46 |
47 | #menu-layer.active {
48 | width: 100vw;
49 | height: 100vh;
50 | position: absolute;
51 | top: 0;
52 | left: 0;
53 | z-index: 80;
54 | background-color: rgba(0, 0, 0, 0.2);
55 | }
56 |
57 | #navbar-nav.show {
58 | margin-left: 0;
59 | }
60 |
61 | #welcome .col .new-box, #welcome .col .welcome-box, #news-wrapper .new-box {
62 | position: relative;
63 | }
64 |
65 | #welcome .col img, .new-box img {
66 | width: 100%;
67 | height: 100%;
68 | }
69 |
70 | #welcome .col * {
71 | font-size: 20px;
72 | font-weight: bold;
73 | color: var(--text-light);
74 | }
75 |
76 | #welcome .col .welcome-location, #welcome .col .new-location, .new-location {
77 | color: var(--text) !important;
78 | }
79 |
80 | .new-box {
81 | overflow-x: hidden !important;
82 | position: relative;
83 | }
84 |
85 | #news-wrapper #news {
86 | position: relative;
87 | border-radius: 5px;
88 | }
89 |
90 | .new-img {
91 | width: 100% !important;
92 | height: 100%;
93 | }
94 |
95 | #news-wrapper .new-title, #news-wrapper .new-location {
96 | -webkit-transform: translateX(10px);
97 | transform: translateX(10px);
98 | }
99 |
100 | #news-wrapper .new-title ,.new-title{
101 | color: rgba(255,255,255,1) !important;
102 | }
103 |
104 | #news-wrapper .new-location,.new-location {
105 | color: var(--text) !important;
106 |
107 | }
108 |
109 | .welcome-layer, .new-layer {
110 | position: absolute;
111 | width: 100%;
112 | height: 100%;
113 | top: 0;
114 | left: 0;
115 | background: rgba(0, 0, 0, 0.45);
116 | padding: 10px;
117 | display: -webkit-box;
118 | display: -ms-flexbox;
119 | display: flex;
120 | -webkit-box-orient: vertical;
121 | -webkit-box-direction: normal;
122 | -ms-flex-direction: column;
123 | flex-direction: column;
124 | gap: 5px;
125 | -webkit-box-pack: end;
126 | -ms-flex-pack: end;
127 | justify-content: flex-end;
128 | }
129 |
130 | #welcome #news{
131 | height:250px !important;
132 | border-radius: 5px;
133 | }
134 |
135 | #news{
136 | padding: 0;
137 | position: relative;
138 | }
139 |
140 | #news-wrapper .new-layer {
141 | margin: 0 auto;
142 | }
143 |
144 | #news-wrapper .new-layer {
145 | background: rgba(0, 0, 0, 0.45) !important;
146 | }
147 |
148 | #footer {
149 | background: var(--text-dark);
150 | }
151 |
152 | #footer a {
153 | color: var(--text-light);
154 | text-decoration: none;
155 | }
156 |
157 | #navbar a {
158 | color: inherit;
159 | text-decoration: none;
160 | }
161 |
162 |
163 | #news:hover .news-layer{
164 | background: none !important;
165 | }
166 |
167 | @media (max-width: 899px) {
168 | #btn-menu, #btn-close {
169 | display: block;
170 | }
171 | .navbar-brand {
172 | font-size: 25px !important;
173 | }
174 | #navbar {
175 | width:100%;
176 | padding: 10px 30px;
177 | }
178 | .nav-item, .dropdown-item {
179 | font-size: 18px !important;
180 | }
181 | .nav-item.active {
182 | color: var(--text-light);
183 | }
184 | .dropdown-menu {
185 | width: 100%;
186 | }
187 | #navbar-nav {
188 | -webkit-box-orient: vertical;
189 | -webkit-box-direction: normal;
190 | -ms-flex-direction: column;
191 | flex-direction: column;
192 | width: 300px;
193 | height: 100vh;
194 | position: absolute;
195 | top: 0;
196 | left: 0;
197 | padding: 80px 0 0 20px;
198 | -webkit-box-pack: flex-start !important;
199 | -ms-flex-pack: flex-start !important;
200 | justify-content: flex-start !important;
201 | -webkit-box-align: start !important;
202 | -ms-flex-align: start !important;
203 | align-items: flex-start !important;
204 | background:rgba(0, 0, 0, 0.95);
205 | text-align: start;
206 | z-index: 100;
207 | margin-left: -350px;
208 | -webkit-transition: 0.5s all;
209 | transition: 0.5s all;
210 | text-align: left;
211 | }
212 |
213 | #navbar-nav .nav-item{
214 | color:rgba(255,255,255,0.75);
215 | }
216 |
217 | #navbar-nav i{
218 | color:rgba(255,255,255,0.75);
219 | }
220 |
221 | .bulb{
222 | border-radius: 10px !important;
223 | padding:5px 10px !important ;
224 | }
225 |
226 |
227 | #welcome {
228 | width: 98% !important;
229 | margin: 50px 0;
230 | gap: 1rem;
231 | margin: 20px auto;
232 | }
233 | #welcome .col .new-box, #welcome .col .welcome-box {
234 | width: 98%;
235 | height: 350px;
236 | position: relative;
237 | }
238 | #welcome .col * {
239 | font-size: 23px;
240 | }
241 | #news .new-box {
242 | width: 100% !important;
243 | height: 250px;
244 | position: relative;
245 | }
246 | #news img {
247 | width: 100% !important;
248 | height: 100% !important;
249 | }
250 | #news .new-layer {
251 | width: 100%;
252 | height: 100%;
253 | top: 0;
254 | left: 0;
255 | position: absolute;
256 | background-color: rgba(0, 0, 0, 0.35);
257 | }
258 | /* #news * {
259 | color: var(--text-light);
260 | font-size: 18px;
261 | } */
262 | #news .new-location, #news .new-date {
263 | color: var(--text);
264 | }
265 | }
266 |
267 | @media (min-width: 900px) and (max-width: 1119px) {
268 | #btn-menu, #btn-close {
269 | display: none;
270 | }
271 | }
272 |
273 | @media (min-width: 1200px) {
274 | #welcome {
275 | display: -webkit-box;
276 | display: -ms-flexbox;
277 | display: flex;
278 | -webkit-box-orient: horizontal;
279 | -webkit-box-direction: normal;
280 | -ms-flex-direction: row;
281 | flex-direction: row;
282 | }
283 | #welcome #right {
284 | display: -webkit-box;
285 | display: -ms-flexbox;
286 | display: flex;
287 | -ms-flex-wrap: wrap;
288 | flex-wrap: wrap;
289 | }
290 | #welcome #right * {
291 | font-size: 15px;
292 | }
293 | #welcome #right .new-box {
294 | width: 45%;
295 | }
296 | #welcome .col .welcome-box {
297 | height: 400px;
298 | position: relative;
299 | }
300 | #news .new-box {
301 | width: 30%;
302 | }
303 | #menu-layer {
304 | display: none !important;
305 | }
306 | }
307 |
308 | /*# sourceMappingURL=home.css.map */
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM https://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM set title of command window
39 | title %0
40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
42 |
43 | @REM set %HOME% to equivalent of $HOME
44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
45 |
46 | @REM Execute a user defined script before this one
47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
51 | :skipRcPre
52 |
53 | @setlocal
54 |
55 | set ERROR_CODE=0
56 |
57 | @REM To isolate internal variables from possible post scripts, we use another setlocal
58 | @setlocal
59 |
60 | @REM ==== START VALIDATION ====
61 | if not "%JAVA_HOME%" == "" goto OkJHome
62 |
63 | echo.
64 | echo Error: JAVA_HOME not found in your environment. >&2
65 | echo Please set the JAVA_HOME variable in your environment to match the >&2
66 | echo location of your Java installation. >&2
67 | echo.
68 | goto error
69 |
70 | :OkJHome
71 | if exist "%JAVA_HOME%\bin\java.exe" goto init
72 |
73 | echo.
74 | echo Error: JAVA_HOME is set to an invalid directory. >&2
75 | echo JAVA_HOME = "%JAVA_HOME%" >&2
76 | echo Please set the JAVA_HOME variable in your environment to match the >&2
77 | echo location of your Java installation. >&2
78 | echo.
79 | goto error
80 |
81 | @REM ==== END VALIDATION ====
82 |
83 | :init
84 |
85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
86 | @REM Fallback to current working directory if not found.
87 |
88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
90 |
91 | set EXEC_DIR=%CD%
92 | set WDIR=%EXEC_DIR%
93 | :findBaseDir
94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
95 | cd ..
96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
97 | set WDIR=%CD%
98 | goto findBaseDir
99 |
100 | :baseDirFound
101 | set MAVEN_PROJECTBASEDIR=%WDIR%
102 | cd "%EXEC_DIR%"
103 | goto endDetectBaseDir
104 |
105 | :baseDirNotFound
106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
107 | cd "%EXEC_DIR%"
108 |
109 | :endDetectBaseDir
110 |
111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
112 |
113 | @setlocal EnableExtensions EnableDelayedExpansion
114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116 |
117 | :endReadAdditionalConfig
118 |
119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122 |
123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
124 |
125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
127 | )
128 |
129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data.
131 | if exist %WRAPPER_JAR% (
132 | if "%MVNW_VERBOSE%" == "true" (
133 | echo Found %WRAPPER_JAR%
134 | )
135 | ) else (
136 | if not "%MVNW_REPOURL%" == "" (
137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
138 | )
139 | if "%MVNW_VERBOSE%" == "true" (
140 | echo Couldn't find %WRAPPER_JAR%, downloading it ...
141 | echo Downloading from: %DOWNLOAD_URL%
142 | )
143 |
144 | powershell -Command "&{"^
145 | "$webclient = new-object System.Net.WebClient;"^
146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
148 | "}"^
149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
150 | "}"
151 | if "%MVNW_VERBOSE%" == "true" (
152 | echo Finished downloading %WRAPPER_JAR%
153 | )
154 | )
155 | @REM End of extension
156 |
157 | @REM Provide a "standardized" way to retrieve the CLI args that will
158 | @REM work with both Windows and non-Windows executions.
159 | set MAVEN_CMD_LINE_ARGS=%*
160 |
161 | %MAVEN_JAVA_EXE% ^
162 | %JVM_CONFIG_MAVEN_PROPS% ^
163 | %MAVEN_OPTS% ^
164 | %MAVEN_DEBUG_OPTS% ^
165 | -classpath %WRAPPER_JAR% ^
166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
168 | if ERRORLEVEL 1 goto error
169 | goto end
170 |
171 | :error
172 | set ERROR_CODE=1
173 |
174 | :end
175 | @endlocal & set ERROR_CODE=%ERROR_CODE%
176 |
177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
181 | :skipRcPost
182 |
183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause
185 |
186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
187 |
188 | cmd /C exit /B %ERROR_CODE%
189 |
--------------------------------------------------------------------------------
/src/main/resources/static/js/comment_script.js:
--------------------------------------------------------------------------------
1 | const commentContainer = $("#comments");
2 | const route = window.location.href.split("/");
3 | const userName = $("#user-name").html();
4 | const commentForm = $("#comment-form");
5 | var status = "See More";
6 | var seeMore = false;
7 | var comments = [];//to control see more or see less
8 |
9 |
10 | $(document).ready(() => {
11 | let newsId = route[route.length -1];
12 | getComments(newsId);
13 | $("#btn-view").html(status);
14 |
15 | commentForm.on("submit", handleComment);
16 | seeMore = $("#btn-view").attr("data-show") == "true";
17 |
18 | $("#btn-view").click(() => {
19 | if(!seeMore && comments.length > 2){
20 | $("#comments #comment").each((idx,e) => {
21 | e.classList.remove("hide");
22 | });
23 | status = "See Less";
24 | seeMore = true;
25 | $("#btn-view").attr("data-show",seeMore).html(status);
26 | }else{
27 | $("#comments #comment").each((idx,e) => {
28 | if(idx > 1){
29 | e.classList.add("hide");
30 | }
31 | })
32 | status = "See More";
33 | seeMore = false;
34 | $("#btn-view").attr("data-show",seeMore).html(status);
35 | }
36 | });
37 | });
38 |
39 | function getComments(newsId){
40 | fetch(`http://localhost:8080/hexa/api/news/${newsId}/comments`)
41 | .then(res => res.json())
42 | .then(data => {
43 |
44 | comments = data;
45 |
46 | data.length <= 2 ? $("#btn-view").hide() : $("#btn-view").show();
47 |
48 | let html = ``;
49 | for(let i = 0 ; i < data.length ; i++){
50 |
51 | let extraHTML = '';
52 | let hide = "";
53 |
54 | // console.log(seeMore)
55 |
56 | if(i > 1 && !seeMore){
57 | hide = "hide"
58 | status = "See More";
59 | $("#btn-view").attr("data-view",seeMore).html(status);
60 | } ;
61 |
62 | if($("#user-id").attr("data-target") == data[i].user_id){
63 | extraHTML = `
64 | `
71 | }
72 | html += `
73 | `;
108 | }
109 |
110 | renderComments(html);
111 |
112 | })
113 | }
114 |
115 | function renderComments(html){
116 | commentContainer.html(html);
117 |
118 | //catched event from here cuz dom isn't rdy for other states
119 | document.querySelectorAll("#comments form").forEach(form => {
120 | form.addEventListener("submit",(e) => {
121 | handleCommentEdit(e);
122 |
123 | //finding equal id modal with data-target attr val from form
124 | $(`#comments #modal-${e.target.dataset.target}`).modal("hide");
125 | })
126 | });
127 |
128 | }
129 |
130 |
131 | function handleComment(e){
132 |
133 | e.preventDefault();
134 |
135 | let xhr = new XMLHttpRequest();
136 | let news_id = route[route.length -1];
137 |
138 |
139 | let params = JSON.stringify({
140 | "news_id" : news_id,
141 | "user_id" : $("#user-id").attr("data-target"),
142 | "comments" : $("#comment").val()
143 | });
144 |
145 |
146 | if(news_id != "" && $("#user-id") != "" && $("#comment").val() != ""){
147 | xhr.open("POST",`http://localhost:8080/hexa/api/news/${news_id}/addcomment`,true);
148 | xhr.setRequestHeader("Content-type","application/json");
149 |
150 | xhr.onload = () =>{
151 | if(xhr.status == 200){
152 | if(xhr.responseText == "Success"){
153 | getComments(news_id);
154 | }
155 | }
156 | }
157 | xhr.send(params);
158 |
159 | $("#comment").val("");
160 | }
161 | }
162 |
163 | function handleCommentEdit(e){
164 |
165 | e.preventDefault();
166 |
167 | let newsId = route[route.length -1];
168 | let cmtId = e.srcElement[1].value;
169 |
170 | let xhr = new XMLHttpRequest();
171 | xhr.open("PUT",`http://localhost:8080/hexa/api/news/${newsId}/comments/${cmtId}`,true);
172 |
173 | xhr.setRequestHeader("Content-type","application/json");
174 |
175 | xhr.onload = () => {
176 | if(xhr.status == 200){
177 | if(xhr.responseText == "Success"){
178 | getComments(newsId)
179 | }
180 | }
181 | }
182 |
183 | xhr.send(JSON.stringify({"comments" : e.srcElement[0].value , "comment_id" : cmtId}));
184 |
185 | }
186 |
187 | function handleCommentDelete(comment_id){
188 | let xhr = new XMLHttpRequest();
189 | let newsId = route[route.length -1];
190 |
191 | swal({
192 | text : 'Are you sure to delete your comment?',
193 | icon : 'warning',
194 | buttons : ['No','Yes']
195 | }).then( yes => {
196 | if(yes){
197 | xhr.open("DELETE",`http://localhost:8080/hexa/api/news/${newsId}/comments/${comment_id}`,true);
198 |
199 | xhr.onload = () => {
200 | if(xhr.status == 200){
201 | if(xhr.responseText == "Success"){
202 | getComments(newsId);
203 | }
204 | }
205 | }
206 |
207 | xhr.send();
208 | }
209 | });
210 | }
--------------------------------------------------------------------------------
/src/main/java/com/ace/hexa/controller/MainController.java:
--------------------------------------------------------------------------------
1 | package com.ace.hexa.controller;
2 |
3 | import java.util.ArrayList;
4 |
5 | import javax.servlet.http.HttpServletRequest;
6 | import javax.servlet.http.HttpSession;
7 |
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Controller;
10 | import org.springframework.ui.ModelMap;
11 | import org.springframework.web.bind.annotation.GetMapping;
12 | import org.springframework.web.bind.annotation.ModelAttribute;
13 | import org.springframework.web.bind.annotation.PathVariable;
14 | import org.springframework.web.bind.annotation.PostMapping;
15 | import org.springframework.web.bind.annotation.RequestMapping;
16 | import org.springframework.web.bind.annotation.RequestParam;
17 | import org.springframework.web.servlet.ModelAndView;
18 |
19 | import com.ace.hexa.dao.InteractionDao;
20 | import com.ace.hexa.dao.NewsDao;
21 | import com.ace.hexa.dao.UserDao;
22 | import com.ace.hexa.dto.category.CategoryResponseDto;
23 | import com.ace.hexa.dto.interaction.InteractionRequestDto;
24 | import com.ace.hexa.dto.interaction.InteractionResponseDto;
25 | import com.ace.hexa.dto.news.NewsResponseDto;
26 | import com.ace.hexa.dto.user.UserRequestDto;
27 | import com.ace.hexa.dto.user.UserResponseDto;
28 | import com.ace.hexa.model.InteractionBean;
29 | import com.ace.hexa.model.UserBean;
30 | import com.ace.hexa.service.HashingService;
31 | import com.ace.hexa.service.TodayNewsService;
32 |
33 | @Controller
34 | @RequestMapping("/hexa")
35 | public class MainController {
36 |
37 | @Autowired
38 | private UserDao userDao;
39 |
40 | @Autowired
41 | private NewsDao newsDao;
42 |
43 | @Autowired
44 | private TodayNewsService todayNewsService;
45 |
46 | @Autowired
47 | private InteractionDao interactionDao;
48 |
49 | @GetMapping("/login")
50 | public ModelAndView showLogin(HttpServletRequest request, HttpSession ses) {
51 | if (ses.getAttribute("userInfo") != null) {
52 | return new ModelAndView("redirect:/hexa/home");
53 | }
54 | return new ModelAndView("login", "bean", new UserBean());
55 | }
56 |
57 | @PostMapping("/login")
58 | public String showLogin(@ModelAttribute("bean") UserBean user, HttpSession session, HttpServletRequest request) {
59 | HashingService hash = new HashingService();
60 | String hashPassword = hash.getHash(user.getUser_password(), user.getUser_password().substring(0, 4));
61 | if (userDao.check(user.getUser_email(), hashPassword)) {
62 | UserResponseDto dto = userDao.selectByEmail(user.getUser_email());
63 | if (dto.getUser_status() == 1) {
64 | request.setAttribute("error", "You have been banned !!");
65 | return "login";
66 | }
67 | session.setAttribute("userInfo", dto);
68 | if (dto.getUser_role() == 1) {
69 | return "redirect:/hexa/admin/home";
70 | } else if (dto.getUser_role() == 2) {
71 | return "redirect:/hexa/admin/news";
72 | } else {
73 | return "redirect:/hexa/home";
74 | }
75 | }
76 | request.setAttribute("error", "Email and password do not match !!");
77 | return "login";
78 | }
79 |
80 | @GetMapping("/logout")
81 | public String logout(HttpSession session) {
82 | session.removeAttribute("userInfo");
83 | session.invalidate();
84 | return "redirect:/hexa/login";
85 | }
86 |
87 | @GetMapping("/register")
88 | public ModelAndView showRegister() {
89 | return new ModelAndView("register", "bean", new UserBean());
90 | }
91 |
92 | @PostMapping("/register")
93 | public String register(@ModelAttribute("bean") UserBean user, HttpSession session, HttpServletRequest request) {
94 |
95 | if (!userDao.checkByEmail(user.getUser_email())) {
96 | HashingService hash = new HashingService();
97 | String hashPassword = hash.getHash(user.getUser_password(), user.getUser_password().substring(0, 4));
98 | user.setUser_password(hashPassword);
99 | UserRequestDto dto = new UserRequestDto();
100 | dto.setUser_name(user.getUser_name());
101 | dto.setUser_email(user.getUser_email());
102 | dto.setUser_password(user.getUser_password());
103 | userDao.insertUser(dto);
104 | return "redirect:/hexa/login";
105 | }
106 | request.setAttribute("error", "A user with that email already exists !!
");
107 | return "register";
108 | }
109 |
110 | @PostMapping("/editUser")
111 | public String updateUser(@RequestParam("id") String id, @RequestParam("name") String name,
112 | @RequestParam("email") String email, @RequestParam("psw") String psw, HttpSession ses) {
113 | HashingService hash = new HashingService();
114 | if(psw.isBlank()) {
115 | UserResponseDto userDto = userDao.selectById(Long.valueOf(id));
116 | psw = userDto.getUser_password();
117 | } else {
118 | psw = hash.getHash(psw, psw.substring(0, 4));
119 | }
120 | UserRequestDto dto = new UserRequestDto();
121 | UserResponseDto tmp = new UserResponseDto();
122 | dto.setUser_id(Long.valueOf(id));
123 | dto.setUser_name(name);
124 | dto.setUser_email(email);
125 | dto.setUser_password(psw);
126 | if (userDao.updateUser(dto) > 0) {
127 | tmp = userDao.selectByEmail(email);
128 | ses.setAttribute("userInfo", tmp);
129 | }
130 | if (tmp.getUser_role() < 3) {
131 | return "redirect:/hexa/admin/home";
132 | }
133 | return "redirect:/hexa/home";
134 | }
135 |
136 | @GetMapping("/home")
137 | public String showNews(ModelMap model) {
138 | ArrayList newsDto = newsDao.selectAllNews();
139 | ArrayList todayNews = todayNewsService.getTodayNews(newsDto);
140 | ArrayList categories = newsDao.selectAllNewsCategory();
141 | model.addAttribute("categories", categories);
142 | model.addAttribute("newsList", newsDto);
143 | model.addAttribute("todayNews", todayNews);
144 | return "home";
145 | }
146 |
147 | @GetMapping("/details/{id}")
148 | public ModelAndView showDetails(@PathVariable long id, ModelMap model) {
149 | ArrayList interactionDto = interactionDao.selectInteractionByNewsId(id);
150 | NewsResponseDto dto = newsDao.selectNewsById(id);
151 | ArrayList latestNews = newsDao.selectLatestNews();
152 | model.addAttribute("interactions", interactionDto);
153 | model.addAttribute("newsDetails", dto);
154 | model.addAttribute("latestNews", latestNews);
155 | return new ModelAndView("details", "bean", new InteractionBean());
156 | }
157 |
158 | @PostMapping("/details/addComment/{news_id}")
159 | public String addComment(@PathVariable long news_id, @ModelAttribute("bean") InteractionBean bean) {
160 | InteractionRequestDto dto = new InteractionRequestDto();
161 | dto.setNews_id(news_id);
162 | dto.setUser_id(bean.getUser_id());
163 | dto.setComments(bean.getComments());
164 | interactionDao.insertComment(dto);
165 | return "redirect:/hexa/details/" + news_id;
166 | }
167 |
168 | @PostMapping("/editComment/{news_id}")
169 | public String updateComment(@RequestParam("cmt_id") String cmt_id, @RequestParam("cmt") String cmt,
170 | @PathVariable("news_id") Long news_id) {
171 | InteractionRequestDto dto = new InteractionRequestDto();
172 | dto.setComment_id(Long.valueOf(cmt_id));
173 | dto.setComments(cmt);
174 | interactionDao.updateComment(dto);
175 | return "redirect:/hexa/details/" + news_id;
176 | }
177 |
178 | @GetMapping("/delete_comment/{news_id}/{cmt_id}")
179 | public String deleteComment(@PathVariable("cmt_id") Long cmt_id, @PathVariable("news_id") Long news_id) {
180 | interactionDao.deleteComment(cmt_id);
181 | return "redirect:/hexa/details/" + news_id;
182 | }
183 |
184 | @GetMapping("/searchByCategory/{news_category_id}")
185 | public String searchByCategory(@PathVariable int news_category_id, ModelMap model) {
186 | ArrayList searchNews = newsDao.selectNewsByCategoryId(news_category_id);
187 | ArrayList categories = newsDao.selectAllNewsCategory();
188 | model.addAttribute("categories", categories);
189 | model.addAttribute("newsLists", searchNews);
190 | return "searchNews";
191 | }
192 |
193 | @GetMapping("/searchNewsByTitle")
194 | public String searchNewsBywords(@RequestParam("title") String title, ModelMap model) {
195 | ArrayList newsByTitle = newsDao.selectNewsByWords(title);
196 | if (newsByTitle.size() > 0) {
197 | model.addAttribute("newsByTitle", newsByTitle);
198 | // for (NewsResponseDto news : newsByTitle) {
199 | // System.out.println(news.toString());
200 | // }
201 | return "search";
202 | } else {
203 | model.addAttribute("newsByTitle", newsByTitle);
204 | return "search";
205 | }
206 |
207 | }
208 |
209 | @GetMapping("/dashboard")
210 | public String showDashboard() {
211 | return "adminDashboard";
212 | }
213 |
214 | @GetMapping("/news_manage")
215 | public String manageNews() {
216 | return "news_manage";
217 | }
218 |
219 | @GetMapping("/users")
220 | public String manageUsers() {
221 | return "users";
222 | }
223 |
224 | // edited from here
225 | @GetMapping("/search")
226 | public String searchPage() {
227 | return "search";
228 | }
229 |
230 | @GetMapping(value = "/notfound")
231 | public String notFound() {
232 | return "404";
233 | }
234 |
235 | @GetMapping(value = "/{path:[^\\.]*}")
236 | public String redirectNotFound() {
237 | return "redirect:/hexa/notfound";
238 | }
239 |
240 | }
241 |
--------------------------------------------------------------------------------
/src/main/java/com/ace/hexa/dao/UserDao.java:
--------------------------------------------------------------------------------
1 | package com.ace.hexa.dao;
2 |
3 | import java.sql.Connection;
4 | import java.sql.PreparedStatement;
5 | import java.sql.ResultSet;
6 | import java.sql.SQLException;
7 | import java.util.ArrayList;
8 |
9 | import org.springframework.stereotype.Service;
10 |
11 | import com.ace.hexa.dto.user.UserRequestDto;
12 | import com.ace.hexa.dto.user.UserResponseDto;
13 | import com.ace.hexa.dto.user.UserRoleResponseDto;
14 |
15 | @Service
16 | public class UserDao {
17 |
18 | public static Connection con = null;
19 | static {
20 | try {
21 | con = JdbcConnection.getConnection();
22 | } catch (Exception e) {
23 | System.out.println(e);
24 | }
25 | }
26 |
27 | public boolean check(String email, String password) {
28 | String sql = "select * from user_account where binary user_email=? && binary user_password=?";
29 | try {
30 | PreparedStatement st = con.prepareStatement(sql);
31 | st.setString(1, email);
32 | st.setString(2, password);
33 | ResultSet rs = st.executeQuery();
34 | if (rs.next()) {
35 | return true;
36 | }
37 | } catch (Exception e) {
38 | System.out.println(e);
39 | }
40 |
41 | return false;
42 | }
43 |
44 | public boolean checkByEmail(String email) {
45 |
46 | String sql = "select * from user_account where user_email=?";
47 | try {
48 | PreparedStatement st = con.prepareStatement(sql);
49 | st.setString(1, email);
50 | ResultSet rs = st.executeQuery();
51 | if (rs.next()) {
52 | return true;
53 | }
54 | } catch (Exception e) {
55 | System.out.println(e);
56 | }
57 |
58 | return false;
59 | }
60 |
61 | public Boolean duplicateCheckByIdAndEmail( long id , String email ){
62 | boolean status = true;
63 | String sql = "SELECT * FROM user_account WHERE user_id != ? AND user_email = ? ";
64 |
65 | try{
66 | PreparedStatement pre = con.prepareStatement(sql);
67 | pre.setLong( 1 ,id );
68 | pre.setString( 2 , email );
69 | ResultSet rs = pre.executeQuery();
70 |
71 |
72 | if(!rs.next()){
73 | status = false;
74 | }
75 |
76 | }catch(SQLException e){
77 | e.printStackTrace();
78 | }
79 |
80 | return status;
81 | }
82 |
83 | public UserResponseDto selectById(long userId) {
84 | String sql = "select * from user_account u join user_role r on u.user_role = r.user_role_id where user_id=?";
85 | UserResponseDto res = new UserResponseDto();
86 | try {
87 | PreparedStatement ps = con.prepareStatement(sql);
88 | ps.setLong(1, userId);
89 | ResultSet rs = ps.executeQuery();
90 | while (rs.next()) {
91 | res.setUser_id(rs.getLong("user_id"));
92 | res.setUser_name(rs.getString("user_name"));
93 | res.setUser_role(rs.getInt("user_role"));
94 | res.setUser_email(rs.getString("user_email"));
95 | res.setUser_password(rs.getString("user_password"));
96 | res.setUser_status(rs.getInt("user_status"));
97 | res.setUser_role_name(rs.getString("user_role_name"));
98 | }
99 | } catch (Exception e) {
100 | System.out.println(e);
101 | }
102 | return res;
103 | }
104 |
105 | public UserResponseDto selectByEmail(String user_email) {
106 | String sql = "select * from user_account join user_role on user_account.user_role = user_role.user_role_id where user_email=?";
107 | UserResponseDto res = new UserResponseDto();
108 | try {
109 | PreparedStatement ps = con.prepareStatement(sql);
110 | ps.setString(1, user_email);
111 | ResultSet rs = ps.executeQuery();
112 | while (rs.next()) {
113 | res.setUser_id(rs.getLong("user_id"));
114 | res.setUser_name(rs.getString("user_name"));
115 | res.setUser_role(rs.getInt("user_role"));
116 | res.setUser_email(rs.getString("user_email"));
117 | res.setUser_password(rs.getString("user_password"));
118 | res.setUser_role_name(rs.getString("user_role_name"));
119 | res.setUser_status(rs.getInt("user_status"));
120 | }
121 | } catch (Exception e) {
122 | System.out.println(e);
123 | }
124 | return res;
125 | }
126 |
127 | public ArrayList selectAllUsers() {
128 | ArrayList list = new ArrayList<>();
129 | String sql = "select user_account.user_id, user_account.user_name, user_account.user_email, user_account.user_status, user_role.user_role_name from user_account join user_role on user_account.user_role = user_role.user_role_id where user_role = 3 order by user_account.user_id";
130 | try {
131 | PreparedStatement ps = con.prepareStatement(sql);
132 | ResultSet rs = ps.executeQuery();
133 | while (rs.next()) {
134 | UserResponseDto res = new UserResponseDto();
135 | res.setUser_id(rs.getLong("user_id"));
136 | res.setUser_name(rs.getString("user_name"));
137 | res.setUser_email(rs.getNString("user_email"));
138 | res.setUser_role_name(rs.getString("user_role_name"));
139 | res.setUser_status(rs.getInt("user_status"));
140 | list.add(res);
141 | }
142 | } catch (Exception e) {
143 | System.out.println(e);
144 | }
145 | return list;
146 | }
147 |
148 | public ArrayList selectAllExceptAdmins() {
149 | ArrayList list = new ArrayList<>();
150 | String sql = "select user_account.user_id, user_account.user_name, user_account.user_email, user_account.user_role , user_account.user_status, user_role.user_role_name from user_account join user_role on user_account.user_role = user_role.user_role_id where user_account.user_role <> 1 order by user_account.user_id";
151 | try {
152 | PreparedStatement ps = con.prepareStatement(sql);
153 | ResultSet rs = ps.executeQuery();
154 | while (rs.next()) {
155 | UserResponseDto res = new UserResponseDto();
156 | res.setUser_id(rs.getLong("user_id"));
157 | res.setUser_name(rs.getString("user_name"));
158 | res.setUser_email(rs.getNString("user_email"));
159 | res.setUser_role(rs.getInt("user_role"));
160 | res.setUser_role_name(rs.getString("user_role_name"));
161 | res.setUser_status(rs.getInt("user_status"));
162 | list.add(res);
163 | }
164 | } catch (Exception e) {
165 | System.out.println(e);
166 | }
167 | return list;
168 | }
169 |
170 | public int insertUser(UserRequestDto dto) {
171 | String sql = "insert into user_account (user_name, user_role, user_email, user_password, user_status) values(?, ?, ?, ?, ?)";
172 | int i = 0;
173 | try {
174 | PreparedStatement ps = con.prepareStatement(sql);
175 | ps.setString(1, dto.getUser_name());
176 | ps.setInt(2, 3);
177 | ps.setString(3, dto.getUser_email());
178 | ps.setString(4, dto.getUser_password());
179 | ps.setInt(5, 0);
180 | i = ps.executeUpdate();
181 | } catch (Exception e) {
182 | System.out.println(e);
183 | }
184 | return i;
185 | }
186 |
187 | public int updateUser(UserRequestDto dto) {
188 | String sql = "update user_account set user_name = ?, user_email = ?, user_password = ? where user_id = ?";
189 | int i = 0;
190 | try {
191 | PreparedStatement ps = con.prepareStatement(sql);
192 | ps.setString(1, dto.getUser_name());
193 | ps.setString(2, dto.getUser_email());
194 | ps.setString(3, dto.getUser_password());
195 | ps.setLong(4, dto.getUser_id());
196 | i = ps.executeUpdate();
197 | } catch (Exception e) {
198 | System.out.println(e);
199 | }
200 | return i;
201 | }
202 |
203 | public int updateUserStatusById(int user_status, long user_id) {
204 | String sql = "update user_account set user_status = ? where user_id = ?";
205 | int i = 0;
206 | try {
207 | PreparedStatement ps = con.prepareStatement(sql);
208 | ps.setInt(1, user_status);
209 | ps.setLong(2, user_id);
210 | i = ps.executeUpdate();
211 | } catch (Exception e) {
212 | System.out.println(e);
213 | }
214 | return i;
215 | }
216 |
217 | public ArrayList selectAllRole() {
218 | ArrayList list = new ArrayList<>();
219 | String sql = "SELECT * FROM user_role;";
220 | try {
221 | PreparedStatement ps = con.prepareStatement(sql);
222 | ResultSet rs = ps.executeQuery();
223 | while (rs.next()) {
224 | UserRoleResponseDto res = new UserRoleResponseDto();
225 | res.setId(rs.getInt("user_role_id"));
226 | res.setName(rs.getString("user_role_name"));
227 | list.add(res);
228 | }
229 | } catch (SQLException e) {
230 | e.printStackTrace();
231 | }
232 | return list;
233 | }
234 |
235 | public ArrayList selectAllEmails(){
236 | ArrayList emails = new ArrayList<>();
237 | String sql = "SELECT user_email from user_account";
238 | try{
239 | PreparedStatement ps = con.prepareStatement(sql);
240 | ResultSet rs = ps.executeQuery();
241 | while(rs.next()){
242 | UserResponseDto res = new UserResponseDto();
243 | res.setUser_email(rs.getString("user_email"));
244 | emails.add(res);
245 | }
246 | }catch(SQLException e){
247 | e.printStackTrace();
248 | }
249 |
250 | return emails;
251 |
252 | }
253 |
254 | public int updateUserRoleById(int user_role, long user_id) {
255 | String sql = "update user_account set user_role = ? where user_id = ?";
256 | int i = 0;
257 | try {
258 | PreparedStatement ps = con.prepareStatement(sql);
259 | ps.setInt(1, user_role);
260 | ps.setLong(2, user_id);
261 | i = ps.executeUpdate();
262 | } catch (Exception e) {
263 | System.out.println(e);
264 | }
265 | return i;
266 | }
267 |
268 | public long getReportersCount() {
269 | String sql = "select count(user_id) as repoters from user_account where user_role= 2";
270 | long res = 0;
271 | try {
272 | PreparedStatement ps = con.prepareStatement(sql);
273 | ResultSet rs = ps.executeQuery();
274 | while (rs.next()) {
275 | res = rs.getInt("repoters");
276 | }
277 | } catch (Exception e) {
278 | System.out.println(e);
279 | }
280 | return res;
281 | }
282 |
283 | public long getUsersCount() {
284 | String sql = "select count(user_id) as users from user_account where user_role = 3";
285 | long res = 0;
286 | try {
287 | PreparedStatement ps = con.prepareStatement(sql);
288 | ResultSet rs = ps.executeQuery();
289 | while (rs.next()) {
290 | res = rs.getInt("users");
291 | }
292 | } catch (Exception e) {
293 | System.out.println(e);
294 | }
295 | return res;
296 | }
297 | }
298 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # https://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /usr/local/etc/mavenrc ] ; then
40 | . /usr/local/etc/mavenrc
41 | fi
42 |
43 | if [ -f /etc/mavenrc ] ; then
44 | . /etc/mavenrc
45 | fi
46 |
47 | if [ -f "$HOME/.mavenrc" ] ; then
48 | . "$HOME/.mavenrc"
49 | fi
50 |
51 | fi
52 |
53 | # OS specific support. $var _must_ be set to either true or false.
54 | cygwin=false;
55 | darwin=false;
56 | mingw=false
57 | case "`uname`" in
58 | CYGWIN*) cygwin=true ;;
59 | MINGW*) mingw=true;;
60 | Darwin*) darwin=true
61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
63 | if [ -z "$JAVA_HOME" ]; then
64 | if [ -x "/usr/libexec/java_home" ]; then
65 | export JAVA_HOME="`/usr/libexec/java_home`"
66 | else
67 | export JAVA_HOME="/Library/Java/Home"
68 | fi
69 | fi
70 | ;;
71 | esac
72 |
73 | if [ -z "$JAVA_HOME" ] ; then
74 | if [ -r /etc/gentoo-release ] ; then
75 | JAVA_HOME=`java-config --jre-home`
76 | fi
77 | fi
78 |
79 | if [ -z "$M2_HOME" ] ; then
80 | ## resolve links - $0 may be a link to maven's home
81 | PRG="$0"
82 |
83 | # need this for relative symlinks
84 | while [ -h "$PRG" ] ; do
85 | ls=`ls -ld "$PRG"`
86 | link=`expr "$ls" : '.*-> \(.*\)$'`
87 | if expr "$link" : '/.*' > /dev/null; then
88 | PRG="$link"
89 | else
90 | PRG="`dirname "$PRG"`/$link"
91 | fi
92 | done
93 |
94 | saveddir=`pwd`
95 |
96 | M2_HOME=`dirname "$PRG"`/..
97 |
98 | # make it fully qualified
99 | M2_HOME=`cd "$M2_HOME" && pwd`
100 |
101 | cd "$saveddir"
102 | # echo Using m2 at $M2_HOME
103 | fi
104 |
105 | # For Cygwin, ensure paths are in UNIX format before anything is touched
106 | if $cygwin ; then
107 | [ -n "$M2_HOME" ] &&
108 | M2_HOME=`cygpath --unix "$M2_HOME"`
109 | [ -n "$JAVA_HOME" ] &&
110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
111 | [ -n "$CLASSPATH" ] &&
112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
113 | fi
114 |
115 | # For Mingw, ensure paths are in UNIX format before anything is touched
116 | if $mingw ; then
117 | [ -n "$M2_HOME" ] &&
118 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
119 | [ -n "$JAVA_HOME" ] &&
120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
121 | fi
122 |
123 | if [ -z "$JAVA_HOME" ]; then
124 | javaExecutable="`which javac`"
125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
126 | # readlink(1) is not available as standard on Solaris 10.
127 | readLink=`which readlink`
128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
129 | if $darwin ; then
130 | javaHome="`dirname \"$javaExecutable\"`"
131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
132 | else
133 | javaExecutable="`readlink -f \"$javaExecutable\"`"
134 | fi
135 | javaHome="`dirname \"$javaExecutable\"`"
136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
137 | JAVA_HOME="$javaHome"
138 | export JAVA_HOME
139 | fi
140 | fi
141 | fi
142 |
143 | if [ -z "$JAVACMD" ] ; then
144 | if [ -n "$JAVA_HOME" ] ; then
145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
146 | # IBM's JDK on AIX uses strange locations for the executables
147 | JAVACMD="$JAVA_HOME/jre/sh/java"
148 | else
149 | JAVACMD="$JAVA_HOME/bin/java"
150 | fi
151 | else
152 | JAVACMD="`\\unset -f command; \\command -v java`"
153 | fi
154 | fi
155 |
156 | if [ ! -x "$JAVACMD" ] ; then
157 | echo "Error: JAVA_HOME is not defined correctly." >&2
158 | echo " We cannot execute $JAVACMD" >&2
159 | exit 1
160 | fi
161 |
162 | if [ -z "$JAVA_HOME" ] ; then
163 | echo "Warning: JAVA_HOME environment variable is not set."
164 | fi
165 |
166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
167 |
168 | # traverses directory structure from process work directory to filesystem root
169 | # first directory with .mvn subdirectory is considered project base directory
170 | find_maven_basedir() {
171 |
172 | if [ -z "$1" ]
173 | then
174 | echo "Path not specified to find_maven_basedir"
175 | return 1
176 | fi
177 |
178 | basedir="$1"
179 | wdir="$1"
180 | while [ "$wdir" != '/' ] ; do
181 | if [ -d "$wdir"/.mvn ] ; then
182 | basedir=$wdir
183 | break
184 | fi
185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
186 | if [ -d "${wdir}" ]; then
187 | wdir=`cd "$wdir/.."; pwd`
188 | fi
189 | # end of workaround
190 | done
191 | echo "${basedir}"
192 | }
193 |
194 | # concatenates all lines of a file
195 | concat_lines() {
196 | if [ -f "$1" ]; then
197 | echo "$(tr -s '\n' ' ' < "$1")"
198 | fi
199 | }
200 |
201 | BASE_DIR=`find_maven_basedir "$(pwd)"`
202 | if [ -z "$BASE_DIR" ]; then
203 | exit 1;
204 | fi
205 |
206 | ##########################################################################################
207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
208 | # This allows using the maven wrapper in projects that prohibit checking in binary data.
209 | ##########################################################################################
210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
211 | if [ "$MVNW_VERBOSE" = true ]; then
212 | echo "Found .mvn/wrapper/maven-wrapper.jar"
213 | fi
214 | else
215 | if [ "$MVNW_VERBOSE" = true ]; then
216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
217 | fi
218 | if [ -n "$MVNW_REPOURL" ]; then
219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
220 | else
221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
222 | fi
223 | while IFS="=" read key value; do
224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
225 | esac
226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
227 | if [ "$MVNW_VERBOSE" = true ]; then
228 | echo "Downloading from: $jarUrl"
229 | fi
230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
231 | if $cygwin; then
232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
233 | fi
234 |
235 | if command -v wget > /dev/null; then
236 | if [ "$MVNW_VERBOSE" = true ]; then
237 | echo "Found wget ... using wget"
238 | fi
239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
241 | else
242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
243 | fi
244 | elif command -v curl > /dev/null; then
245 | if [ "$MVNW_VERBOSE" = true ]; then
246 | echo "Found curl ... using curl"
247 | fi
248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
249 | curl -o "$wrapperJarPath" "$jarUrl" -f
250 | else
251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
252 | fi
253 |
254 | else
255 | if [ "$MVNW_VERBOSE" = true ]; then
256 | echo "Falling back to using Java to download"
257 | fi
258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
259 | # For Cygwin, switch paths to Windows format before running javac
260 | if $cygwin; then
261 | javaClass=`cygpath --path --windows "$javaClass"`
262 | fi
263 | if [ -e "$javaClass" ]; then
264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
265 | if [ "$MVNW_VERBOSE" = true ]; then
266 | echo " - Compiling MavenWrapperDownloader.java ..."
267 | fi
268 | # Compiling the Java class
269 | ("$JAVA_HOME/bin/javac" "$javaClass")
270 | fi
271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
272 | # Running the downloader
273 | if [ "$MVNW_VERBOSE" = true ]; then
274 | echo " - Running MavenWrapperDownloader.java ..."
275 | fi
276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
277 | fi
278 | fi
279 | fi
280 | fi
281 | ##########################################################################################
282 | # End of extension
283 | ##########################################################################################
284 |
285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
286 | if [ "$MVNW_VERBOSE" = true ]; then
287 | echo $MAVEN_PROJECTBASEDIR
288 | fi
289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
290 |
291 | # For Cygwin, switch paths to Windows format before running java
292 | if $cygwin; then
293 | [ -n "$M2_HOME" ] &&
294 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
295 | [ -n "$JAVA_HOME" ] &&
296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
297 | [ -n "$CLASSPATH" ] &&
298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
299 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
301 | fi
302 |
303 | # Provide a "standardized" way to retrieve the CLI args that will
304 | # work with both Windows and non-Windows executions.
305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
306 | export MAVEN_CMD_LINE_ARGS
307 |
308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
309 |
310 | exec "$JAVACMD" \
311 | $MAVEN_OPTS \
312 | $MAVEN_DEBUG_OPTS \
313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
314 | "-Dmaven.home=${M2_HOME}" \
315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
317 |
--------------------------------------------------------------------------------
/src/main/java/com/ace/hexa/controller/AdminController.java:
--------------------------------------------------------------------------------
1 | package com.ace.hexa.controller;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 |
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpSession;
8 |
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.stereotype.Controller;
11 | import org.springframework.ui.ModelMap;
12 | import org.springframework.web.bind.annotation.GetMapping;
13 | import org.springframework.web.bind.annotation.ModelAttribute;
14 | import org.springframework.web.bind.annotation.PathVariable;
15 | import org.springframework.web.bind.annotation.PostMapping;
16 | import org.springframework.web.bind.annotation.RequestMapping;
17 | import org.springframework.web.bind.annotation.RequestParam;
18 | import org.springframework.web.servlet.ModelAndView;
19 |
20 | import com.ace.hexa.dao.InteractionDao;
21 | import com.ace.hexa.dao.NewsDao;
22 | import com.ace.hexa.dao.UserDao;
23 | import com.ace.hexa.dto.category.CategoryRequestDto;
24 | import com.ace.hexa.dto.category.CategoryResponseDto;
25 | import com.ace.hexa.dto.interaction.InteractionResponseDto;
26 | import com.ace.hexa.dto.news.NewsRequestDto;
27 | import com.ace.hexa.dto.news.NewsResponseDto;
28 | import com.ace.hexa.dto.user.UserResponseDto;
29 | import com.ace.hexa.model.NewsBean;
30 | import com.ace.hexa.model.TempNewsBean;
31 | import com.ace.hexa.service.FileService;
32 |
33 | @Controller
34 | @RequestMapping("/hexa/admin")
35 | public class AdminController {
36 |
37 | @Autowired
38 | private InteractionDao interactionDao;
39 |
40 | @Autowired
41 | private NewsDao newsDao;
42 |
43 | @Autowired
44 | private UserDao userDao;
45 |
46 | @Autowired
47 | private FileService fileService;
48 |
49 | @GetMapping("/home")
50 | public String showDashboard(ModelMap model) {
51 | model.addAttribute("reportersCount", userDao.getReportersCount());
52 | model.addAttribute("usersCount", userDao.getUsersCount());
53 | model.addAttribute("newsCount", newsDao.getNewsCount());
54 | return "adminDashboard";
55 | }
56 |
57 | @GetMapping("/users")
58 | public String showUsers(ModelMap model, HttpSession ses) {
59 | ArrayList users = new ArrayList<>();
60 | if (((UserResponseDto) ses.getAttribute("userInfo")).getUser_role() == 1) {
61 | users = userDao.selectAllExceptAdmins();
62 | model.addAttribute("users", users);
63 | model.addAttribute("roles", userDao.selectAllRole());
64 | return "set-reporters";
65 | }
66 | users = userDao.selectAllUsers();
67 | model.addAttribute("users", users);
68 | return "users";
69 | }
70 |
71 | @GetMapping("/role/{user_id}/{user_role}")
72 | public String setUserRole(@PathVariable long user_id, @PathVariable int user_role) {
73 | if (userDao.updateUserRoleById(user_role, user_id) > 0) {
74 | System.out.println("sus");
75 | }
76 | return "redirect:/hexa/admin/users";
77 | }
78 |
79 | @GetMapping("/news")
80 | public String showNews(ModelMap model, HttpSession ses) {
81 | ArrayList news = new ArrayList<>();
82 | UserResponseDto usr = (UserResponseDto) ses.getAttribute("userInfo");
83 | if (usr.getUser_role() == 1) {
84 | news = newsDao.selectAllNews();
85 | model.addAttribute("news", news);
86 | } else {
87 | news = newsDao.selectNewsByCreatorId(usr.getUser_id());
88 | model.addAttribute("news", news);
89 | }
90 | return "news";
91 | }
92 |
93 | @GetMapping("/categories")
94 | public String showCategories(ModelMap model) {
95 | ArrayList categories = newsDao.selectAllNewsCategory();
96 | model.addAttribute("categories", categories);
97 | return "categories";
98 | }
99 |
100 | // for admin.
101 | @GetMapping("/manageCategories")
102 | public String manageCategories(ModelMap model) {
103 | ArrayList tmpCategories = newsDao.selectAllNewsCategory();
104 | ArrayList categories = new ArrayList<>();
105 | for (CategoryResponseDto cat : tmpCategories) {
106 | CategoryResponseDto tmpCat = new CategoryResponseDto();
107 | tmpCat.setNews_category_id(cat.getNews_category_id());
108 | tmpCat.setNews_category_name(cat.getNews_category_name());
109 | tmpCat.setNews_count(newsDao.getNewsCountByCatId(cat.getNews_category_id()));
110 | categories.add(tmpCat);
111 | }
112 | model.addAttribute("categories", categories);
113 | return "adminCategories";
114 | }
115 |
116 | @GetMapping("/deleteCategory/{catId}")
117 | public String delCat(@PathVariable long catId, ModelMap model) {
118 | try {
119 | int i = newsDao.deleteCategory(catId);
120 | if (i > 0) {
121 | model.addAttribute("err", "Successfully Deleted.");
122 | } else {
123 | model.addAttribute("err", "Delete Failed!");
124 | }
125 | } catch (Exception e) {
126 | e.printStackTrace();
127 | }
128 |
129 | return "redirect:/hexa/admin/manageCategories";
130 | }
131 |
132 | @GetMapping("/create_news")
133 | public ModelAndView setupCreateNews(ModelMap model) {
134 | ArrayList news_categories = newsDao.selectAllNewsCategory();
135 | model.addAttribute("news_categories", news_categories);
136 | return new ModelAndView("create-news", "newsBean", new NewsBean());
137 | }
138 |
139 | @PostMapping("/create_news")
140 | public String createNews(@ModelAttribute("newsBean") NewsBean bean, ModelMap model)
141 | throws IllegalStateException, IOException {
142 | NewsRequestDto dto = new NewsRequestDto();
143 | System.out.println(bean.getNews_img());
144 | dto.setNews_name(bean.getNews_name());
145 | dto.setNews_category(bean.getNews_category());
146 | dto.setDescriptions(bean.getDescriptions());
147 | dto.setNews_location(bean.getNews_location());
148 | dto.setCreator_id(bean.getCreator_id());
149 | dto.setNews_img(bean.getNews_img().getOriginalFilename());
150 | fileService.uploadFile(bean.getNews_img());
151 | newsDao.insertNews(dto);
152 | return "redirect:/hexa/admin/create_news";
153 | }
154 |
155 | @PostMapping("/add_category")
156 | public String addCategory(@RequestParam String category, ModelMap model, HttpSession session) {
157 | UserResponseDto userInfo = (UserResponseDto) session.getAttribute("userInfo");
158 | if (!newsDao.checkCategory(category)) {
159 | CategoryRequestDto dto = new CategoryRequestDto();
160 | dto.setNews_category_name(category);
161 | newsDao.insertCategory(dto);
162 | if (userInfo.getUser_role() == 1) {
163 | return "redirect:/hexa/admin/manageCategories";
164 | }
165 | return "redirect:/hexa/admin/categories";
166 | }
167 | if (userInfo.getUser_role() == 1) {
168 | return "redirect:/hexa/admin/manageCategories";
169 | }
170 | return "redirect:/hexa/admin/categories";
171 | }
172 |
173 | @GetMapping("/status/{user_id}")
174 | public String toggleUserStatus(@PathVariable long user_id) {
175 | UserResponseDto userRes = userDao.selectById(user_id);
176 | if (userRes.getUser_status() == 1) {
177 | userDao.updateUserStatusById(0, user_id);
178 | } else {
179 | userDao.updateUserStatusById(1, user_id);
180 | }
181 | return "redirect:/hexa/admin/users";
182 | }
183 |
184 | // old selectPost Mapping
185 | @GetMapping("/allPost")
186 | public String setupShowComments(ModelMap model, HttpSession session) {
187 | UserResponseDto dto = (UserResponseDto) session.getAttribute("userInfo");
188 | if(dto == null) {
189 | return "redirect:/hexa/home";
190 | }
191 | if(dto.getUser_role() == 3) {
192 | return "redirect:/hexa/home";
193 | }
194 | if(dto.getUser_role() == 2) {
195 | return "redirect:/hexa/admin/selectPost";
196 | }
197 | ArrayList bean = new ArrayList();
198 | long comments_count = 0;
199 | long commenters_count = 0;
200 | String news_title = null;
201 | ArrayList lists = interactionDao.selectCommentedNewsId();
202 |
203 | for (long list : lists) {
204 | TempNewsBean newsBean = new TempNewsBean();
205 | comments_count = interactionDao.selectCommentCountByNewsId(list);
206 | commenters_count = interactionDao.selectCommentersByNewsId(list);
207 | news_title = newsDao.selectNewsNameByNewsId(list);
208 | newsBean.setId(list);
209 | newsBean.setTitle(news_title);
210 | newsBean.setCommenters_count(commenters_count);
211 | newsBean.setComments_count(comments_count);
212 | bean.add(newsBean);
213 | }
214 | model.addAttribute("news", bean);
215 | return "setup-comments";
216 | }
217 |
218 | // new mapping & method.
219 | @GetMapping("/selectPost")
220 | public String setupShowComments4Reporter(ModelMap model, HttpSession ses) {
221 |
222 | UserResponseDto dto = (UserResponseDto) ses.getAttribute("userInfo");
223 | if(dto == null) {
224 | return "redirect:/hexa/home";
225 | }
226 | ArrayList bean = new ArrayList();
227 | long comments_count = 0;
228 | long commenters_count = 0;
229 | String news_title = null;
230 | ArrayList lists = interactionDao
231 | .selectCommentedNewsIdByCreatorId(((UserResponseDto) ses.getAttribute("userInfo")).getUser_id());
232 |
233 | for (long list : lists) {
234 | TempNewsBean newsBean = new TempNewsBean();
235 | comments_count = interactionDao.selectCommentCountByNewsId(list);
236 | commenters_count = interactionDao.selectCommentersByNewsId(list);
237 | news_title = newsDao.selectNewsNameByNewsId(list);
238 | newsBean.setId(list);
239 | newsBean.setTitle(news_title);
240 | newsBean.setCommenters_count(commenters_count);
241 | newsBean.setComments_count(comments_count);
242 | bean.add(newsBean);
243 | }
244 |
245 | model.addAttribute("news", bean);
246 | return "setup-comments";
247 | }
248 |
249 | @GetMapping("/comments/{newsId}")
250 | public String showComments(@PathVariable long newsId, ModelMap model) {
251 | ArrayList commenters = new ArrayList();
252 | ArrayList interactionDto = interactionDao.selectInteractionByNewsId(newsId);
253 | for (InteractionResponseDto tmp : interactionDto) {
254 | commenters.add(userDao.selectById(tmp.getUser_id()).getUser_name());
255 | }
256 | model.addAttribute("interactions", interactionDto);
257 | model.addAttribute("commenters", commenters);
258 | return "comments";
259 | }
260 |
261 | @GetMapping("/delete/{cmtId}")
262 | public String delComments(@PathVariable long cmtId, ModelMap model) {
263 | long newsId = interactionDao.selectInteractionById(cmtId).getNews_id();
264 | int i = interactionDao.deleteComment(cmtId);
265 | if (i > 0) {
266 | model.addAttribute("err", "Successfully Deleted.");
267 | } else {
268 | model.addAttribute("err", "Delete Failed!");
269 | }
270 | return "redirect:/hexa/admin/comments/" + newsId;
271 | }
272 |
273 | @GetMapping("/update_news/{news_id}")
274 | public ModelAndView setupUpdateNews(@PathVariable long news_id, ModelMap model, HttpServletRequest request) {
275 | ArrayList updatenews_categories = newsDao.selectAllNewsCategory();
276 | model.addAttribute("updatenews_categories", updatenews_categories);
277 | NewsResponseDto dto = newsDao.selectNewsById(news_id);
278 | CategoryResponseDto selectedCategory = newsDao.selectCategoryByNewsId(news_id);
279 | request.setAttribute("selectedCategory", selectedCategory);
280 | request.setAttribute("news_img", dto.getNews_img());
281 | return new ModelAndView("setup-news", "newsBean", dto);
282 |
283 | }
284 |
285 | @PostMapping("/update_news")
286 | public String updateNews(@ModelAttribute("newsBean") NewsBean bean, ModelMap model, HttpServletRequest request)
287 | throws IllegalStateException, IOException {
288 | String news_img = request.getParameter("news_img");
289 | NewsRequestDto dto = new NewsRequestDto();
290 | dto.setNews_id(bean.getNews_id());
291 | dto.setNews_name(bean.getNews_name());
292 | dto.setNews_category(bean.getNews_category());
293 | dto.setNews_location(bean.getNews_location());
294 | dto.setDescriptions(bean.getDescriptions());
295 | if (bean.getNews_img().getOriginalFilename().isBlank()) {
296 | newsDao.updateNewsWithoutImg(dto);
297 | return "redirect:/hexa/admin/news";
298 | } else {
299 | dto.setNews_img(bean.getNews_img().getOriginalFilename());
300 | fileService.deleteFile(news_img);
301 | fileService.uploadFile(bean.getNews_img());
302 | newsDao.updateNews(dto);
303 | return "redirect:/hexa/admin/news";
304 | }
305 | }
306 |
307 | @GetMapping("/delete_news/{news_id}/{news_img}")
308 | public String deleteNews(@PathVariable("news_id") Long news_id, @PathVariable("news_img") String news_img) {
309 | fileService.deleteFile(news_img);
310 | newsDao.deleteNews(news_id);
311 | return "redirect:/hexa/admin/news";
312 | }
313 |
314 | @GetMapping("/test")
315 | public String test(){
316 | return "note-test";
317 | }
318 |
319 | }
320 |
--------------------------------------------------------------------------------