diff --git a/data/db.mv.db b/data/db.mv.db index 2fc3b4d..232741a 100644 Binary files a/data/db.mv.db and b/data/db.mv.db differ diff --git a/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java b/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java index ea8dc5d..f893257 100644 --- a/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java @@ -45,7 +45,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { log.debug("Security enabled"); http.authorizeRequests() .antMatchers("/").permitAll() - .antMatchers("/login", "/index", "/news/*", "/h2-console/*", "/h2-console").permitAll() + .antMatchers("/login", "/index", "/news/**", "/h2-console/*", "/h2-console").permitAll() .antMatchers("/swagger-ui.html").hasAuthority(UserRoleConstants.ADMIN) .anyRequest().authenticated() .and() diff --git a/src/main/java/ru/ulstu/controller/IndexController.java b/src/main/java/ru/ulstu/controller/IndexController.java index d6f2fc0..9774e53 100644 --- a/src/main/java/ru/ulstu/controller/IndexController.java +++ b/src/main/java/ru/ulstu/controller/IndexController.java @@ -22,7 +22,7 @@ public class IndexController { @GetMapping("/") public String index(Model model) { - model.addAttribute("news", newsService.getAll()); + model.addAttribute("news", newsService.getLast()); return "index"; } } diff --git a/src/main/java/ru/ulstu/controller/NewsController.java b/src/main/java/ru/ulstu/controller/NewsController.java index 3de7221..111a1ca 100644 --- a/src/main/java/ru/ulstu/controller/NewsController.java +++ b/src/main/java/ru/ulstu/controller/NewsController.java @@ -13,12 +13,14 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; import ru.ulstu.model.News; import ru.ulstu.service.NewsService; import javax.validation.Valid; @Controller +@RequestMapping("news") public class NewsController { private final NewsService newsService; @@ -26,6 +28,12 @@ public class NewsController { this.newsService = newsService; } + @GetMapping("/news") + public String index(Model model) { + model.addAttribute("news", newsService.getAll()); + return "news"; + } + @GetMapping("/editNews/{newsId}") public String editNews(@PathVariable(value = "newsId") Integer id, Model model) { model.addAttribute("news", (id != null && id != 0) ? newsService.getById(id) : new News()); @@ -35,7 +43,7 @@ public class NewsController { @GetMapping("/news/{newsId}") public String viewNews(@PathVariable(value = "newsId") Integer id, Model model) { model.addAttribute("news", id != null ? newsService.getById(id) : new News()); - return "news"; + return "viewNews"; } @PostMapping("saveNews") @@ -45,12 +53,12 @@ public class NewsController { } newsService.save(news); - return "redirect:/"; + return "redirect:/news/news"; } @GetMapping("deleteNews/{newsId}") public String delete(@PathVariable(value = "newsId") Integer id) { newsService.delete(id); - return "redirect:/"; + return "redirect:/news/news"; } } diff --git a/src/main/java/ru/ulstu/repository/NewsRepository.java b/src/main/java/ru/ulstu/repository/NewsRepository.java index 3aaf6bf..6bd607a 100644 --- a/src/main/java/ru/ulstu/repository/NewsRepository.java +++ b/src/main/java/ru/ulstu/repository/NewsRepository.java @@ -3,5 +3,8 @@ package ru.ulstu.repository; import org.springframework.data.jpa.repository.JpaRepository; import ru.ulstu.model.News; +import java.util.List; + public interface NewsRepository extends JpaRepository { + List findFirst3ByOrderByDateDesc(); } diff --git a/src/main/java/ru/ulstu/service/NewsService.java b/src/main/java/ru/ulstu/service/NewsService.java index 293d062..3f743f0 100644 --- a/src/main/java/ru/ulstu/service/NewsService.java +++ b/src/main/java/ru/ulstu/service/NewsService.java @@ -46,4 +46,8 @@ public class NewsService { public void delete(Integer id) { newsRepository.deleteById(id); } + + public List getLast() { + return newsRepository.findFirst3ByOrderByDateDesc(); + } } diff --git a/src/main/resources/public/css/main.css b/src/main/resources/public/css/main.css index 359a34c..9b299ad 100644 --- a/src/main/resources/public/css/main.css +++ b/src/main/resources/public/css/main.css @@ -29,6 +29,6 @@ color: black; } -.link-dark, .link-dark:visited, .link-dark:focus { +.link-dark, .link-dark:visited, .link-dark:focus, .link-dark:any-link { color: black; } \ No newline at end of file diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 5d978bd..3146bbf 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -33,7 +33,7 @@