From 2f475fcbaa40f483d4af230820124d459eb3b2f3 Mon Sep 17 00:00:00 2001 From: Sergei Zakharenko Date: Tue, 7 Nov 2023 21:27:04 +0300 Subject: [PATCH] User's posts list page added. --- .../job4j/cars/controller/UserController.java | 7 +++ .../resources/templates/posts/create.html | 2 +- src/main/resources/templates/posts/list.html | 2 + src/main/resources/templates/posts/one.html | 2 +- src/main/resources/templates/users/posts.html | 46 +++++++++++++++++++ .../resources/templates/users/update.html | 2 +- 6 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/templates/users/posts.html diff --git a/src/main/java/ru/job4j/cars/controller/UserController.java b/src/main/java/ru/job4j/cars/controller/UserController.java index cf0668b..56a2546 100644 --- a/src/main/java/ru/job4j/cars/controller/UserController.java +++ b/src/main/java/ru/job4j/cars/controller/UserController.java @@ -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 savedUser = userService.save(user); diff --git a/src/main/resources/templates/posts/create.html b/src/main/resources/templates/posts/create.html index 23e41c8..b014717 100644 --- a/src/main/resources/templates/posts/create.html +++ b/src/main/resources/templates/posts/create.html @@ -9,7 +9,7 @@ - Автомаг + Новое объявление diff --git a/src/main/resources/templates/posts/list.html b/src/main/resources/templates/posts/list.html index f412df7..774c559 100644 --- a/src/main/resources/templates/posts/list.html +++ b/src/main/resources/templates/posts/list.html @@ -17,6 +17,7 @@
+

@@ -145,6 +146,7 @@

+
diff --git a/src/main/resources/templates/posts/one.html b/src/main/resources/templates/posts/one.html index 6c7f157..61de09c 100644 --- a/src/main/resources/templates/posts/one.html +++ b/src/main/resources/templates/posts/one.html @@ -9,7 +9,7 @@ - Автомаг + Объявление о продаже diff --git a/src/main/resources/templates/users/posts.html b/src/main/resources/templates/users/posts.html new file mode 100644 index 0000000..96c55ad --- /dev/null +++ b/src/main/resources/templates/users/posts.html @@ -0,0 +1,46 @@ + + + + + + + + + + + + + Ваши объявления + + + +
+
+
+ + + + + + + + + + + + + + + + +
Марка и модельДвигательЦветГод выпускаЦена
+ + + + +
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/users/update.html b/src/main/resources/templates/users/update.html index 87c2020..baf5f1e 100644 --- a/src/main/resources/templates/users/update.html +++ b/src/main/resources/templates/users/update.html @@ -9,7 +9,7 @@ - Изменение параметров + Изменение данных пользователя