diff --git a/build.gradle b/build.gradle index ba00bce..e2763db 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/data.mv.db b/data.mv.db index 6b1eaad..9b9f9f5 100644 Binary files a/data.mv.db and b/data.mv.db differ diff --git a/src/main/java/com/example/demo/core/configuration/Constants.java b/src/main/java/com/example/demo/core/configuration/Constants.java index af14112..e8c5eda 100644 --- a/src/main/java/com/example/demo/core/configuration/Constants.java +++ b/src/main/java/com/example/demo/core/configuration/Constants.java @@ -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() { } diff --git a/src/main/java/com/example/demo/news/api/NewsController.java b/src/main/java/com/example/demo/news/api/NewsController.java index 4e30a98..e6bb797 100644 --- a/src/main/java/com/example/demo/news/api/NewsController.java +++ b/src/main/java/com/example/demo/news/api/NewsController.java @@ -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) { diff --git a/src/main/resources/public/css/style.css b/src/main/resources/public/css/style.css index a304cfa..ba7619b 100644 --- a/src/main/resources/public/css/style.css +++ b/src/main/resources/public/css/style.css @@ -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; } \ No newline at end of file diff --git a/src/main/resources/public/images/logo.png b/src/main/resources/public/images/logo.png new file mode 100644 index 0000000..e089579 Binary files /dev/null and b/src/main/resources/public/images/logo.png differ diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index fd39a8a..8f217c2 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -4,10 +4,12 @@ + + diff --git a/src/main/resources/templates/new-edit.html b/src/main/resources/templates/new-edit.html new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/templates/news.html b/src/main/resources/templates/news.html index 57d4926..eaa9e35 100644 --- a/src/main/resources/templates/news.html +++ b/src/main/resources/templates/news.html @@ -4,15 +4,16 @@ - Новости -
-

Типы заказов

+
+ + Новости +
- Добавить тип заказа + Добавить новость
@@ -21,6 +22,17 @@
+
+ +
+
+ +