Начало сущности news
This commit is contained in:
parent
16114c71a5
commit
f12e9dfad5
@ -35,6 +35,7 @@ dependencies {
|
|||||||
|
|
||||||
implementation 'org.springframework.boot:spring-boot-devtools'
|
implementation 'org.springframework.boot:spring-boot-devtools'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||||
|
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.3.0'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
runtimeOnly 'org.webjars.npm:bootstrap:5.3.3'
|
runtimeOnly 'org.webjars.npm:bootstrap:5.3.3'
|
||||||
implementation 'com.h2database:h2:2.2.224'
|
implementation 'com.h2database:h2:2.2.224'
|
||||||
|
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -7,6 +7,8 @@ public class Constants {
|
|||||||
|
|
||||||
public static final String DEFAULT_PAGE_SIZE = "5";
|
public static final String DEFAULT_PAGE_SIZE = "5";
|
||||||
|
|
||||||
|
public static final String REDIRECT_VIEW = "redirect:";
|
||||||
|
|
||||||
private Constants() {
|
private Constants() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,18 @@
|
|||||||
package com.example.demo.news.api;
|
package com.example.demo.news.api;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.modelmapper.ModelMapper;
|
import org.modelmapper.ModelMapper;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import com.example.demo.core.configuration.Constants;
|
||||||
import com.example.demo.department.service.DepartmentService;
|
import com.example.demo.department.service.DepartmentService;
|
||||||
import com.example.demo.news.service.NewsService;
|
|
||||||
import com.example.demo.news.model.NewsEntity;
|
import com.example.demo.news.model.NewsEntity;
|
||||||
|
import com.example.demo.news.service.NewsService;
|
||||||
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
@ -23,8 +21,8 @@ import jakarta.validation.Valid;
|
|||||||
public class NewsController {
|
public class NewsController {
|
||||||
public static final String URL = "/news";
|
public static final String URL = "/news";
|
||||||
private static final String NEWS_VIEW = "news";
|
private static final String NEWS_VIEW = "news";
|
||||||
private static final String NEWS_VIEW_EDIT_VIEW = "new-edit";
|
private static final String NEWS_EDIT_VIEW = "new-edit";
|
||||||
private static final String NEWS_VIEW_ATTRIBUTE = "news";
|
private static final String NEWS_ATTRIBUTE = "news";
|
||||||
private final NewsService newsService;
|
private final NewsService newsService;
|
||||||
private final ModelMapper modelMapper;
|
private final ModelMapper modelMapper;
|
||||||
private final DepartmentService departmentService;
|
private final DepartmentService departmentService;
|
||||||
@ -53,7 +51,7 @@ public class NewsController {
|
|||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public String getAll(Model model) {
|
public String getAll(Model model) {
|
||||||
model.addAttribute(NEWS_VIEW_ATTRIBUTE,
|
model.addAttribute(NEWS_ATTRIBUTE,
|
||||||
newsService.getAll().stream().map(this::toDto).toList());
|
newsService.getAll().stream().map(this::toDto).toList());
|
||||||
return NEWS_VIEW;
|
return NEWS_VIEW;
|
||||||
}
|
}
|
||||||
@ -68,6 +66,24 @@ public class NewsController {
|
|||||||
return toDto(newsService.create(toEntity(dto)));
|
return toDto(newsService.create(toEntity(dto)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete/{id}")
|
||||||
|
public String delete(
|
||||||
|
@PathVariable(name = "id") Long id) {
|
||||||
|
newsService.delete(id);
|
||||||
|
return Constants.REDIRECT_VIEW + URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/edit/{id}")
|
||||||
|
public String update(
|
||||||
|
@PathVariable(name = "id") Long id,
|
||||||
|
Model model) {
|
||||||
|
if (id <= 0) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
model.addAttribute(NEWS_ATTRIBUTE, toDto(newsService.get(id)));
|
||||||
|
return NEWS_EDIT_VIEW;
|
||||||
|
}
|
||||||
|
|
||||||
// @PutMapping("/{id}")
|
// @PutMapping("/{id}")
|
||||||
// public NewsDto update(@PathVariable(name = "id") Long id, @RequestBody
|
// public NewsDto update(@PathVariable(name = "id") Long id, @RequestBody
|
||||||
// NewsDto dto) {
|
// NewsDto dto) {
|
||||||
|
@ -65,36 +65,41 @@ td form {
|
|||||||
.cart-item {
|
.cart-item {
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
.headStyle{
|
|
||||||
|
.headStyle {
|
||||||
color: #FFFFFF
|
color: #FFFFFF
|
||||||
}
|
}
|
||||||
.headStyleNavBar{
|
|
||||||
|
.headStyleNavBar {
|
||||||
background-color: #454545;
|
background-color: #454545;
|
||||||
}
|
}
|
||||||
.headStyleNavBar2{
|
|
||||||
|
.headStyleNavBar2 {
|
||||||
background-color: #575757
|
background-color: #575757
|
||||||
}
|
}
|
||||||
.stsp{
|
|
||||||
|
.stsp {
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
color: #333333;
|
color: #333333;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-top: 70;
|
margin-top: 70;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mainSt{
|
.mainSt {
|
||||||
color: #060647;
|
color: #060647;
|
||||||
font-size: 50px;
|
font-size: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.rectPage2{
|
.rectPage2 {
|
||||||
color: #FFFFFF;
|
color: #FFFFFF;
|
||||||
width: 1470px;
|
width: 1470px;
|
||||||
height: 900px;
|
height: 900px;
|
||||||
border : 2px solid #000000;
|
border: 2px solid #000000;
|
||||||
background-color: #FFFFFF;
|
background-color: #FFFFFF;
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
.rectPage4{
|
|
||||||
|
.rectPage4 {
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
color: #FFFFFF;
|
color: #FFFFFF;
|
||||||
@ -104,55 +109,66 @@ td form {
|
|||||||
background-color: #7c7474;
|
background-color: #7c7474;
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
.rectPage5{
|
|
||||||
|
.rectPage5 {
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
margin-top : auto;
|
margin-top: auto;
|
||||||
margin-bottom : auto;
|
margin-bottom: auto;
|
||||||
width: 600px;
|
width: 600px;
|
||||||
height: 500px;
|
height: 500px;
|
||||||
border: 2px solid #000000;
|
border: 2px solid #000000;
|
||||||
background-color: #FFFFFF;
|
background-color: #FFFFFF;
|
||||||
opacity: 0.7;
|
opacity: 0.7;
|
||||||
}
|
}
|
||||||
.rectNews{
|
|
||||||
width:310px;
|
.rectNews {
|
||||||
height:200px;
|
width: 310px;
|
||||||
border : 2px solid #2582A3;
|
height: 200px;
|
||||||
|
border: 2px solid #2582A3;
|
||||||
border-radius: 8%;
|
border-radius: 8%;
|
||||||
margin-left: 180;
|
margin-left: 180;
|
||||||
margin-top: 9px;
|
margin-top: 9px;
|
||||||
margin-bottom:25px;
|
margin-bottom: 25px;
|
||||||
}
|
}
|
||||||
.stylePage2{
|
|
||||||
float : center;
|
.stylePage2 {
|
||||||
|
float: center;
|
||||||
margin-right: 7;
|
margin-right: 7;
|
||||||
color: #063638;
|
color: #063638;
|
||||||
font-size: 18px
|
font-size: 18px
|
||||||
}
|
}
|
||||||
.styleParagraph{
|
|
||||||
|
.styleParagraph {
|
||||||
border-top: 2px solid #000000;
|
border-top: 2px solid #000000;
|
||||||
}
|
}
|
||||||
.styleBlack{
|
|
||||||
color : #000000;
|
.styleBlack {
|
||||||
|
color: #000000;
|
||||||
}
|
}
|
||||||
.stylePage2LargeSymbol{
|
|
||||||
float : left;
|
.stylePage2LargeSymbol {
|
||||||
|
float: left;
|
||||||
margin-right: 7;
|
margin-right: 7;
|
||||||
color: #118D94;
|
color: #118D94;
|
||||||
font-size: 50px;
|
font-size: 50px;
|
||||||
line-height: 52px
|
line-height: 52px
|
||||||
}
|
}
|
||||||
.rectNewsTextBox{
|
|
||||||
width : 310px;
|
.rectNewsTextBox {
|
||||||
min-height : 50px;
|
width: 310px;
|
||||||
|
min-height: 50px;
|
||||||
border: 2px solid #000000;
|
border: 2px solid #000000;
|
||||||
background-color: #FFFFFF;
|
background-color: #FFFFFF;
|
||||||
opacity: 0.7;
|
opacity: 0.7;
|
||||||
border-radius: 10% / 40%;
|
border-radius: 10% / 40%;
|
||||||
margin-top : 5px;
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
.rectNewsText{
|
|
||||||
|
.rectNewsText {
|
||||||
color: #000000;
|
color: #000000;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 3px;
|
||||||
}
|
}
|
BIN
src/main/resources/public/images/logo.png
Normal file
BIN
src/main/resources/public/images/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
@ -4,10 +4,12 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" href="/images/logo.png" type="image/x-icon">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<script type="text/javascript" src="/webjars/bootstrap/5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
<script type="text/javascript" src="/webjars/bootstrap/5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<link rel="stylesheet" href="/webjars/bootstrap/5.3.3/dist/css/bootstrap.min.css" />
|
<link rel="stylesheet" href="/webjars/bootstrap/5.3.3/dist/css/bootstrap.min.css" />
|
||||||
<link rel="stylesheet" href="/webjars/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css" />
|
<link rel="stylesheet" href="/webjars/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css" />
|
||||||
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||||
<link rel="stylesheet" href="/css/style.css" />
|
<link rel="stylesheet" href="/css/style.css" />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
0
src/main/resources/templates/new-edit.html
Normal file
0
src/main/resources/templates/new-edit.html
Normal file
@ -4,15 +4,16 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<link rel="stylesheet" href="/css/style.css" />
|
|
||||||
<title>Новости</title>
|
<title>Новости</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<main layout:fragment="content">
|
<main class="text-center" layout:fragment="content">
|
||||||
<h2>Типы заказов</h2>
|
<span class="mainSt">
|
||||||
|
<b>Новости</b>
|
||||||
|
</span>
|
||||||
<div>
|
<div>
|
||||||
<a href="/news/edit/" class="btn btn-primary">Добавить тип заказа</a>
|
<a href="/news/edit/" class="btn btn-primary">Добавить новость</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col mt-4" th:each="newItem : ${news}">
|
<div class="col mt-4" th:each="newItem : ${news}">
|
||||||
@ -21,6 +22,17 @@
|
|||||||
<div class="rectNewsTextBox">
|
<div class="rectNewsTextBox">
|
||||||
<span class="rectNewsText">
|
<span class="rectNewsText">
|
||||||
<b scope="row" th:text="${newItem.description}"></b>
|
<b scope="row" th:text="${newItem.description}"></b>
|
||||||
|
<form th:action="@{/news/edit/{id}(id=${newItem.id})}" method="get">
|
||||||
|
<button type="submit" class="btn btn-link button-link">
|
||||||
|
<i class="fa fa-edit"></i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<form th:action="@{/news/delete/{id}(id=${newItem.id})}" method="post">
|
||||||
|
<button type="submit" class="btn btn-link button-link"
|
||||||
|
onclick="return confirm('Вы уверены?')">
|
||||||
|
<i class="fa fa-trash"></i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user