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

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

Added some views and functionalities

  • Property mode set to 100644
File size: 1.7 KB
Line 
1package com.example.autopartz.controller;
2
3import com.example.autopartz.model.User;
4import com.example.autopartz.service.LoginService;
5import com.example.autopartz.service.PartService;
6import org.springframework.stereotype.Controller;
7import org.springframework.ui.Model;
8import org.springframework.web.bind.annotation.GetMapping;
9import org.springframework.web.bind.annotation.PostMapping;
10import org.springframework.web.bind.annotation.RequestMapping;
11import org.springframework.web.bind.annotation.RequestParam;
12
13@Controller
14@RequestMapping("/")
15public 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}
Note: See TracBrowser for help on using the repository browser.