1 | package com.example.autopartz.controller;
|
---|
2 |
|
---|
3 | import com.example.autopartz.model.User;
|
---|
4 | import com.example.autopartz.service.LoginService;
|
---|
5 | import com.example.autopartz.service.PartService;
|
---|
6 | import org.springframework.stereotype.Controller;
|
---|
7 | import org.springframework.ui.Model;
|
---|
8 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
9 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
10 | import org.springframework.web.bind.annotation.RequestMapping;
|
---|
11 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
12 |
|
---|
13 | @Controller
|
---|
14 | @RequestMapping("/")
|
---|
15 | public class HomeController {
|
---|
16 | private final LoginService loginService;
|
---|
17 | private final PartService partService;
|
---|
18 |
|
---|
19 | public HomeController(LoginService loginService, PartService partService) {
|
---|
20 | this.loginService = loginService;
|
---|
21 | this.partService = partService;
|
---|
22 | }
|
---|
23 |
|
---|
24 | @GetMapping()
|
---|
25 | public String getHomePage(Model model){
|
---|
26 | model.addAttribute("parts",partService.findAll());
|
---|
27 | return "homepage";
|
---|
28 | }
|
---|
29 | @GetMapping("/login")
|
---|
30 | public String getLoginPage(){
|
---|
31 | return "login";
|
---|
32 | }
|
---|
33 | @GetMapping("/register")
|
---|
34 | public String getRegisterPage(){
|
---|
35 | return "register";
|
---|
36 | }
|
---|
37 | @PostMapping("/login")
|
---|
38 | public void handleLogin(@RequestParam String username, @RequestParam String password){
|
---|
39 | User u = loginService.login(username,password);
|
---|
40 | }
|
---|
41 | @PostMapping("/register")
|
---|
42 | public void handleRegister(@RequestParam String username, @RequestParam String name,
|
---|
43 | @RequestParam String password, @RequestParam String email,
|
---|
44 | @RequestParam String number){
|
---|
45 | User u = loginService.register(name,username,email,number,password);
|
---|
46 | }
|
---|
47 | }
|
---|