source: src/main/java/com/example/autopartz/controller/HomeController.java@ ae042f4

main
Last change on this file since ae042f4 was ae042f4, checked in by andrejtodorovski <82031894+andrejtodorovski@…>, 18 months ago

Configured spring security, changed spring version

  • Property mode set to 100644
File size: 3.9 KB
Line 
1package com.example.autopartz.controller;
2
3import com.example.autopartz.model.User;
4import com.example.autopartz.repository.PartsForCarTypeAndCategoryRepository;
5import com.example.autopartz.repository.RepairShopReviewSummaryRepository;
6import com.example.autopartz.service.CarService;
7import com.example.autopartz.service.CategoryService;
8import com.example.autopartz.service.LoginService;
9import com.example.autopartz.service.PartService;
10import org.springframework.stereotype.Controller;
11import org.springframework.ui.Model;
12import org.springframework.web.bind.annotation.GetMapping;
13import org.springframework.web.bind.annotation.PostMapping;
14import org.springframework.web.bind.annotation.RequestMapping;
15import org.springframework.web.bind.annotation.RequestParam;
16
17import javax.servlet.http.HttpServletRequest;
18
19@Controller
20@RequestMapping("/")
21public class HomeController {
22 private final LoginService loginService;
23 private final PartService partService;
24 private final PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository;
25 private final CarService carService;
26 private final CategoryService categoryService;
27 private final RepairShopReviewSummaryRepository repairShopReviewSummaryRepository;
28
29 public HomeController(LoginService loginService, PartService partService, PartsForCarTypeAndCategoryRepository partsForCarTypeAndCategoryRepository, CarService carService, CategoryService categoryService, RepairShopReviewSummaryRepository repairShopReviewSummaryRepository) {
30 this.loginService = loginService;
31 this.partService = partService;
32 this.partsForCarTypeAndCategoryRepository = partsForCarTypeAndCategoryRepository;
33 this.carService = carService;
34 this.categoryService = categoryService;
35 this.repairShopReviewSummaryRepository = repairShopReviewSummaryRepository;
36 }
37
38 @GetMapping()
39 public String getHomePage(Model model, HttpServletRequest request){
40 model.addAttribute("bodyContent","home");
41 model.addAttribute("user",request.getRemoteUser());
42 return "master-template";
43 }
44 @GetMapping("/products")
45 public String getProducts(Model model){
46 model.addAttribute("parts",partService.findAll());
47 model.addAttribute("cars",carService.findAll());
48 model.addAttribute("categories",categoryService.findAll());
49 model.addAttribute("bodyContent","products");
50 return "master-template";
51 }
52 @GetMapping("/services")
53 public String getServices(Model model){
54 model.addAttribute("services",repairShopReviewSummaryRepository.findAll());
55 model.addAttribute("bodyContent","services");
56 return "master-template";
57 }
58 @GetMapping("/filtered")
59 public String getPartsForCarTypeAndCategory(@RequestParam String cartype, @RequestParam String category, Model model){
60 model.addAttribute("filtered", partsForCarTypeAndCategoryRepository.findAllByCartypeAndCategory(cartype,category));
61 model.addAttribute("bodyContent","filteredParts");
62 return "master-template";
63 }
64 @GetMapping("/login")
65 public String getLoginPage(Model model){
66 model.addAttribute("bodyContent","login");
67 return "master-template";
68 }
69 @GetMapping("/register")
70 public String getRegisterPage(Model model){
71 model.addAttribute("bodyContent","register");
72 return "master-template";
73 }
74 @PostMapping("/login")
75 public void handleLogin(@RequestParam String username, @RequestParam String password){
76 User u = loginService.login(username,password);
77 System.out.println(u.getName_user());
78 }
79 @PostMapping("/register")
80 public void handleRegister(@RequestParam String username, @RequestParam String name,
81 @RequestParam String password, @RequestParam String email,
82 @RequestParam String number){
83 User u = loginService.register(name,username,email,number,password);
84 }
85}
Note: See TracBrowser for help on using the repository browser.