package com.project.beautycenter.web; import com.project.beautycenter.model.Beautycenter; import com.project.beautycenter.model.Users; import com.project.beautycenter.service.BeautyCenterService; import com.project.beautycenter.service.KlientiService; import com.project.beautycenter.service.UsersService; import com.project.beautycenter.service.VraboteniService; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import java.time.Instant; import java.util.List; @Controller public class RegisterController { private final UsersService usersService; private final KlientiService klientiService; private final VraboteniService vraboteniService; private final BeautyCenterService beautyCenterService; public RegisterController(UsersService usersService, KlientiService klientiService, VraboteniService vraboteniService, BeautyCenterService beautyCenterService) { this.usersService = usersService; this.klientiService = klientiService; this.vraboteniService = vraboteniService; this.beautyCenterService = beautyCenterService; } @GetMapping("/register") public String register() { return "register_form.html"; } @PostMapping("/register") public String create(@RequestParam String username, @RequestParam String name, @RequestParam String surname, @RequestParam String telbr, @RequestParam String email, @RequestParam String password) { Users users = this.usersService.create(username, password); this.klientiService.create(users, name, surname, telbr, email); return "redirect:/login"; } @GetMapping("/registerEmployee") public String registerEmpl(Model model) { List beautyCentres = this.beautyCenterService.listAll(); model.addAttribute("beautyCentres", beautyCentres); return "registerEmpl_form.html"; } @PostMapping("/registerEmployee") public String create(@RequestParam String username, @RequestParam String name, @RequestParam String middleName, @RequestParam String surname, @RequestParam String telbr, @RequestParam String email, @RequestParam String password, @RequestParam Integer rabIskustvo, @RequestParam String rabotiOd, @RequestParam String beautyCenterId) { Users users = this.usersService.create(username, password); this.vraboteniService.create(users, name, middleName, surname, telbr, email, rabIskustvo, Instant.parse(rabotiOd), beautyCenterId); return "redirect:/login"; } }