Advertisement
Guest User

controller

a guest
Jan 22nd, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. package michal.przychodnia.pacjent;
  2.  
  3. import java.util.Locale;
  4. import java.util.UUID;
  5.  
  6. import javax.ws.rs.GET;
  7. import javax.ws.rs.POST;
  8.  
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.context.MessageSource;
  11. import org.springframework.stereotype.Controller;
  12. import org.springframework.ui.Model;
  13. import org.springframework.validation.BindingResult;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15.  
  16. import michal.przychodnia.validators.PacjentRegisterValidator;
  17.  
  18.  
  19. @Controller
  20. public class PacjentRegisterController {
  21.  
  22. @Autowired
  23. PacjentRepository pacjentRepository;
  24.  
  25. @Autowired
  26. MessageSource messageSource;
  27.  
  28. @Autowired
  29. PacjentService pacjentService;
  30.  
  31. @GET
  32. @RequestMapping(value="/pacjent/regpacjent")
  33. public String pacjentRegisterForm(Model model) {
  34. Pacjent p=new Pacjent();
  35. model.addAttribute("pacjent",p);
  36. return "pacjent/regpacjent";
  37. }
  38.  
  39. @POST
  40. @RequestMapping(value="/pacjent/addpacjent")
  41. public String pacjentRegisterAction(Pacjent pacjent, BindingResult result, Model model, Locale locale) {
  42. String returnPage=null;
  43.  
  44. Pacjent pacjentExist=pacjentRepository.findPacjentByPesel(pacjent.getPesel());
  45.  
  46. new PacjentRegisterValidator().validate(pacjent, result);
  47.  
  48. new PacjentRegisterValidator().validatePeselExist(pacjentExist, result);
  49.  
  50. if(result.hasErrors()) {
  51. returnPage="pacjent/regpacjent";
  52. }else {
  53. String uniqueID= UUID.randomUUID().toString();
  54. pacjent.setKod(uniqueID);
  55. pacjentService.savePacjent(pacjent);
  56. model.addAttribute("message",messageSource.getMessage("user.register.success",null, locale));
  57. model.addAttribute("pacjent",new Pacjent());
  58. returnPage = "pacjent/regpacjent";
  59. }
  60. return returnPage;
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement