├── src ├── main │ ├── webapp │ │ └── views │ │ │ ├── layout │ │ │ ├── public-category.jsp │ │ │ ├── public-footer.jsp │ │ │ ├── admin-navbar.jsp │ │ │ ├── admin-accedit-modal.jsp │ │ │ ├── admin-sidebar.jsp │ │ │ └── public-navbar.jsp │ │ │ ├── login.jsp │ │ │ ├── register.jsp │ │ │ ├── setup-comments.jsp │ │ │ ├── home.jsp │ │ │ ├── news.jsp │ │ │ ├── users.jsp │ │ │ ├── search.jsp │ │ │ ├── comments.jsp │ │ │ ├── searchNews.jsp │ │ │ ├── categories.jsp │ │ │ ├── details.jsp │ │ │ ├── set-reporters.jsp │ │ │ ├── adminDashboard.jsp │ │ │ ├── adminCategories.jsp │ │ │ ├── create-news.jsp │ │ │ └── setup-news.jsp │ ├── resources │ │ ├── static │ │ │ ├── img │ │ │ │ ├── 404.gif │ │ │ │ ├── golf.jpg │ │ │ │ ├── apple.jpg │ │ │ │ ├── bunsj.jpg │ │ │ │ ├── darwin.jpg │ │ │ │ ├── doggo.jpg │ │ │ │ ├── girl.webp │ │ │ │ ├── profile.png │ │ │ │ ├── search.gif │ │ │ │ ├── search.jpg │ │ │ │ ├── diabetics.jpg │ │ │ │ ├── jonathan.jpg │ │ │ │ ├── notfound.gif │ │ │ │ ├── shinzoabe.jpg │ │ │ │ ├── kyrgyzstan.jpg │ │ │ │ ├── man_anxiety.jpg │ │ │ │ ├── squid_game.jpg │ │ │ │ ├── weird_thingy.jpg │ │ │ │ ├── covid_at_risk.png │ │ │ │ ├── super_computer.jpg │ │ │ │ ├── quantum_computer.jpg │ │ │ │ ├── indo_girl_with_mic.jpg │ │ │ │ └── that_one_ukraine_dude.jpg │ │ │ ├── js │ │ │ │ ├── search_page.js │ │ │ │ ├── date_period_dom.js │ │ │ │ ├── logout_confirm.js │ │ │ │ ├── confirm.js │ │ │ │ ├── view-detail.js │ │ │ │ ├── admin-table.js │ │ │ │ ├── role_change_confirm.js │ │ │ │ ├── common.js │ │ │ │ ├── homeOg.js │ │ │ │ ├── toggle_user_status.js │ │ │ │ ├── home.js │ │ │ │ ├── delete_confirm.js │ │ │ │ ├── admin-home.js │ │ │ │ ├── getPeriod.js │ │ │ │ ├── admin_chart.js │ │ │ │ ├── pagination.js │ │ │ │ └── comment_script.js │ │ │ └── css │ │ │ │ ├── searchPage.css │ │ │ │ ├── login_register.css │ │ │ │ ├── detail.css │ │ │ │ ├── table.css │ │ │ │ ├── admin_home.css │ │ │ │ ├── user_role.css │ │ │ │ └── home.css │ │ └── application.properties │ └── java │ │ └── com │ │ └── ace │ │ └── hexa │ │ ├── dto │ │ ├── user │ │ │ ├── UserRoleResponseDto.java │ │ │ ├── UserRequestDto.java │ │ │ └── UserResponseDto.java │ │ ├── category │ │ │ ├── CategoryRequestDto.java │ │ │ └── CategoryResponseDto.java │ │ ├── interaction │ │ │ ├── InteractionRequestDto.java │ │ │ └── InteractionResponseDto.java │ │ └── news │ │ │ ├── NewsRequestDto.java │ │ │ └── NewsResponseDto.java │ │ ├── model │ │ ├── Count.java │ │ ├── TempNewsBean.java │ │ ├── InteractionBean.java │ │ ├── UserBean.java │ │ ├── AuthUser.java │ │ ├── News.java │ │ └── NewsBean.java │ │ ├── HexaApplication.java │ │ ├── controller │ │ ├── Main.java │ │ ├── MainController.java │ │ └── AdminController.java │ │ ├── Main.java │ │ ├── dao │ │ ├── JdbcConnection.java │ │ ├── AuthUserDao.java │ │ ├── InteractionDao.java │ │ └── UserDao.java │ │ └── service │ │ ├── FileService.java │ │ ├── TodayNewsService.java │ │ └── HashingService.java └── test │ └── java │ └── com │ └── ace │ └── hexa │ └── HexaApplicationTests.java ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .gitignore ├── .database ├── pom.xml ├── mvnw.cmd └── mvnw /src/main/webapp/views/layout/public-category.jsp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/static/img/404.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/404.gif -------------------------------------------------------------------------------- /src/main/resources/static/img/golf.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/golf.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/apple.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/apple.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/bunsj.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/bunsj.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/darwin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/darwin.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/doggo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/doggo.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/girl.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/girl.webp -------------------------------------------------------------------------------- /src/main/resources/static/img/profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/profile.png -------------------------------------------------------------------------------- /src/main/resources/static/img/search.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/search.gif -------------------------------------------------------------------------------- /src/main/resources/static/img/search.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/search.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/diabetics.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/diabetics.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/jonathan.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/jonathan.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/notfound.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/notfound.gif -------------------------------------------------------------------------------- /src/main/resources/static/img/shinzoabe.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/shinzoabe.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/kyrgyzstan.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/kyrgyzstan.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/man_anxiety.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/man_anxiety.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/squid_game.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/squid_game.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/weird_thingy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/weird_thingy.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/covid_at_risk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/covid_at_risk.png -------------------------------------------------------------------------------- /src/main/resources/static/img/super_computer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/super_computer.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/quantum_computer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/quantum_computer.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/indo_girl_with_mic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/indo_girl_with_mic.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/that_one_ukraine_dude.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahkar33/hexa_project/HEAD/src/main/resources/static/img/that_one_ukraine_dude.jpg -------------------------------------------------------------------------------- /src/main/resources/static/js/search_page.js: -------------------------------------------------------------------------------- 1 | 2 | document.querySelectorAll("#news-content").forEach(news => { 3 | let origin = news.textContent; 4 | 5 | news.textContent = origin.substring(0,150) + "..."; 6 | }) -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/dto/user/UserRoleResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class UserRoleResponseDto { 7 | int id; 8 | String name; 9 | } 10 | -------------------------------------------------------------------------------- /src/main/resources/static/js/date_period_dom.js: -------------------------------------------------------------------------------- 1 | const dates = document.querySelectorAll(".created-date"); 2 | 3 | dates.forEach(d => { 4 | let date = d.textContent; 5 | d.textContent= getPeriod(date,'yy-mm-dd'); 6 | }) -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.mvc.view.prefix=/views/ 2 | spring.mvc.view.suffix=.jsp 3 | 4 | spring.servlet.multipart.enabled=true 5 | spring.servlet.multipart.max-file-size=1000000MB 6 | spring.servlet.multipart.max-request-size=1000000MB 7 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/dto/category/CategoryRequestDto.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.dto.category; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class CategoryRequestDto { 7 | private long news_category_id; 8 | private String news_category_name; 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/model/Count.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class Count { 7 | private long news_count; 8 | private long reporter_count; 9 | private long user_count; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/model/TempNewsBean.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class TempNewsBean { 7 | private long id; 8 | private String title; 9 | private long commenters_count; 10 | private long comments_count; 11 | } -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/model/InteractionBean.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class InteractionBean { 7 | private long comment_id; 8 | private long news_id; 9 | private long user_id; 10 | private String comments; 11 | } 12 | -------------------------------------------------------------------------------- /src/main/resources/static/js/logout_confirm.js: -------------------------------------------------------------------------------- 1 | const logoutBtn = document.querySelector("#logout"); 2 | 3 | if(logoutBtn != null ){ 4 | logoutBtn.onclick = () => { 5 | localStorage.removeItem('curPage'); 6 | 7 | doConfirm('logout','../../hexa/logout'); 8 | } 9 | } -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/dto/category/CategoryResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.dto.category; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class CategoryResponseDto { 7 | private long news_category_id; 8 | private String news_category_name; 9 | private long news_count; 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/com/ace/hexa/HexaApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class HexaApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/dto/interaction/InteractionRequestDto.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.dto.interaction; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class InteractionRequestDto { 7 | private long comment_id; 8 | private long news_id; 9 | private long user_id; 10 | private String comments; 11 | } 12 | -------------------------------------------------------------------------------- /src/main/resources/static/js/confirm.js: -------------------------------------------------------------------------------- 1 | 2 | const doConfirm = ( msg , goTo ) => { 3 | console.log("do") 4 | swal({ 5 | text : `Are you sure to ${msg}?`, 6 | icon : 'warning', 7 | buttons : ['No','Yes'] 8 | }).then( yes => { 9 | 10 | if(yes) window.location.href = goTo; 11 | 12 | }); 13 | } -------------------------------------------------------------------------------- /src/main/resources/static/js/view-detail.js: -------------------------------------------------------------------------------- 1 | 2 | const newsBoxes = document.querySelectorAll("#news"); 3 | 4 | newsBoxes.forEach(box => { 5 | box.addEventListener("click",() => { 6 | //will get id from box element and go to detail page with get method 7 | // window.location.href = "./detail.html"; 8 | }) 9 | }) -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/model/UserBean.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class UserBean { 7 | private long user_id; 8 | private String user_name; 9 | private int user_role; 10 | private String user_email; 11 | private String user_password; 12 | private int user_status; 13 | } 14 | -------------------------------------------------------------------------------- /src/main/resources/static/js/admin-table.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(document).ready(() => { 4 | $("#table").DataTable(); 5 | $("#table_info").css("display","none"); 6 | $("#table_length").css("transform","translateX(100%)"); 7 | $("#table_filter").css("transform","translateX(-60%)"); 8 | $("#table_paginate").css("transform","translateX(-60%)"); 9 | }) -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/dto/user/UserRequestDto.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class UserRequestDto { 7 | private long user_id; 8 | private String user_name; 9 | private int user_role; 10 | private String user_email; 11 | private String user_password; 12 | private int user_status; 13 | } 14 | -------------------------------------------------------------------------------- /src/main/resources/static/js/role_change_confirm.js: -------------------------------------------------------------------------------- 1 | const roleChangeBtns = document.querySelectorAll('#role-ch-btn'); 2 | 3 | roleChangeBtns.forEach( btn => { 4 | btn.addEventListener("click" , e => { 5 | let data = btn.getAttribute("data-target").split(","); 6 | 7 | doConfirm( 'change role for this user?' , `../admin/role/${data[0]}/${data[1]}`); 8 | }) 9 | }) -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/HexaApplication.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication() 7 | public class HexaApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HexaApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/dto/user/UserResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class UserResponseDto { 7 | 8 | private long user_id; 9 | private String user_name; 10 | private int user_role; 11 | private String user_role_name; 12 | private String user_email; 13 | private String user_password; 14 | private int user_status; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/dto/interaction/InteractionResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.dto.interaction; 2 | 3 | import java.time.LocalDate; 4 | 5 | import lombok.Data; 6 | 7 | @Data 8 | public class InteractionResponseDto { 9 | private long comment_id; 10 | private long news_id; 11 | private long user_id; 12 | private String comments; 13 | private String user_name; 14 | private LocalDate commented_date; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/resources/static/js/common.js: -------------------------------------------------------------------------------- 1 | 2 | // const btns = document.querySelectorAll("#btn-ban"); 3 | 4 | // btns.forEach(btn => { 5 | // btn.addEventListener("click" , () => { 6 | // confirm(`Are you sure to ${btn.textContent}?`); 7 | // // with backend 8 | // if(confirm(`Are you sure to ${btn.textContent}?`)){ 9 | // window.location.href("/url"); 10 | // } 11 | // }) 12 | // }) -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/controller/Main.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.controller; 2 | 3 | import com.ace.hexa.service.HashingService; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | String rawPassword = "asdfqwer"; 8 | HashingService hash = new HashingService(); 9 | String hashPassword = hash.getHash(rawPassword, rawPassword.substring(0, 4)); 10 | System.out.println(hashPassword); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/model/AuthUser.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.model; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | 6 | @Data 7 | @NoArgsConstructor 8 | public class AuthUser { 9 | private long user_id; 10 | private String user_name; 11 | private String user_email; 12 | private String user_password; 13 | private int role_id; 14 | private String user_role; 15 | private int _token; 16 | private int status; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/Main.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa; 2 | 3 | import com.ace.hexa.dao.NewsDao; 4 | import com.ace.hexa.dto.category.CategoryResponseDto; 5 | 6 | 7 | public class Main { 8 | public static void main(String[] args) { 9 | 10 | NewsDao dao = new NewsDao(); 11 | CategoryResponseDto dto = dao.selectCategoryByNewsId(72); 12 | System.out.println("name " + dto.getNews_category_name()); 13 | System.out.println("id " + dto.getNews_category_id()); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/dto/news/NewsRequestDto.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.dto.news; 2 | 3 | import java.time.LocalDate; 4 | 5 | import lombok.Data; 6 | 7 | @Data 8 | public class NewsRequestDto { 9 | private long news_id; 10 | private String news_name; 11 | private String descriptions; 12 | private String news_img; 13 | private String news_location; 14 | private long creator_id; 15 | private long news_category; 16 | private LocalDate created_date; 17 | private LocalDate updated_date; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/dto/news/NewsResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.dto.news; 2 | 3 | import java.time.LocalDate; 4 | 5 | import lombok.Data; 6 | 7 | @Data 8 | public class NewsResponseDto { 9 | private long news_id; 10 | private String news_name; 11 | private String descriptions; 12 | private String news_img; 13 | private String news_location; 14 | private String creator_name; 15 | private long news_category; 16 | private String news_category_name; 17 | private LocalDate created_date; 18 | private LocalDate updated_date; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/model/News.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.model; 2 | 3 | import java.time.LocalDate; 4 | 5 | import org.springframework.web.multipart.MultipartFile; 6 | 7 | import lombok.Data; 8 | 9 | @Data 10 | public class News { 11 | private long news_id; 12 | private String news_name; 13 | private String descriptions; 14 | private MultipartFile news_img; 15 | private String news_location; 16 | private long creator_id; 17 | private long news_category; 18 | private LocalDate created_date; 19 | private LocalDate updated_date; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/model/NewsBean.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.model; 2 | 3 | import java.time.LocalDate; 4 | 5 | import org.springframework.web.multipart.MultipartFile; 6 | 7 | import lombok.Data; 8 | 9 | @Data 10 | public class NewsBean { 11 | private long news_id; 12 | private String news_name; 13 | private String descriptions; 14 | private MultipartFile news_img; 15 | private String news_location; 16 | private long creator_id; 17 | private long news_category; 18 | private LocalDate created_date; 19 | private LocalDate updated_date; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/resources/static/js/homeOg.js: -------------------------------------------------------------------------------- 1 | //custom js 2 | $(document).ready(() => { 3 | $("#btn-menu").click(handleShowMenu); 4 | $("#navbar-nav").click(handleCloseMenu); 5 | $("#menu-layer").click(handleCloseMenu); 6 | }); 7 | 8 | //handling for menu button 9 | const handleShowMenu = function(e){ 10 | $("#navbar-nav")[0].classList.add("show"); 11 | $("#menu-layer")[0].classList.add("active"); 12 | } 13 | 14 | const handleCloseMenu = function(e){ 15 | $("#navbar-nav")[0].classList.remove("show"); 16 | $("#menu-layer")[0].classList.remove("active"); 17 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | 35 | 36 | 37 | ./src/main/resources/static/js/node_modules/ 38 | -------------------------------------------------------------------------------- /src/main/resources/static/css/searchPage.css: -------------------------------------------------------------------------------- 1 | 2 | #search-news #news-wrapper #news{ 3 | width:100%; 4 | height:auto; 5 | overflow: hidden; 6 | } 7 | 8 | #news-wrapper #image{ 9 | height:200px; 10 | position: relative; 11 | overflow: hidden; 12 | } 13 | 14 | #news image img{ 15 | width:100%; 16 | height:100%; 17 | } 18 | 19 | #news{ 20 | box-shadow: 0 0 1.5px rgba(0,0,0,0.75); 21 | } 22 | 23 | 24 | #news-wrapper #content{ 25 | padding: 20px; 26 | } 27 | 28 | #content p{ 29 | color:rgba(0,0,0,0.75); 30 | } 31 | 32 | .bulb{ 33 | border-radius: 10px !important; 34 | padding:5px 10px !important ; 35 | } -------------------------------------------------------------------------------- /src/main/resources/static/js/toggle_user_status.js: -------------------------------------------------------------------------------- 1 | const banBtns = document.querySelectorAll("#ban"); 2 | const unbanBtns = document.querySelectorAll("#unban"); 3 | 4 | if(banBtns != null){ 5 | banBtns.forEach( btn => { 6 | btn.addEventListener('click' , e => { 7 | 8 | doConfirm( 'ban this user?' , `../../hexa/admin/status/${btn.getAttribute('data-target')}` ); 9 | }) 10 | }); 11 | } 12 | 13 | if( unbanBtns != null ){ 14 | unbanBtns.forEach( btn => { 15 | btn.addEventListener('click' , e => { 16 | doConfirm( 'unban this user?' , `../../hexa/admin/status/${btn.getAttribute('data-target')}` ); 17 | }) 18 | }) 19 | } -------------------------------------------------------------------------------- /src/main/resources/static/js/home.js: -------------------------------------------------------------------------------- 1 | //custom js 2 | $(document).ready(() => { 3 | $("#btn-menu").click(handleShowMenu); 4 | $("#navbar-nav").click(handleCloseMenu); 5 | $("#menu-layer").click(handleCloseMenu); 6 | }); 7 | 8 | //handling for menu button 9 | const handleShowMenu = function(e){ 10 | $("#navbar-nav")[0].classList.add("show"); 11 | $("#menu-layer")[0].classList.add("active"); 12 | $("#btn-menu").css({"transform" : "translateX(-100%)"}); 13 | } 14 | 15 | const handleCloseMenu = function(e){ 16 | $("#navbar-nav")[0].classList.remove("show"); 17 | $("#menu-layer")[0].classList.remove("active"); 18 | $("#btn-menu").css({"transform" : "translateX(600%)"}); 19 | } -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/dao/JdbcConnection.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.dao; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.SQLException; 6 | 7 | public class JdbcConnection { 8 | static Connection con = null; 9 | 10 | public static Connection getConnection() throws SQLException { 11 | String url = "jdbc:mysql://localhost:3306/news_project"; 12 | String uname = "sqluser"; 13 | String pass = "bazinga||jk"; 14 | try { 15 | Class.forName("com.mysql.cj.jdbc.Driver"); 16 | con = DriverManager.getConnection(url, uname, pass); 17 | } catch (ClassNotFoundException e) { 18 | System.out.println("Driver class not found"); 19 | } catch (SQLException e) { 20 | System.out.println("Database not found"); 21 | } 22 | return con; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/service/FileService.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.service; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.web.multipart.MultipartFile; 8 | 9 | @Service 10 | public class FileService { 11 | 12 | public void uploadFile(MultipartFile file) throws IllegalStateException, IOException { 13 | file.transferTo( 14 | new File("C:\\Users\\Ahkar Toe Maw\\Desktop\\hexa_project\\src\\main\\resources\\static\\img\\" 15 | + file.getOriginalFilename())); 16 | } 17 | 18 | public boolean deleteFile(String news_img) { 19 | File fileToDelete = new File( 20 | "C:\\Users\\Ahkar Toe Maw\\Desktop\\hexa_project\\src\\main\\resources\\static\\img\\" 21 | + news_img); 22 | return fileToDelete.delete(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/webapp/views/layout/public-footer.jsp: -------------------------------------------------------------------------------- 1 | 15 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/service/TodayNewsService.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.service; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.ArrayList; 5 | import java.util.Date; 6 | 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.ace.hexa.dto.news.NewsResponseDto; 10 | 11 | @Service 12 | public class TodayNewsService { 13 | 14 | public ArrayList getTodayNews(ArrayList list) { 15 | ArrayList todayNews = new ArrayList(); 16 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 17 | Date date = new Date(System.currentTimeMillis()); 18 | String currentDate = formatter.format(date); 19 | String todayDate = currentDate.substring(0, 10); 20 | for (NewsResponseDto news : list) { 21 | if (news.getCreated_date().toString().equals(todayDate)) { 22 | todayNews.add(news); 23 | } 24 | } 25 | return todayNews; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/service/HashingService.java: -------------------------------------------------------------------------------- 1 | package com.ace.hexa.service; 2 | 3 | import java.security.MessageDigest; 4 | import java.security.NoSuchAlgorithmException; 5 | 6 | public class HashingService { 7 | public String getHash(String passwordToHash, 8 | String salt) { 9 | String generatedPassword = null; 10 | try { 11 | MessageDigest md = MessageDigest.getInstance("SHA-384"); 12 | md.update(salt.getBytes()); 13 | byte[] bytes = md.digest(passwordToHash.getBytes()); 14 | StringBuilder sb = new StringBuilder(); 15 | for (int i = 0; i < bytes.length; i++) { 16 | sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16) 17 | .substring(1)); 18 | } 19 | generatedPassword = sb.toString(); 20 | } catch (NoSuchAlgorithmException e) { 21 | e.printStackTrace(); 22 | } 23 | return generatedPassword; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/resources/static/js/delete_confirm.js: -------------------------------------------------------------------------------- 1 | const newsDelBtns = document.querySelectorAll("#news-del-btn"); 2 | const categoryDelBtns = document.querySelectorAll("#category-del-btn"); 3 | const commentDelBtns = document.querySelectorAll("#comment-del-btn"); 4 | 5 | if( newsDelBtns != null){ 6 | newsDelBtns.forEach( btn => { 7 | btn.addEventListener("click" , e => { 8 | let data = btn.getAttribute('data-target').split(",") 9 | doConfirm('delete this news ? ' , `../admin/delete_news/${data[0]}/${data[1]}`); 10 | }) 11 | }); 12 | } 13 | 14 | if( categoryDelBtns != null ){ 15 | categoryDelBtns.forEach( btn => { 16 | btn.addEventListener("click" , e => { 17 | doConfirm('delete this category ? ' , `../admin/deleteCategory/${btn.getAttribute('data-target')}`); 18 | }); 19 | }) 20 | } 21 | 22 | if( commentDelBtns != null ){ 23 | commentDelBtns.forEach( btn => { 24 | btn.addEventListener( "click" , e => { 25 | doConfirm('delete this comment ? ' , `../../admin/delete/${btn.getAttribute('data-target')}`); 26 | }) 27 | } ) 28 | } -------------------------------------------------------------------------------- /src/main/resources/static/js/admin-home.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | const counts = document.querySelectorAll("#count"); 4 | const date = new Date(); 5 | 6 | 7 | $(document).ready(() => { 8 | 9 | $("#year").html(date.getFullYear()); 10 | $("#day-name").html(getDayName(date.getDay())); 11 | $("#day").html(date.getDate()); 12 | 13 | 14 | if(!localStorage.getItem("countDone") || localStorage.getItem("countDone") == null){ 15 | counts.forEach(count => { 16 | let realVal = Number(count.textContent);//real value 17 | let start = 0; 18 | count.textContent = start; 19 | 20 | const counter = setInterval(() => { 21 | let currentVal = Number(count.textContent); 22 | currentVal += 1 ; 23 | if(currentVal == realVal) clearInterval(counter) 24 | count.textContent = currentVal; 25 | },10); 26 | 27 | }) 28 | } 29 | localStorage.setItem("countDone",true); 30 | }) 31 | 32 | function getDayName(day){ 33 | let result = ""; 34 | switch(day){ 35 | case 0 : result = "Sunday";break; 36 | case 1 : result = "Monday";break; 37 | case 2 : result = "Tuesday";break; 38 | case 3 : result = "Wednesday";break; 39 | case 4 : result = "Thursday";break; 40 | case 5 : result = "Friday";break; 41 | case 6 : result = "Saturday";break; 42 | default : result = "error"; 43 | } 44 | return result; 45 | } -------------------------------------------------------------------------------- /src/main/webapp/views/layout/admin-navbar.jsp: -------------------------------------------------------------------------------- 1 | 18 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/main/webapp/views/layout/admin-accedit-modal.jsp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.database: -------------------------------------------------------------------------------- 1 | #Hexa_Project(Database structures) 2 | 3 | To run this project 4 | 5 | (1)Need to create project' database 6 | 7 | CREATE DATABASE IF NOT EXISTS news_project; 8 | 9 | ----------------------------------------------- 10 | 11 | (2)Need to create required tables 12 | 13 | (i)user_roles 14 | CREATE TABLE IF NOT EXISTS user_role( 15 | user_role_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, 16 | user_role_name VARCHAR(100) NOT NULL 17 | ) 18 | 19 | (ii)user_accounts 20 | CREATE TABLE IF NOT EXISTS user_account( 21 | user_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, 22 | user_name VARCHAR(100), 23 | user_role INT, 24 | FOREIGN KEY(user_role) REFERENCES user_role(user_role_id) ON DELETE SET null, 25 | user_email VARCHAR(100) UNIQUE, 26 | user_password VARCHAR(100) 27 | ) 28 | 29 | (iii)news_category 30 | CREATE TABLE IF NOT EXISTS news_category( 31 | news_category_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, 32 | news_category_name VARCHAR(200) NOT NULL 33 | ) 34 | 35 | (iv)news 36 | CREATE TABLE IF NOT EXISTS news( 37 | news_id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, 38 | news_name VARCHAR(200), 39 | descriptions VARCHAR(8000), 40 | news_img VARCHAR(200), 41 | news_location VARCHAR(200), 42 | news_status VARCHAR(200), 43 | news_category INT NOT NULL, 44 | FOREIGN KEY (news_category) REFERENCES news_category (news_category_id), 45 | created_date DATETIME DEFAULT NOW(), 46 | updated_date DATETIME DEFAULT NOW() ON UPDATE NOW() 47 | ) 48 | 49 | (v)intersection 50 | CREATE TABLE IF NOT EXISTS intersection( 51 | news_id BIGINT NOT NULL, 52 | user_id INT NOT NULL, 53 | comments VARCHAR(800), 54 | likes INT DEFAULT 0, 55 | FOREIGN KEY (news_id) REFERENCES news(news_id) ON DELETE CASCADE ON UPDATE CASCADE, 56 | FOREIGN KEY (user_id) REFERENCES user_account(user_id) ON DELETE CASCADE ON UPDATE CASCADE 57 | ) 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/main/resources/static/css/login_register.css: -------------------------------------------------------------------------------- 1 | *{ 2 | padding:0; 3 | margin:0; 4 | box-sizing:border-box; 5 | } 6 | 7 | body{ 8 | width:100vw; 9 | height:100vh; 10 | background-color: #eee; 11 | } 12 | 13 | 14 | .text{ 15 | color:rgba(0,0,0,0.65) !important; 16 | } 17 | 18 | .thm{ 19 | color:rgba(245, 197, 125,1) !important; 20 | } 21 | 22 | .text-light{ 23 | color:rgba(255,255,255,0.75); 24 | } 25 | 26 | #bg{ 27 | background-color: rgba(0,0,0,0.75); 28 | } 29 | 30 | #container{ 31 | transition: 0.8s all; 32 | } 33 | 34 | .form-group{ 35 | position: relative; 36 | } 37 | 38 | .form-group i{ 39 | position: absolute; 40 | top:50%; 41 | right:20px; 42 | } 43 | 44 | .input{ 45 | width:100%; 46 | border-top:none; 47 | border-left:none; 48 | border-right:none; 49 | border-bottom: 0.5px solid rgba(0,0,0,0.35); 50 | border-radius: 5px; 51 | padding:0 10px; 52 | transition: 0.5s all; 53 | color:rgba(57, 14, 199,0.75); 54 | font-weight: bold; 55 | } 56 | 57 | ::-webkit-input-placeholder{ 58 | color:rgba(0,0,0,0.75); 59 | font-weight: normal; 60 | } 61 | 62 | .input:focus{ 63 | outline:none; 64 | border-bottom:1px dashed rgba(57, 14, 199.1); 65 | } 66 | 67 | footer{ 68 | position:absolute; 69 | bottom:0; 70 | left:0; 71 | } 72 | 73 | 74 | @media (max-width:499px){ 75 | #container{ 76 | width:80% !important; 77 | } 78 | 79 | #wrapper{ 80 | padding: 0 20px; 81 | flex-direction: column !important; 82 | justify-content: center; 83 | align-items: center; 84 | } 85 | } 86 | 87 | @media (min-width:500px) and (max-width:899px){ 88 | #container{ 89 | width:65% !important; 90 | } 91 | 92 | #wrapper{ 93 | padding: 0 20px; 94 | flex-direction: column !important; 95 | justify-content: center; 96 | align-items: center; 97 | } 98 | } 99 | 100 | @media (min-width:900px) and (max-width:1119px){ 101 | #container{ 102 | width:40% !important; 103 | } 104 | } 105 | 106 | @media (min-width:1200px){ 107 | #container{ 108 | width:25% !important; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 2.7.0 10 | 11 | 12 | com.hex 13 | testingProject 14 | 0.0.1-SNAPSHOT 15 | testingProject 16 | Demo project for Spring Boot 17 | 18 | 11 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-web 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-devtools 28 | runtime 29 | true 30 | 31 | 32 | mysql 33 | mysql-connector-java 34 | runtime 35 | 36 | 37 | org.projectlombok 38 | lombok 39 | true 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-test 44 | test 45 | 46 | 47 | org.apache.tomcat.embed 48 | tomcat-embed-jasper 49 | provided 50 | 51 | 52 | javax.servlet 53 | jstl 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | org.projectlombok 66 | lombok 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/main/java/com/ace/hexa/dao/AuthUserDao.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 | 8 | import org.springframework.stereotype.Service; 9 | 10 | import com.ace.hexa.model.AuthUser; 11 | 12 | @Service 13 | public class AuthUserDao { 14 | 15 | private static Connection con; 16 | 17 | static{ 18 | try{ 19 | con = JdbcConnection.getConnection(); 20 | }catch(Exception e){ 21 | e.printStackTrace(); 22 | } 23 | } 24 | 25 | public int insertAuthUser(AuthUser authUser){ 26 | int status = 0; 27 | String sql = "INSERT INTO auth_users (user_email,_token,role_id) VALUES(?,?,?)"; 28 | try{ 29 | PreparedStatement pre = con.prepareStatement(sql); 30 | pre.setString( 1 , authUser.getUser_email()); 31 | pre.setInt( 2 , authUser.get_token()); 32 | pre.setInt( 3 , authUser.getRole_id() ); 33 | 34 | status = pre.executeUpdate(); 35 | }catch(SQLException e){ 36 | e.printStackTrace(); 37 | } 38 | 39 | return status; 40 | } 41 | 42 | public AuthUser selectAuthUser(String email){ 43 | AuthUser authUser = new AuthUser(); 44 | String sql = "SELECT * FROM auth_users u LEFT JOIN user_role r ON u.role_id = r.user_role_id WHERE user_email = ? ORDER BY id DESC LIMIT 1"; 45 | try{ 46 | PreparedStatement pre = con.prepareStatement(sql); 47 | pre.setString( 1 , email ); 48 | 49 | ResultSet set = pre.executeQuery(); 50 | 51 | while(set.next()){ 52 | authUser.setUser_email(set.getString("user_email")); 53 | authUser.set_token(set.getInt("_token")); 54 | authUser.setRole_id(set.getInt("role_id")); 55 | authUser.setUser_role(set.getString("user_role_name")); 56 | } 57 | 58 | }catch(SQLException e){ 59 | e.printStackTrace(); 60 | } 61 | return authUser; 62 | } 63 | 64 | public int deleteAuthUser(String email){ 65 | int status = 0; 66 | String sql = "DELETE FROM auth_users WHERE user_email = ? "; 67 | 68 | try{ 69 | PreparedStatement pre = con.prepareStatement(sql); 70 | pre.setString( 1 , email ); 71 | 72 | status = pre.executeUpdate(); 73 | }catch(SQLException e){ 74 | e.printStackTrace(); 75 | } 76 | return status; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/resources/static/js/getPeriod.js: -------------------------------------------------------------------------------- 1 | /* 2 | * data is real date , format is format of inputted date e.g (yy-mm-dd) or (dd-mm-dd) or (mm-yy-dd) 3 | * now is only available for (2022-07-01) or (01-07-2022) or (07-20222-01) date , format 4 | */ 5 | const getPeriod = ( date = "" , format ) => { 6 | const obj = new Date(); 7 | const inputArray = date.split("-"); 8 | 9 | const curYear = obj.getFullYear(); 10 | const curMonth = obj.getMonth() + 1; 11 | const curDay = obj.getDate(); 12 | 13 | 14 | const getKeyFromFormat = ( format ) => { 15 | let Key; 16 | 17 | switch( format ){ 18 | case "yy-mm-dd" : Key = { 19 | year : 0, 20 | month : 1, 21 | day : 2, 22 | }; 23 | break; 24 | 25 | case "mm-yy-dd" : Key = { 26 | year : 1, 27 | month : 0, 28 | day : 2 29 | }; 30 | break; 31 | 32 | case "dd-mm-yy" : Key = { 33 | year : 2, 34 | month : 1, 35 | day : 0, 36 | }; 37 | break; 38 | 39 | default : Key = "INVALID"; 40 | 41 | } 42 | 43 | return Key; 44 | } 45 | 46 | const getDifference = ( current , past ) => { 47 | return Math.abs( current - past ); 48 | } 49 | 50 | const getDaysFromYear = ( year = 0 ) => { 51 | return parseInt(year) * 365 ; 52 | } 53 | 54 | const getDaysFromMonth = ( month = 0 ) => { 55 | return parseInt( month ) * 30; 56 | } 57 | 58 | const getResultFromDayDiff = ( days ) => { 59 | let result = ""; 60 | 61 | switch( true ){ 62 | case days == 0 : result = "Today" ; break; 63 | case days == 1 : result = `1 day ago`;break; 64 | case days == 30 || days < 60 : result = '1 month ago';break; 65 | case days > 60 && days < 365 : result = `${Math.floor(days/30)} months ago`;break; 66 | case days == 365 : result = `1 year ago`;break; 67 | case days > 365 : result = `${Math.floor(days/365)} years ago`;break; 68 | default : result = `${days} days ago`; 69 | } 70 | 71 | return result; 72 | } 73 | 74 | const key = getKeyFromFormat(format); 75 | 76 | let year = key == "INVALID" ? curYear : inputArray[key.year]; 77 | let month = key == "INVALID" ? curMonth : inputArray[key.month]; 78 | let day = key == "INVALID" ? curDay : inputArray[key.day]; 79 | 80 | let yearDiff = getDifference( parseInt(curYear) , parseInt(year) ); 81 | let monthDiff = getDifference( parseInt(curMonth) , parseInt(month) ) ; 82 | let dayDiff = getDifference( parseInt(curDay) , parseInt(day) ); 83 | 84 | let totalDayDiff = dayDiff + getDaysFromYear(yearDiff) + getDaysFromMonth(monthDiff); 85 | 86 | return getResultFromDayDiff(totalDayDiff); 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/main/webapp/views/login.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 | 12 | 13 | Login 14 | 15 | 18 | 19 | 21 | 22 | 23 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 36 |
37 |
38 | HEXA 39 |
40 |
${error}
41 | 43 |
44 | 46 | 48 | 49 |
50 |
51 | 52 | 54 | 55 |
56 |
57 | 58 |
59 | Home Page 60 | Create? 61 |
62 |
63 |
64 |
65 | 66 |
67 |
70 |
Created By Team Hexa(Ace 71 | Inspiration)
72 |
73 | 74 | 75 | 76 |
77 |
78 |
79 | 80 | 81 | -------------------------------------------------------------------------------- /src/main/resources/static/css/detail.css: -------------------------------------------------------------------------------- 1 | @charset "ISO-8859-1"; 2 | 3 | #news-wrapper { 4 | width: 90%; 5 | height:auto !important; 6 | } 7 | 8 | #news-image { 9 | width:100%; 10 | height: 400px; 11 | position: relative; 12 | } 13 | 14 | #news-image img { 15 | width: 100%; 16 | height: 100%; 17 | -webkit-box-shadow: 0 0 1px rgba(0, 0, 0, 0.75); 18 | box-shadow: 0 0 1px rgba(0, 0, 0, 0.75); 19 | } 20 | 21 | #news-location *{ 22 | color:rgba(245, 197, 125,1) !important; 23 | } 24 | 25 | 26 | #news-image #layer { 27 | position: absolute; 28 | width: 100%; 29 | height: 100%; 30 | top: 0; 31 | left: 0; 32 | background-color: rgba(0, 0, 0, 0.1); 33 | } 34 | 35 | #news-image * { 36 | color: rgba(255, 255, 255, 0.75); 37 | } 38 | 39 | #news-image #news-writer { 40 | -webkit-transform: translateX(10px); 41 | transform: translateX(10px); 42 | } 43 | 44 | #news-content { 45 | width: 100%; 46 | color: rgba(0, 0, 0, 0.75); 47 | font-size: 23px; 48 | font-weight: bold; 49 | } 50 | 51 | #others { 52 | height: 100% !important; 53 | } 54 | 55 | #other-news { 56 | width: 100%; 57 | height: 200px; 58 | /* -webkit-transform: translate(30%, -25%); 59 | transform: translate(30%, -25%); */ 60 | position: relative; 61 | border-radius: 5px !important; 62 | 63 | } 64 | 65 | #other-news img { 66 | width: 100%; 67 | height: 100%; 68 | } 69 | 70 | #other-news #layer { 71 | position: absolute; 72 | width: 100%; 73 | height: 100%; 74 | top: 0; 75 | left: 0; 76 | background: rgba(0, 0, 0, 0.35); 77 | text-align: start; 78 | } 79 | 80 | #other-news * { 81 | color: rgba(255, 255, 255, 0.75); 82 | font-weight: bold; 83 | } 84 | 85 | #other-news #location { 86 | color: #f5c57d; 87 | } 88 | 89 | 90 | #comment { 91 | -webkit-box-shadow: 0 0 1px rgba(0, 0, 0, 0.75); 92 | box-shadow: 0 0 1px rgba(0, 0, 0, 0.75); 93 | padding: 10px; 94 | font-size: 15px !important; 95 | color: rgba(0, 0, 0, 0.75); 96 | /* font-weight: bold; */ 97 | position: relative; 98 | } 99 | 100 | #comment.hide{ 101 | display: none; 102 | } 103 | 104 | 105 | /* edited here for comment control */ 106 | #comment #cmt-control{ 107 | position: absolute; 108 | top:3px; 109 | right:10px; 110 | color: rgba(0, 0, 0, 0.75); 111 | font-size: 18px; 112 | } 113 | 114 | /* ended here*/ 115 | 116 | #comment img { 117 | width: 40px; 118 | height: 40px; 119 | border-radius: 100%; 120 | -webkit-box-shadow: 0 0 0.3px #f5c57d; 121 | box-shadow: 0 0 0.3px #f5c57d; 122 | } 123 | 124 | #comment #info { 125 | font-weight: bold; 126 | font-size: 13px; 127 | color: #f5c57d; 128 | } 129 | /*# sourceMappingURL=detail.css.map */ 130 | 131 | .text{ 132 | color: #f5c57d; 133 | } 134 | 135 | #news-content *{ 136 | color:rgba(0, 0, 0, 0.75) !important; 137 | } 138 | 139 | #btn-view:hover{ 140 | cursor: pointer; 141 | } 142 | 143 | #comment .dropdown a:hover{ 144 | cursor:pointer; 145 | } 146 | 147 | .thm{ 148 | color: rgba(245, 197, 125,1) !important; 149 | } 150 | 151 | .txt-snow{ 152 | color: rgba(255, 255, 255, 1) !important; 153 | } -------------------------------------------------------------------------------- /src/main/resources/static/js/admin_chart.js: -------------------------------------------------------------------------------- 1 | const months = ['January','February','March','April','May','June','July','August','September','October','November','December']; 2 | var datas = []; 3 | var year = new Date().getFullYear();//present year will be default for fetching , meant to be dynamic 4 | var newsChart; 5 | 6 | window.addEventListener('afterprint',() => { 7 | newsChart.resize(); 8 | }) 9 | 10 | $(document).ready( () => { 11 | 12 | /* 13 | year is to fetch with that value 14 | eg. to show datas for 2020 ,year will be 2020 15 | */ 16 | renderChart(year); 17 | 18 | $("#year-btns").html(getYearBtns(year)); 19 | 20 | 21 | $(".year-btn").each( (index,btn) => { 22 | btn.addEventListener("click",() => { 23 | let target = btn.textContent; 24 | setActiveYearBtn(target); 25 | newsChart.destroy(); 26 | renderChart(target); 27 | }) 28 | }) 29 | 30 | }); 31 | 32 | //target stands for year target 33 | function renderChart( target ){ 34 | fetch(`http://localhost:8080/hexa/api/news/years?y=${target}`) 35 | .then( res => res.json()) 36 | .then( news => { 37 | datas = getNewsCounts( news , target ); 38 | 39 | newsChart = new Chart( 40 | document.getElementById("newsPerMonthChart"), 41 | { 42 | type : 'bar', 43 | data : { 44 | labels : months, 45 | datasets : [ 46 | { label : "News Count Per Month's Datas", 47 | backgroundColor: 'rgba(245, 197, 125,1)', 48 | borderColor: 'rgba(0,0,0,0.55)', 49 | data : datas, 50 | } 51 | ] 52 | } 53 | } 54 | ); 55 | }); 56 | } 57 | 58 | function getNewsCounts( datas = [] , year ){ 59 | let results = []; 60 | let news = []; 61 | //m stands for month 62 | for( let m = 1 ; m <= 12 ; m++ ){ 63 | let search = ''; 64 | search += `${year}-` 65 | search += m < 10 ? `0${m}` : m ; 66 | news = datas.filter( d => { 67 | return d.created_date.includes(search); 68 | }); 69 | results.push(news.length); 70 | } 71 | 72 | results.push(Math.max(...results) + 20);//to take y-axis more amount than maximum in array 73 | 74 | return results; 75 | } 76 | 77 | /* 78 | to get btns for control chart, 79 | e.g if now is 2022, we will able to see for last two years 80 | */ 81 | function getYearBtns( now ){ 82 | let html = ""; 83 | 84 | for(let cur = now - 2 ; cur <= now ; cur++){ 85 | let isActive = cur == now ? "active" : ""; 86 | 87 | html += ` 88 | 89 | ` 90 | } 91 | return html; 92 | } 93 | 94 | function setActiveYearBtn( target ){ 95 | $('.year-btn').each( (index,btn) => { 96 | btn.textContent == target ? btn.classList.add("active") : btn.classList.remove("active"); 97 | }) 98 | } 99 | 100 | -------------------------------------------------------------------------------- /src/main/webapp/views/layout/admin-sidebar.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 | 71 | 72 | -------------------------------------------------------------------------------- /src/main/resources/static/css/table.css: -------------------------------------------------------------------------------- 1 | @import url(https://fonts.googleapis.com/css?family=Roboto:400,500,700,300,100); 2 | 3 | body { 4 | font-family: "Roboto", helvetica, arial, sans-serif; 5 | font-size: 16px; 6 | font-weight: 400; 7 | text-rendering: optimizeLegibility; 8 | } 9 | 10 | div.table-title { 11 | display: block; 12 | margin: auto; 13 | max-width: 300px; 14 | padding:5px; 15 | width: 100%; 16 | background: rgba(0,0,0,0.75) !important; 17 | } 18 | 19 | .table-title h3 { 20 | color: #05060a; 21 | font-size: 30px; 22 | font-weight: 400; 23 | font-style:normal; 24 | font-family: "Roboto", helvetica, arial, sans-serif; 25 | text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1); 26 | text-transform:uppercase; 27 | } 28 | 29 | 30 | /*** Table Styles **/ 31 | .table-fill { 32 | background: white; 33 | border-radius:3px; 34 | border-collapse: collapse; 35 | height: 320px; 36 | margin: auto; 37 | max-width: 80%; 38 | padding:5px; 39 | width: 100%; 40 | box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1); 41 | animation: float 5s infinite; 42 | } 43 | 44 | th { 45 | color:#D5DDE5;; 46 | background:#1b1e24; 47 | border-bottom:4px solid #9ea7af; 48 | border-right: 1px solid #343a45; 49 | font-size:18px; 50 | font-weight: 100; 51 | padding:24px; 52 | text-align:left; 53 | text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1); 54 | vertical-align:middle; 55 | } 56 | 57 | th:first-child { 58 | border-top-left-radius:3px; 59 | } 60 | 61 | th:last-child { 62 | border-top-right-radius:3px; 63 | border-right:none; 64 | } 65 | 66 | tr { 67 | border-top: 1px solid #C1C3D1; 68 | border-bottom: 1px solid #C1C3D1; 69 | color:#666B85; 70 | font-size:16px; 71 | font-weight:normal; 72 | text-shadow: 0 1px 1px rgba(256, 256, 256, 0.1); 73 | } 74 | 75 | tr:hover td { 76 | background:#4E5066; 77 | color:#FFFFFF; 78 | border-top: 1px solid #22262e; 79 | } 80 | 81 | tr:first-child { 82 | border-top:none; 83 | } 84 | 85 | tr:last-child { 86 | border-bottom:none; 87 | } 88 | 89 | tr:nth-child(odd) td { 90 | background:#EBEBEB; 91 | } 92 | 93 | tr:nth-child(odd):hover td { 94 | background:#4E5066; 95 | } 96 | 97 | tr:last-child td:first-child { 98 | border-bottom-left-radius:3px; 99 | } 100 | 101 | tr:last-child td:last-child { 102 | border-bottom-right-radius:3px; 103 | } 104 | 105 | td { 106 | background:#FFFFFF; 107 | padding:20px; 108 | text-align:left; 109 | vertical-align:middle; 110 | font-weight:300; 111 | font-size:18px; 112 | text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1); 113 | border-right: 1px solid #C1C3D1; 114 | } 115 | 116 | td:last-child { 117 | border-right: 0px; 118 | } 119 | 120 | th.text-left { 121 | text-align: left; 122 | } 123 | 124 | th.text-center { 125 | text-align: center; 126 | } 127 | 128 | th.text-right { 129 | text-align: right; 130 | } 131 | 132 | td.text-left { 133 | text-align: left; 134 | } 135 | 136 | td.text-center { 137 | text-align: center; 138 | } 139 | 140 | td.text-right { 141 | text-align: right; 142 | } 143 | 144 | /* edited from here!! */ 145 | /* #table-wrapper{ 146 | height:70vh; 147 | overflow-y: scroll; 148 | } */ 149 | /* new added */ 150 | .newstbl{ 151 | width: 1.3in; 152 | height: 1in; 153 | } 154 | -------------------------------------------------------------------------------- /src/main/resources/static/css/admin_home.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --text: rgba(245, 197, 125,1); 3 | --text-light: rgba(255,255,255,0.75); 4 | --light-dark:rgba(0,0,0,0.75); 5 | } 6 | 7 | 8 | 9 | .bg-snow{ 10 | background-color: rgba(255,255,255,1) !important; 11 | } 12 | 13 | .w-85{ 14 | width:85% !important; 15 | } 16 | 17 | .w-15{ 18 | width:15% !important; 19 | } 20 | 21 | .text { 22 | color: var(--text) !important; 23 | } 24 | 25 | .text-dark { 26 | color: var(--text-dark) !important; 27 | } 28 | 29 | .text-light { 30 | color: var(--text-light) !important; 31 | } 32 | 33 | .dark { 34 | background-color: var(--light-dark) !important; 35 | } 36 | 37 | * { 38 | -webkit-transition: 0.5s all; 39 | transition: 0.5s all; 40 | box-sizing: border-box; 41 | } 42 | 43 | .dropdown-menu:hover { 44 | cursor: pointer; 45 | } 46 | 47 | .dropdown-menu.dropdown-item { 48 | color: var(--text) !important; 49 | } 50 | 51 | a { 52 | text-decoration: none; 53 | color: var(--text); 54 | } 55 | 56 | a:visited { 57 | color: var(--text); 58 | } 59 | 60 | #navbar:hover{ 61 | cursor: pointer; 62 | } 63 | 64 | #main-data{ 65 | margin-left:15% !important ; 66 | } 67 | 68 | 69 | #main-body { 70 | height: 92vh; 71 | } 72 | 73 | #main-body #sidebar { 74 | width: 15%; 75 | height: 100%; 76 | } 77 | 78 | #main-body #main-data { 79 | width: 85%; 80 | height: 100%; 81 | } 82 | 83 | #sidebar { 84 | height:100vh !important; 85 | color: var(--text-light); 86 | } 87 | 88 | #sidebar:hover { 89 | cursor: pointer; 90 | } 91 | 92 | .dark-bg { 93 | background-color: var(--light-dark); 94 | -webkit-box-shadow: 0 0 5px var(--text); 95 | box-shadow: 0 0 5px var(--text); 96 | } 97 | 98 | 99 | ul { 100 | list-style-type: none; 101 | color: var(--text-light) !important; 102 | } 103 | 104 | #sidebar-list a { 105 | color: var(--text-light); 106 | } 107 | 108 | #sidebar-list li#sidebar-item { 109 | color: var(--text-light) !important; 110 | margin:0 5px !important; 111 | z-index: 10; 112 | transition: 0.3s all; 113 | } 114 | 115 | #sidebar-list li#sidebar-item:hover { 116 | background-color: rgba(0, 0, 0, 0.25); 117 | } 118 | 119 | #footer * { 120 | font-size: 15px; 121 | font-weight: bold; 122 | } 123 | 124 | #footer-links a { 125 | color: var(--text-light); 126 | } 127 | 128 | #navbar { 129 | -webkit-box-shadow: 0 0 10px var(--text) !important; 130 | box-shadow: 0 0 10px var(--text) !important; 131 | } 132 | 133 | .data-box { 134 | height: 180px; 135 | background-color: rgba(0, 0, 0, 0.75); 136 | } 137 | /*# sourceMappingURL=admin_home.css.map */ 138 | 139 | .year-btn{ 140 | box-shadow:0 0 3px rgba(0, 0, 0, 0.75); 141 | border-radius: 3px; 142 | border:none; 143 | } 144 | 145 | .year-btn.active{ 146 | color:rgba(255,255,255,0.75); 147 | background-color:rgb(13,110,253) ; 148 | } 149 | 150 | #newsPerMonthChart{ 151 | max-height:400px !important; 152 | } 153 | 154 | #chart-wrapper{ 155 | margin-bottom:150px !important; 156 | } 157 | 158 | #box{ 159 | border-radius: 10px !important; 160 | box-shadow: -2px 2px 3px rgba(245, 197, 125,1); 161 | 162 | transition: 0.3s all; 163 | } 164 | 165 | #box:hover{ 166 | cursor: pointer; 167 | box-shadow: -5px 5px 3px rgba(245, 197, 125,1); 168 | margin-left:5px; 169 | margin-bottom: 5px; 170 | } 171 | 172 | -------------------------------------------------------------------------------- /src/main/webapp/views/register.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 | 12 | 13 | Register 14 | 15 | 16 | 19 | 20 | 23 | 24 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
37 |
38 | HEXA 39 |
40 |
${error }
41 | 43 |
44 | 45 | 47 | 48 |
49 |
50 | 52 | 54 | 55 |
56 |
57 | 58 | 61 | 62 |
63 |
64 | 65 |
66 | Home Page 67 | Already had? 68 |
69 |
70 |
71 |
72 | 73 |
74 |
77 |
Created By Team Hexa(Ace 78 | Inspiration)
79 |
80 | 81 | 82 | 83 |
84 |
85 |
86 | 87 | -------------------------------------------------------------------------------- /src/main/resources/static/css/user_role.css: -------------------------------------------------------------------------------- 1 | @charset "ISO-8859-1"; 2 | @import url(https://fonts.googleapis.com/css?family=Roboto:400,500,700,300,100); 3 | :root { 4 | --text: rgba(245, 197, 125,1); 5 | --text-dark: rgba(0,0,0,0.75); 6 | --text-light: rgba(255,255,255,0.75); 7 | } 8 | 9 | body { 10 | font-family: "Roboto", helvetica, arial, sans-serif; 11 | font-size: 16px; 12 | font-weight: 400; 13 | text-rendering: optimizeLegibility; 14 | } 15 | 16 | div.table-title { 17 | display: block; 18 | margin: auto; 19 | max-width: 300px; 20 | padding: 5px; 21 | width: 100%; 22 | } 23 | 24 | .table-title h3 { 25 | color: #05060a; 26 | font-size: 30px; 27 | font-weight: 400; 28 | font-style: normal; 29 | font-family: "Roboto", helvetica, arial, sans-serif; 30 | text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1); 31 | text-transform: uppercase; 32 | } 33 | 34 | /*** Table Styles **/ 35 | .table-fill { 36 | /* background: white; */ 37 | border-radius: 3px; 38 | border-collapse: collapse; 39 | height: 320px; 40 | margin: auto; 41 | max-width: 80%; 42 | padding: 5px; 43 | width: 100%; 44 | -webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1); 45 | box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1); 46 | -webkit-animation: float 5s infinite; 47 | animation: float 5s infinite; 48 | } 49 | 50 | thead { 51 | background-color: rgba(0, 0, 0, 0.85); 52 | letter-spacing: 0.8px; 53 | z-index: 100; 54 | } 55 | 56 | th { 57 | color: var(--text); 58 | font-weight: bold; 59 | padding: 1rem !important; 60 | vertical-align: middle; 61 | } 62 | 63 | th:first-child { 64 | border-top-left-radius: 3px; 65 | } 66 | 67 | th:last-child { 68 | border-top-right-radius: 3px; 69 | border-right: none; 70 | } 71 | 72 | tr { 73 | border-top: 1px solid #C1C3D1; 74 | border-bottom: 1px solid #C1C3D1; 75 | color: #666B85; 76 | font-size: 16px; 77 | font-weight: normal; 78 | text-shadow: 0 1px 1px rgba(255, 255, 255, 0.1); 79 | } 80 | 81 | tr:hover td { 82 | background: #4E5066; 83 | color: #FFFFFF; 84 | border-top: 1px solid #22262e; 85 | } 86 | 87 | tr:first-child { 88 | border-top: none; 89 | } 90 | 91 | tr:last-child { 92 | border-bottom: none; 93 | } 94 | 95 | tr:nth-child(odd) td { 96 | background: #EBEBEB; 97 | } 98 | 99 | tr:nth-child(odd):hover td { 100 | background: rgba(78, 80, 102, 0.75); 101 | } 102 | 103 | tr:last-child td:first-child { 104 | border-bottom-left-radius: 3px; 105 | } 106 | 107 | tr:last-child td:last-child { 108 | border-bottom-right-radius: 3px; 109 | } 110 | 111 | td { 112 | background: #FFFFFF; 113 | padding: 20px; 114 | text-align: left; 115 | vertical-align: middle; 116 | font-weight: 300; 117 | font-size: 18px; 118 | text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1); 119 | border-right: 1px solid #C1C3D1; 120 | } 121 | 122 | td:last-child { 123 | border-right: 0px; 124 | } 125 | 126 | th.text-left { 127 | text-align: left; 128 | } 129 | 130 | th.text-center { 131 | text-align: center; 132 | } 133 | 134 | th.text-right { 135 | text-align: right; 136 | } 137 | 138 | td.text-left { 139 | text-align: left; 140 | } 141 | 142 | td.text-center { 143 | text-align: center; 144 | } 145 | 146 | td.text-right { 147 | text-align: right; 148 | } 149 | 150 | tbody * { 151 | color: var(--text-dark); 152 | font-weight: 400; 153 | letter-spacing: 0.5px; 154 | font-size: 18px; 155 | } 156 | 157 | /* edited from here!! */ 158 | /* #table-wrapper { 159 | height: 70vh; 160 | overflow-y: scroll; 161 | } */ 162 | 163 | #navbar { 164 | -webkit-box-shadow: 0 0 10px var(--text) !important; 165 | box-shadow: 0 0 10px var(--text) !important; 166 | } 167 | /*# sourceMappingURL=user_role.css.map */ -------------------------------------------------------------------------------- /src/main/webapp/views/setup-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 | Setup comments 14 | 15 | 18 | 19 | 20 | 23 | 24 | 25 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | <% 34 | response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); 35 | if (session.getAttribute("userInfo") == null) { 36 | response.sendRedirect("/hexa/home"); 37 | } else { 38 | UserResponseDto dto = (UserResponseDto) session.getAttribute("userInfo"); 39 | if (dto.getUser_role() == 3) { 40 | response.sendRedirect("/hexa/home"); 41 | } 42 | } 43 | %> 44 | 45 |
46 | 47 | 48 | 49 | 50 |
51 | 52 | 53 | 54 |
55 |

Interaction

56 |
57 | 58 |
59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 81 | 82 | 83 | 84 | 85 |
No.News TitleCommenter CountComment CountAction
${count}${news.title}${news.commenters_count}${news.comments_count}Detail
86 |
87 | 88 |
89 |
90 | 91 | 92 | 93 | 94 | 96 | 97 | 98 | 101 | 102 | 103 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /src/main/resources/static/js/pagination.js: -------------------------------------------------------------------------------- 1 | var newsList = []; 2 | var max = 9;//mean 5 news per one page 3 | 4 | $(document).ready(() => { 5 | 6 | fetch("http://localhost:8080/hexa/api/news") 7 | .then(res => res.json()) 8 | .then(data => { 9 | newsList = data; 10 | 11 | let container = $("#news-wrapper"); 12 | let pagination = $("#pagination"); 13 | let page = localStorage.getItem("curPage") == null ? 1 : localStorage.getItem("curPage"); 14 | let totalPage = Math.ceil(newsList.length/max); 15 | 16 | 17 | container.html(getHTML(newsList,page)); 18 | pagination.html(getBtns(newsList)); 19 | 20 | let btns = $(".page-link"); 21 | for(let btn of btns){ 22 | btn.addEventListener("click",(e) => { 23 | let pg = Number(e.target.innerText); 24 | page = pg; 25 | localStorage.setItem("curPage",page); 26 | container.html(getHTML(newsList,page)); 27 | showCurrentPage(page); 28 | }); 29 | } 30 | 31 | $("#prev").click((e) => { 32 | page = getPrevPage(page,totalPage); 33 | container.html(getHTML(newsList,page)); 34 | showCurrentPage(page); 35 | }); 36 | 37 | $("#next").click((e) => { 38 | page = getNextPage(page,totalPage); 39 | container.html(getHTML(newsList,page)); 40 | showCurrentPage(page); 41 | }) 42 | 43 | showCurrentPage(page); 44 | }); 45 | }); 46 | 47 | 48 | //(array,number,node) 49 | function getHTML(datas,pageFrom){ 50 | 51 | let start = (Number(pageFrom) - 1) * max; 52 | let end = start + max; 53 | 54 | let html = '';//result 55 | 56 | for(let i = start ; i < end ; i++){ 57 | if(datas[i] == null) break; 58 | html += ` 59 | 69 | `; 70 | } 71 | 72 | return html; 73 | } 74 | 75 | function getBtns(datas){ 76 | 77 | let totalPage = Math.ceil(datas.length/max); 78 | let html = '
  • '; 79 | 80 | for(let i = 1 ; i <= totalPage ; i++){ 81 | html += `
  • ${i}
  • ` 82 | } 83 | 84 | html += `
  • `; 85 | 86 | return html; 87 | } 88 | 89 | function getPrevPage(now,total){ 90 | let page = Number(now); 91 | let result ; 92 | 93 | page <= 1 ? result = Number(total) : result = page - 1 ; 94 | localStorage.setItem("curpage",result); 95 | return result; 96 | } 97 | 98 | function getNextPage(now,total){ 99 | let page = Number(now); 100 | let result; 101 | 102 | page >= Number(total) ? result = 1 : result = page + 1; 103 | localStorage.setItem("curpage",result); 104 | return result; 105 | } 106 | 107 | function showCurrentPage(now){ 108 | for(let link of $(".page-link")){ 109 | if(link.textContent == now){ 110 | link.classList.add("fw-bold"); 111 | }else{ 112 | link.classList.remove("fw-bold"); 113 | } 114 | } 115 | } -------------------------------------------------------------------------------- /src/main/webapp/views/home.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 | Home 12 | 13 | 14 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 26 | 36 | 37 | 38 | 39 | 40 | 41 |
    42 |
    43 | 44 | ${category.news_category_name} 46 | 47 |
    48 |
    49 | 50 | 51 | 52 |

    Today's 53 | News

    54 | 71 |
    72 | 73 | 74 |
    75 |

    News

    76 |
    77 | 78 |
    79 | 80 |
    81 |
      82 | 83 |
    84 |
    85 |
    86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 95 | 96 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /src/main/webapp/views/layout/public-navbar.jsp: -------------------------------------------------------------------------------- 1 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | 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 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 85 | 86 | 87 | 88 |
    No.TitleCategoryCreaterCreated DateAction
    ${count}${news.news_name}${news.news_category_name}${news.creator_name }${news.created_date} 82 | Update 83 | Delete 84 |
    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 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 91 | 92 | 93 | 94 |
    No.UsernameEmail AddressRoleAction
    ${count}${user.user_name}${user.user_email}${user.user_role_name} 80 | 81 | Ban ${user.user_id} 84 | 85 | 86 | Unban 89 | 90 |
    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 |
    81 |
    82 |
    84 |
    85 | 88 |
    89 | Created By 90 | Hexa_Group(Ace Inspiration) ${newsByTitle.size()} 91 |
    92 |
    93 |
    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 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | <% int id = 1; %> 66 | 67 | 68 | 69 | 70 | 71 | 72 | 75 | 76 | <% id++; %> 77 | 78 | 79 |
    IdCommentCommented UserCommented DateAction
    <%= id %>${interactions.comments }${commenters[stus.index]}${interactions.commented_date } 73 | Delete 74 |
    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 |
    53 | 60 |
    61 | 62 | 63 | - 64 | 94 | 95 |
    96 |
    97 |
    98 |
    99 | 102 |
    103 | Created By 104 | Hexa_Group(Ace Inspiration) 105 |
    106 |
    107 |
    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 | 71 | 72 | 73 | 74 | 75 | <% int id = 1; %> 76 | 77 | 78 | 79 | 80 | 81 | <% id++; %> 82 | 83 | 84 |
    No.Category Name
    <%= id %>${category.news_category_name}
    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 |
    81 | 82 | <% 83 | if (session.getAttribute("userInfo") != null) { 84 | %> 85 |
    86 | 87 | 89 | 90 |
    91 | 92 | <% 93 | } 94 | %> 95 | 96 |
    97 |
    98 | 99 |
    100 | 101 |
    102 |
    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 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 102 | 112 | 113 | 114 | 115 |
    No.UsernameEmail AddressRoleAction
    ${count}${user.user_name}${user.user_email} 103 | 104 |

    Ban

    106 |
    107 | 108 |

    Unban

    110 |
    111 |
    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 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 92 | 93 | 94 | 95 |
    No.Category NameNews CountAction
    ${count}${category.news_category_name}${category.news_count} 85 | 86 | Delete 87 | 88 | 89 | - 90 | 91 |
    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 |
    103 | 105 | 106 | 108 |
    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 |
    74 | ${extraHTML} 75 |
    76 |
    77 | 78 |
    79 |
    80 |
    ${data[i].user_name}
    81 |
    ${data[i].commented_date}
    82 |
    83 |
    84 |
    ${data[i].comments}
    85 | 107 |
    `; 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 | --------------------------------------------------------------------------------