source: src/main/java/com/project/beautycenter/web/RegisterController.java

Last change on this file was 850b344, checked in by Tamara Simikj <tamara.simic12@…>, 2 years ago

Initial commit

  • Property mode set to 100644
File size: 3.0 KB
Line 
1package com.project.beautycenter.web;
2
3import com.project.beautycenter.model.Beautycenter;
4import com.project.beautycenter.model.Users;
5import com.project.beautycenter.service.BeautyCenterService;
6import com.project.beautycenter.service.KlientiService;
7import com.project.beautycenter.service.UsersService;
8import com.project.beautycenter.service.VraboteniService;
9import org.springframework.stereotype.Controller;
10import org.springframework.ui.Model;
11import org.springframework.web.bind.annotation.GetMapping;
12import org.springframework.web.bind.annotation.PostMapping;
13import org.springframework.web.bind.annotation.RequestParam;
14
15import java.time.Instant;
16import java.util.List;
17
18@Controller
19public class RegisterController {
20 private final UsersService usersService;
21 private final KlientiService klientiService;
22 private final VraboteniService vraboteniService;
23 private final BeautyCenterService beautyCenterService;
24
25 public RegisterController(UsersService usersService, KlientiService klientiService, VraboteniService vraboteniService, BeautyCenterService beautyCenterService) {
26 this.usersService = usersService;
27 this.klientiService = klientiService;
28 this.vraboteniService = vraboteniService;
29 this.beautyCenterService = beautyCenterService;
30 }
31
32
33 @GetMapping("/register")
34 public String register() {
35 return "register_form.html";
36 }
37
38 @PostMapping("/register")
39 public String create(@RequestParam String username,
40 @RequestParam String name,
41 @RequestParam String surname,
42 @RequestParam String telbr,
43 @RequestParam String email,
44 @RequestParam String password) {
45
46 Users users = this.usersService.create(username, password);
47 this.klientiService.create(users, name, surname, telbr, email);
48
49 return "redirect:/login";
50
51 }
52
53 @GetMapping("/registerEmployee")
54 public String registerEmpl(Model model) {
55 List<Beautycenter> beautyCentres = this.beautyCenterService.listAll();
56 model.addAttribute("beautyCentres", beautyCentres);
57 return "registerEmpl_form.html";
58 }
59
60 @PostMapping("/registerEmployee")
61 public String create(@RequestParam String username,
62 @RequestParam String name,
63 @RequestParam String middleName,
64 @RequestParam String surname,
65 @RequestParam String telbr,
66 @RequestParam String email,
67 @RequestParam String password,
68 @RequestParam Integer rabIskustvo,
69 @RequestParam String rabotiOd,
70 @RequestParam String beautyCenterId) {
71
72 Users users = this.usersService.create(username, password);
73 this.vraboteniService.create(users, name, middleName, surname, telbr, email, rabIskustvo,
74 Instant.parse(rabotiOd), beautyCenterId);
75
76 return "redirect:/login";
77
78 }
79
80}
Note: See TracBrowser for help on using the repository browser.