Skip to content
Snippets Groups Projects
Commit 08ce91c5 authored by Marnuri Nitish Marnuri Nitish's avatar Marnuri Nitish Marnuri Nitish
Browse files

Add database object

parent 77ca3d14
No related branches found
No related tags found
No related merge requests found
Showing
with 263 additions and 130 deletions
......@@ -32,6 +32,9 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.commonmark:commonmark:0.21.0'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.mariadb.jdbc:mariadb-java-client:2.1.2'
}
tasks.named('test') {
......
package polish_community_group_11.polish_community.information.common;
import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
public class Utility {
public static String markdownToHtml(String markdown){
Parser parser = Parser.builder().build();
HtmlRenderer renderer = HtmlRenderer.builder().build();
Node document = parser.parse(markdown);
String html = renderer.render(document);
return html;
}
}
package polish_community_group_11.polish_community.information.controllers;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import polish_community_group_11.polish_community.information.services.InformationService;
import polish_community_group_11.polish_community.information.common.Utility;
import polish_community_group_11.polish_community.information.services.InformationRepositoryImpl;
@Controller
public class InformationController {
InformationService infoSevice= new InformationService();
private InformationRepositoryImpl infoService;
public InformationController(InformationRepositoryImpl infoService){
this.infoService = infoService;
}
@GetMapping("getInfo")
public ModelAndView getInformation(){
ModelAndView modelAndView = new ModelAndView("information/information");
modelAndView.addObject("dbInfo",infoSevice.getDbInfo());
String html = Utility.markdownToHtml(infoService.getMenuItem(1).getInfoDescription());
modelAndView.addObject("dbInfo", infoService.getMenuItem(1));
modelAndView.addObject("html",html);
return modelAndView;
}
}
package polish_community_group_11.polish_community.information.models;
import java.time.LocalDate;
public class DBInfo extends Information implements DBInfoImpl{
private int categoryId;
private int tagId;
public DBInfo(int categoryId, int tagId, int informationId, String infoTitle,
String createdBy, LocalDate createdDate, LocalDate updatedDate, String infoDescription){
super(informationId, infoTitle,createdBy, createdDate, updatedDate, infoDescription);
this.categoryId=categoryId;
this.tagId=tagId;
}
public int getCategoryId() {
return categoryId;
}
public void setCategoryId(int categoryId) {
this.categoryId = categoryId;
}
public int getTagId() {
return tagId;
}
public void setTagId(int tagId) {
this.tagId = tagId;
}
public interface DBInfo extends Information {
public int getCategoryId();
public void setCategoryId(int categoryId);
public int getTagId();
public void setTagId(int tagId);
}
package polish_community_group_11.polish_community.information.models;
public interface DBInfoImpl extends InformationImpl{
public int getCategoryId();
public void setCategoryId(int categoryId);
public int getTagId();
public void setTagId(int tagId);
import java.time.LocalDate;
public class DBInfoImpl extends InformationImpl implements DBInfo {
private int categoryId;
private int tagId;
public DBInfoImpl(int categoryId, int tagId, int informationId, String infoTitle,
String createdBy, LocalDate createdDate, LocalDate updatedDate, String infoDescription){
super(informationId, infoTitle,createdBy, createdDate, updatedDate, infoDescription);
this.categoryId=categoryId;
this.tagId=tagId;
}
public int getCategoryId() {
return categoryId;
}
public void setCategoryId(int categoryId) {
this.categoryId = categoryId;
}
public int getTagId() {
return tagId;
}
public void setTagId(int tagId) {
this.tagId = tagId;
}
}
package polish_community_group_11.polish_community.information.models;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.time.LocalDate;
@Data
@AllArgsConstructor
public abstract class Information implements InformationImpl {
private int informationId;
private String infoTitle;
private String createdBy;
private LocalDate createdDate;
private LocalDate updatedDate;
private String infoDescription;
public int getInformationId() {
return informationId;
}
public void setInformationId(int informationId) {
this.informationId = informationId;
}
public String getInfoTitle() {
return infoTitle;
}
public void setInfoTitle(String infoTitle) {
this.infoTitle = infoTitle;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public LocalDate getCreatedDate() {
return createdDate;
}
public void setCreatedDate(LocalDate createdDate) {
this.createdDate = createdDate;
}
public LocalDate getUpdatedDate() {
return updatedDate;
}
public void setUpdatedDate(LocalDate updatedDate) {
this.updatedDate = updatedDate;
}
public String getInfoDescription() {
return infoDescription;
}
public void setInfoDescription(String infoDescription) {
this.infoDescription = infoDescription;
}
public interface Information {
public int getInformationId();
public void setInformationId(int informationId);
public String getInfoTitle();
public void setInfoTitle(String infoTitle);
public String getCreatedBy();
public void setCreatedBy(String createdBy);
public LocalDate getCreatedDate();
public void setCreatedDate(LocalDate createdDate);
public LocalDate getUpdatedDate();
public void setUpdatedDate(LocalDate updatedDate);
public String getInfoDescription();
public void setInfoDescription(String infoDescription);
}
package polish_community_group_11.polish_community.information.models;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.time.LocalDate;
public interface InformationImpl {
public int getInformationId();
public void setInformationId(int informationId);
public String getInfoTitle();
public void setInfoTitle(String infoTitle);
public String getCreatedBy();
public void setCreatedBy(String createdBy);
public LocalDate getCreatedDate();
public void setCreatedDate(LocalDate createdDate);
public LocalDate getUpdatedDate();
public void setUpdatedDate(LocalDate updatedDate);
public String getInfoDescription();
public void setInfoDescription(String infoDescription);
@Data
@AllArgsConstructor
public abstract class InformationImpl implements Information {
private int informationId;
private String infoTitle;
private String createdBy;
private LocalDate createdDate;
private LocalDate updatedDate;
private String infoDescription;
public int getInformationId() {
return informationId;
}
public void setInformationId(int informationId) {
this.informationId = informationId;
}
public String getInfoTitle() {
return infoTitle;
}
public void setInfoTitle(String infoTitle) {
this.infoTitle = infoTitle;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public LocalDate getCreatedDate() {
return createdDate;
}
public void setCreatedDate(LocalDate createdDate) {
this.createdDate = createdDate;
}
public LocalDate getUpdatedDate() {
return updatedDate;
}
public void setUpdatedDate(LocalDate updatedDate) {
this.updatedDate = updatedDate;
}
public String getInfoDescription() {
return infoDescription;
}
public void setInfoDescription(String infoDescription) {
this.infoDescription = infoDescription;
}
}
package polish_community_group_11.polish_community.information.services;
import polish_community_group_11.polish_community.information.models.DBInfo;
import polish_community_group_11.polish_community.information.models.DBInfoImpl;
public interface InformationRepository {
// public DBInfo getDbInfo();
// public void setDbInfo(DBInfo dbInfo);
public DBInfoImpl getMenuItem(int id);
}
package polish_community_group_11.polish_community.information.services;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import polish_community_group_11.polish_community.information.models.DBInfoImpl;
import java.sql.SQLException;
@Repository
public class InformationRepositoryImpl implements InformationRepository {
// private DBInfo dbInfo;
private JdbcTemplate jdbc;
private RowMapper<DBInfoImpl> infoItemMapper;
public InformationRepositoryImpl(JdbcTemplate aJdbc){
// dbInfo = new DBInfoImpl(1,1, 1, "Information Title",
// "Nitish", LocalDate.now(), LocalDate.now(),
// "### Info\n" +
// "\n" +
// "**ipsum odor amet,** consectetuer adipiscing elit. Suspendisse nascetur sodales aenean; ullamcorper amet tristique dictumst. Tristique consectetur non cubilia efficitur dictum venenatis platea viverra. Tortor tempor dictum vivamus in placerat hendrerit. Taciti ligula tortor fusce torquent donec. Erat maximus pellentesque morbi semper sit efficitur. Potenti tempus blandit libero quam phasellus nam commodo placerat.\n" +
// "\n" +
// "![](/assets/back-image.png)Hello World");
this.jdbc = aJdbc;
setInfoItemMapper();
}
public void setInfoItemMapper(){
infoItemMapper = (rs, i) -> new DBInfoImpl(
rs.getInt("category_id"),
rs.getInt("tag_id"),
rs.getInt("info_id"),
rs.getString("info_title"),
rs.getString("created_by"),
rs.getDate("created_date").toLocalDate(),
rs.getDate("updated_date").toLocalDate(),
rs.getString("info_article")
);
}
public DBInfoImpl getMenuItem(int id) {
String sql = "select * from information where info_id=?";
return jdbc.queryForObject(sql, infoItemMapper, id);
}
// public InformationServiceImpl(DBInfo dbInfo){
// this.dbInfo = dbInfo;
// }
// public DBInfo getDbInfo() {
// return dbInfo;
// }
//
// public void setDbInfo(DBInfo dbInfo) {
// this.dbInfo = dbInfo;
// }
}
spring.application.name=polish-community
spring.datasource.url=jdbc:mariadb://localhost:3306/polish_community
spring.datasource.username=root
spring.datasource.password=comsc
spring.sql.init.mode=always
package polish_community_group_11.polish_community.information.services;
delete from information;
import polish_community_group_11.polish_community.information.models.DBInfo;
import polish_community_group_11.polish_community.information.models.DBInfoImpl;
import polish_community_group_11.polish_community.information.models.InformationImpl;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
public class InformationService {
private DBInfoImpl dbInfo;
public InformationService(){
dbInfo = new DBInfo(1,1, 1, "Information Title",
"Nitish", LocalDate.now(), LocalDate.now(),
"### Info\n" +
insert into information (category_id, info_title, created_by, created_date, updated_date, tag_id, info_article)
values (1, 'Info Title', 'Kevin Hart', CURRENT_DATE,CURRENT_DATE, 1, '### Info\n" +
"\n" +
"**ipsum odor amet,** consectetuer adipiscing elit. Suspendisse nascetur sodales aenean; ullamcorper amet tristique dictumst. Tristique consectetur non cubilia efficitur dictum venenatis platea viverra. Tortor tempor dictum vivamus in placerat hendrerit. Taciti ligula tortor fusce torquent donec. Erat maximus pellentesque morbi semper sit efficitur. Potenti tempus blandit libero quam phasellus nam commodo placerat.\n" +
"\n" +
"![](/assets/back-image.png)Hello World");
}
public InformationService(DBInfoImpl dbInfo){
this.dbInfo = dbInfo;
}
public DBInfoImpl getDbInfo() {
return dbInfo;
}
public void setDbInfo(DBInfoImpl dbInfo) {
this.dbInfo = dbInfo;
}
}
"![](/assets/back-image.png)Hello World');
drop table if exists information;
create table if not exists information
(
info_id int auto_increment primary key,
category_id int,
info_title varchar(255),
created_by varchar(255),
created_date date,
updated_date date,
tag_id int,
info_article text
) engine = InnoDB;
\ No newline at end of file
// const turndownService = new TurndownService();
var markdown;
function htmlToMarkdown(){
const html = document.getElementById('info').innerHTML;
markdown = turndownService.turndown(html);
var par = document.createElement('p');
par.innerText = markdown + 'Hello World';
document.getElementById('markdowncontent').appendChild(par);
}
function markdownToHtml(){
// markdown = /*[[${dbInfo.infoDescription}]]*/ '';
const html = marked.parse(markdown);
document.getElementById('markupcontent').innerHTML=html;
}
// document.addEventListener('onload',htmlToMarkdown());
document.addEventListener('onload',markdownToHtml());
\ No newline at end of file
// var markdown;
//
// function htmlToMarkdown(){
// const html = document.getElementById('info').innerHTML;
// markdown = turndownService.turndown(html);
// var par = document.createElement('p');
// par.innerText = markdown + 'Hello World';
// document.getElementById('markdowncontent').appendChild(par);
// }
//
// function markdownToHtml(){
// // markdown = /*[[${dbInfo.infoDescription}]]*/ '';
// const html = marked.parse(markdown);
// document.getElementById('markupcontent').innerHTML=html;
// }
//
// // document.addEventListener('onload',htmlToMarkdown());
// document.addEventListener('onload',markdownToHtml());
\ No newline at end of file
......@@ -20,9 +20,8 @@
<!-- <img src="/assets/back-image.png">-->
<!-- </div>-->
<!-- <div id="markdowncontent"></div>-->
<div id="markupcontent"></div>
<div id="markupcontent" th:utext="${html}"></div>
</main>
</div>
<script src="/js/information/infoScript.js"></script>
</body>
</html>
\ No newline at end of file
package polish_community_group_11.polish_community.information;
import org.junit.jupiter.api.BeforeAll;
import polish_community_group_11.polish_community.information.services.InformationRepositoryImpl;
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
public class TestInformation {
private static InformationRepositoryImpl service;
@BeforeAll
public static void before(){
// service = new InformationRepositoryImpl();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment