Skip to content

Commit

Permalink
User's posts list page added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Niaktes committed Nov 7, 2023
1 parent 98485d9 commit 2f475fc
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/main/java/ru/job4j/cars/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public String getUpdatePage(Model model, HttpSession session) {
return "users/update";
}

@GetMapping("posts")
public String getUsersPosts(Model model, HttpSession session) {
User user = (User) session.getAttribute("user");
model.addAttribute("posts", postService.findAllByUserId(user.getId()));
return "users/posts";
}

@PostMapping("/register")
public String register(@ModelAttribute User user, Model model) {
Optional<User> savedUser = userService.save(user);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/posts/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script th:src="@{/js/jquery-3.7.1.min.js}"></script>
<script th:src="@{/js/bootstrap.bundle.js}"></script>

<title>Автомаг</title>
<title>Новое объявление</title>
</head>

<body>
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/templates/posts/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<header th:insert="~{blocks/header :: header_main}"></header>
<div class="container col-12">

<!-- Accordion search form -->
<div class="accordion accordion-flush" id="searchAccordion">
<div class="accordion-item">
<h4 class="accordion-header" id="flush-headingOne">
Expand Down Expand Up @@ -145,6 +146,7 @@ <h4 class="accordion-header" id="flush-headingOne">
</div>
</div>

<!-- Posts list -->
<div th:each="post: ${posts}">
<div class="row border border-secondary rounded">
<div class="mb-1"></div>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/posts/one.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script th:src="@{/js/jquery-3.7.1.min.js}"></script>
<script th:src="@{/js/bootstrap.bundle.js}"></script>

<title>Автомаг</title>
<title>Объявление о продаже</title>
</head>

<body>
Expand Down
46 changes: 46 additions & 0 deletions src/main/resources/templates/users/posts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!doctype html>
<html lang="en">
<head>

<!-- Зависимости Bootstrap-->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
<script th:src="@{/js/jquery-3.7.1.min.js}"></script>
<script th:src="@{/js/bootstrap.bundle.js}"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.2/font/bootstrap-icons.css">

<title>Ваши объявления</title>
</head>

<body>
<div class="container-fluid p-0">
<header th:insert="~{blocks/header :: header_main}"></header>
<div class="container col-12">
<table class="table table-hover">
<thead>
<tr>
<th scope="col" style="width: 50px;"><i class="bi bi-body-text"></i></th>
<th scope="col">Марка и модель</th>
<th class="text-center" scope="col" style="width: 200px;">Двигатель</th>
<th class="text-center" scope="col" style="width: 200px;">Цвет</th>
<th class="text-center" scope="col" style="width: 200px;">Год выпуска</th>
<th class="text-center" scope="col" style="width: 200px;">Цена</th>
</tr>
</thead>
<tbody>
<tr th:each="post : ${posts}">
<td><a class="btn btn-sm btn-outline-primary" th:href="@{/posts/edit/{postId}(postId=${post.id})}"><i class="bi bi-pencil-square"></i></a></td>
<td th:text="${post.car.brand.name} + ' ' + ${post.car.carModel.name}" />
<td class="text-center" th:text="${post.car.engine.fuelType.name} + ' ' + ${post.car.engine.engineSize.size} + 'л'" />
<td class="text-center" th:text="${post.car.color.name}" />
<td class="text-center" th:text="${post.car.year}" />
<td class="text-center" th:text="${post.price} + 'р'" />
</tr>
</tbody>
</table>
</div>
<footer th:insert="~{blocks/footer :: footer}"></footer>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion src/main/resources/templates/users/update.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script th:src="@{/js/jquery-3.7.1.min.js}"></script>
<script th:src="@{/js/bootstrap.bundle.js}"></script>

<title>Изменение параметров</title>
<title>Изменение данных пользователя</title>
</head>

<body>
Expand Down

0 comments on commit 2f475fc

Please sign in to comment.