[850b344] | 1 | package com.project.beautycenter.web;
|
---|
| 2 |
|
---|
| 3 | import com.project.beautycenter.model.Beautycenter;
|
---|
| 4 | import com.project.beautycenter.model.Users;
|
---|
| 5 | import com.project.beautycenter.service.BeautyCenterService;
|
---|
| 6 | import com.project.beautycenter.service.KlientiService;
|
---|
| 7 | import com.project.beautycenter.service.UsersService;
|
---|
| 8 | import com.project.beautycenter.service.VraboteniService;
|
---|
| 9 | import org.springframework.stereotype.Controller;
|
---|
| 10 | import org.springframework.ui.Model;
|
---|
| 11 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
| 12 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
| 13 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
| 14 |
|
---|
| 15 | import java.time.Instant;
|
---|
| 16 | import java.util.List;
|
---|
| 17 |
|
---|
| 18 | @Controller
|
---|
| 19 | public 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 | } |
---|