Начало сущности 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-starter-thymeleaf'
|
||||
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.3.0'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
runtimeOnly 'org.webjars.npm:bootstrap:5.3.3'
|
||||
implementation 'com.h2database:h2:2.2.224'
|
||||
|
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -6,6 +6,8 @@ public class Constants {
|
||||
public static final String API_URL = "/api/1.0";
|
||||
|
||||
public static final String DEFAULT_PAGE_SIZE = "5";
|
||||
|
||||
public static final String REDIRECT_VIEW = "redirect:";
|
||||
|
||||
private Constants() {
|
||||
}
|
||||
|
@ -1,20 +1,18 @@
|
||||
package com.example.demo.news.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.stereotype.Controller;
|
||||
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.PathVariable;
|
||||
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.RequestMapping;
|
||||
|
||||
import com.example.demo.core.configuration.Constants;
|
||||
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.service.NewsService;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@ -23,8 +21,8 @@ import jakarta.validation.Valid;
|
||||
public class NewsController {
|
||||
public static final String URL = "/news";
|
||||
private static final String NEWS_VIEW = "news";
|
||||
private static final String NEWS_VIEW_EDIT_VIEW = "new-edit";
|
||||
private static final String NEWS_VIEW_ATTRIBUTE = "news";
|
||||
private static final String NEWS_EDIT_VIEW = "new-edit";
|
||||
private static final String NEWS_ATTRIBUTE = "news";
|
||||
private final NewsService newsService;
|
||||
private final ModelMapper modelMapper;
|
||||
private final DepartmentService departmentService;
|
||||
@ -53,7 +51,7 @@ public class NewsController {
|
||||
|
||||
@GetMapping
|
||||
public String getAll(Model model) {
|
||||
model.addAttribute(NEWS_VIEW_ATTRIBUTE,
|
||||
model.addAttribute(NEWS_ATTRIBUTE,
|
||||
newsService.getAll().stream().map(this::toDto).toList());
|
||||
return NEWS_VIEW;
|
||||
}
|
||||
@ -68,6 +66,24 @@ public class NewsController {
|
||||
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}")
|
||||
// public NewsDto update(@PathVariable(name = "id") Long id, @RequestBody
|
||||
// NewsDto dto) {
|
||||
|
@ -65,36 +65,41 @@ td form {
|
||||
.cart-item {
|
||||
height: auto;
|
||||
}
|
||||
.headStyle{
|
||||
|
||||
.headStyle {
|
||||
color: #FFFFFF
|
||||
}
|
||||
.headStyleNavBar{
|
||||
|
||||
.headStyleNavBar {
|
||||
background-color: #454545;
|
||||
}
|
||||
.headStyleNavBar2{
|
||||
|
||||
.headStyleNavBar2 {
|
||||
background-color: #575757
|
||||
}
|
||||
.stsp{
|
||||
|
||||
.stsp {
|
||||
font-size: 30px;
|
||||
color: #333333;
|
||||
text-align: center;
|
||||
margin-top: 70;
|
||||
}
|
||||
|
||||
.mainSt{
|
||||
.mainSt {
|
||||
color: #060647;
|
||||
font-size: 50px;
|
||||
}
|
||||
|
||||
.rectPage2{
|
||||
.rectPage2 {
|
||||
color: #FFFFFF;
|
||||
width: 1470px;
|
||||
height: 900px;
|
||||
border : 2px solid #000000;
|
||||
border: 2px solid #000000;
|
||||
background-color: #FFFFFF;
|
||||
opacity: 0.8;
|
||||
}
|
||||
.rectPage4{
|
||||
|
||||
.rectPage4 {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
color: #FFFFFF;
|
||||
@ -104,55 +109,66 @@ td form {
|
||||
background-color: #7c7474;
|
||||
opacity: 0.8;
|
||||
}
|
||||
.rectPage5{
|
||||
|
||||
.rectPage5 {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
margin-top : auto;
|
||||
margin-bottom : auto;
|
||||
margin-top: auto;
|
||||
margin-bottom: auto;
|
||||
width: 600px;
|
||||
height: 500px;
|
||||
border: 2px solid #000000;
|
||||
background-color: #FFFFFF;
|
||||
opacity: 0.7;
|
||||
}
|
||||
.rectNews{
|
||||
width:310px;
|
||||
height:200px;
|
||||
border : 2px solid #2582A3;
|
||||
|
||||
.rectNews {
|
||||
width: 310px;
|
||||
height: 200px;
|
||||
border: 2px solid #2582A3;
|
||||
border-radius: 8%;
|
||||
margin-left: 180;
|
||||
margin-top: 9px;
|
||||
margin-bottom:25px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
.stylePage2{
|
||||
float : center;
|
||||
|
||||
.stylePage2 {
|
||||
float: center;
|
||||
margin-right: 7;
|
||||
color: #063638;
|
||||
font-size: 18px
|
||||
}
|
||||
.styleParagraph{
|
||||
|
||||
.styleParagraph {
|
||||
border-top: 2px solid #000000;
|
||||
}
|
||||
.styleBlack{
|
||||
color : #000000;
|
||||
|
||||
.styleBlack {
|
||||
color: #000000;
|
||||
}
|
||||
.stylePage2LargeSymbol{
|
||||
float : left;
|
||||
|
||||
.stylePage2LargeSymbol {
|
||||
float: left;
|
||||
margin-right: 7;
|
||||
color: #118D94;
|
||||
font-size: 50px;
|
||||
line-height: 52px
|
||||
}
|
||||
.rectNewsTextBox{
|
||||
width : 310px;
|
||||
min-height : 50px;
|
||||
|
||||
.rectNewsTextBox {
|
||||
width: 310px;
|
||||
min-height: 50px;
|
||||
border: 2px solid #000000;
|
||||
background-color: #FFFFFF;
|
||||
opacity: 0.7;
|
||||
border-radius: 10% / 40%;
|
||||
margin-top : 5px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
.rectNewsText{
|
||||
|
||||
.rectNewsText {
|
||||
color: #000000;
|
||||
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>
|
||||
<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" />
|
||||
<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-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" />
|
||||
</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>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="/css/style.css" />
|
||||
<title>Новости</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main layout:fragment="content">
|
||||
<h2>Типы заказов</h2>
|
||||
<main class="text-center" layout:fragment="content">
|
||||
<span class="mainSt">
|
||||
<b>Новости</b>
|
||||
</span>
|
||||
<div>
|
||||
<a href="/news/edit/" class="btn btn-primary">Добавить тип заказа</a>
|
||||
<a href="/news/edit/" class="btn btn-primary">Добавить новость</a>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col mt-4" th:each="newItem : ${news}">
|
||||
@ -21,6 +22,17 @@
|
||||
<div class="rectNewsTextBox">
|
||||
<span class="rectNewsText">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user