source: src/main/java/tech/techharbor/Web/UserReviewController.java@ f4b4afa

main
Last change on this file since f4b4afa was f4b4afa, checked in by Nikola Todoroski <nikola.todoroski@…>, 6 months ago

Pushed whole project, original project location on github:https://github.com/hehxd/Tech-Harbor

  • Property mode set to 100644
File size: 1.8 KB
Line 
1package tech.techharbor.Web;
2
3import jakarta.servlet.http.HttpSession;
4import org.springframework.stereotype.Controller;
5import org.springframework.ui.Model;
6import org.springframework.web.bind.annotation.GetMapping;
7import org.springframework.web.bind.annotation.PathVariable;
8import tech.techharbor.Model.ProductModel;
9import tech.techharbor.Model.ReviewModel;
10import tech.techharbor.Model.UserTableModel;
11import tech.techharbor.Service.ProductService;
12import tech.techharbor.Service.ReviewService;
13
14import java.util.ArrayList;
15import java.util.List;
16
17@Controller
18public class UserReviewController {
19 private final ReviewService reviewService;
20 private final ProductService productService;
21
22 public UserReviewController(ReviewService reviewService, ProductService productService) {
23 this.reviewService = reviewService;
24 this.productService = productService;
25 }
26
27 @GetMapping("/reviews/{id}")
28 public String showUserReviews(@PathVariable Integer id, Model model, HttpSession session) {
29 UserTableModel user = (UserTableModel) session.getAttribute("user");
30 model.addAttribute("user", user);
31 List<ReviewModel> allReviews = reviewService.listReviews();
32 List<ReviewModel> reviews = new ArrayList<>();
33 List<ProductModel> products = new ArrayList<>();
34 for (ReviewModel review : allReviews) {
35
36 if (review.getCustomerId().equals(user.getUserId())) {
37 reviews.add(review);
38 ProductModel product = productService.findById(review.getProductId());
39 products.add(product);
40 }
41 }
42 model.addAttribute("reviews", reviews);
43 model.addAttribute("products", products);
44 model.addAttribute("index", 0);
45 return "myReviews";
46 }
47
48
49}
Note: See TracBrowser for help on using the repository browser.