[f4b4afa] | 1 | package tech.techharbor.Web;
|
---|
| 2 |
|
---|
| 3 | import jakarta.servlet.http.HttpSession;
|
---|
| 4 | import org.springframework.stereotype.Controller;
|
---|
| 5 | import org.springframework.ui.Model;
|
---|
| 6 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
| 7 | import tech.techharbor.Model.UserTableModel;
|
---|
| 8 | import tech.techharbor.Service.CategoryService;
|
---|
| 9 | import tech.techharbor.Service.ProductService;
|
---|
| 10 | import tech.techharbor.Service.SubcategoryService;
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | @Controller
|
---|
| 14 | public class HomeController {
|
---|
| 15 |
|
---|
| 16 | private final CategoryService categoryService;
|
---|
| 17 | private final SubcategoryService subcategoryService;
|
---|
| 18 | private final ProductService productService;
|
---|
| 19 |
|
---|
| 20 | public HomeController(CategoryService categoryService, SubcategoryService subcategoryService, ProductService productService) {
|
---|
| 21 | this.categoryService = categoryService;
|
---|
| 22 | this.subcategoryService = subcategoryService;
|
---|
| 23 | this.productService = productService;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | @GetMapping("/")
|
---|
| 27 | public String getHomePage(Model model, HttpSession session) {
|
---|
| 28 | model.addAttribute("categories", categoryService.listCategories());
|
---|
| 29 | model.addAttribute("subcategories", subcategoryService.listSubcategories());
|
---|
| 30 | model.addAttribute("products", productService.listProducts());
|
---|
| 31 | UserTableModel user = (UserTableModel) session.getAttribute("user");
|
---|
| 32 | model.addAttribute("user", user);
|
---|
| 33 | Object deliveryManObject = session.getAttribute("deliveryMan");
|
---|
| 34 | model.addAttribute("deliveryMan", deliveryManObject);
|
---|
| 35 | return "index";
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | @GetMapping("/aboutUs")
|
---|
| 39 | public String getAboutUsPage(Model model, HttpSession session) {
|
---|
| 40 | UserTableModel user = (UserTableModel) session.getAttribute("user");
|
---|
| 41 | model.addAttribute("user", user);
|
---|
| 42 | Object deliveryManObject = session.getAttribute("deliveryMan");
|
---|
| 43 | model.addAttribute("deliveryMan", deliveryManObject);
|
---|
| 44 | return "aboutUs";
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | }
|
---|