5 lab допилил функционал с 4 лабы

This commit is contained in:
Павел Сорокин 2023-04-24 08:32:10 +04:00
parent 48558c6fc8
commit 620d48c88d
2 changed files with 31 additions and 8 deletions

View File

@ -123,6 +123,21 @@ public class PostMvcController {
return "redirect:/post/{postId}";
}
@GetMapping("/userPosts")
public String getUserPosts(@RequestParam(value = "userId") Long userId,Model model)
{
model.addAttribute("posts",
userService.GetUserPosts(userId).stream()
.map(PostDto::new)
.toList());
model.addAttribute("users",
userService.findAllUsers().stream()
.map(UserDto::new)
.toList());
return "post";
}
@GetMapping(value = {"/addComment/{postId}", "/editComment/{id}"})
public String editComment(@PathVariable(required = false) Long id,
@PathVariable(required = false) Long postId,

View File

@ -3,6 +3,7 @@
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="/webjars/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
@ -14,13 +15,16 @@
<i class="fa-solid fa-magnifying-glass"></i>
</button>
</form>
<div class="mx-3">
<select id="selectBox">
<option th:each="value: ${users}" th:selected="${selectBox} == ${value}">
<span th:text="${value.firstName}"></span>
</option>
</select>
</div>
<form th:action="@{/post/userPosts}" id="myForm" class="d-flex">
<div class="mx-3">
<select id="selectBox" th:name="userId">
<option value="" disabled selected>Select your option</option>
<option th:each="value: ${users}" th:selected="${selectBox} == ${value}">
<span th:text="${value.Id}" th:value="${value.Id}"></span>
</option>
</select>
</div>
</form>
<div>
<a class="btn btn-outline-primary text-center mx-2"
th:href="@{/post/edit}">
@ -86,7 +90,11 @@
</body>
<th:block layout:fragment="scripts">
<script>
$(document).ready(function() {
$('#selectBox').on('change', function() {
this.form.submit();
});
});
</script>
</th:block>
</html>