Skip to content

Commit

Permalink
creating owner, user, and authority from the owner controller using
Browse files Browse the repository at this point in the history
corresponding services
  • Loading branch information
cmullercejas committed Feb 5, 2020
1 parent da81571 commit 8910433
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.model.Owner;
import org.springframework.samples.petclinic.model.User;
import org.springframework.samples.petclinic.service.AuthoritiesService;
import org.springframework.samples.petclinic.service.ClinicService;
import org.springframework.samples.petclinic.service.UserService;
import org.springframework.stereotype.Controller;
Expand All @@ -44,13 +44,14 @@ public class OwnerController {
private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";

private final ClinicService clinicService;

private final UserService userService;
private final AuthoritiesService authoritiesService;

@Autowired
public OwnerController(ClinicService clinicService, UserService userService) {
public OwnerController(ClinicService clinicService, UserService userService, AuthoritiesService authoritiesService) {
this.clinicService = clinicService;
this.userService = userService;
this.authoritiesService = authoritiesService;
}

@InitBinder
Expand All @@ -71,9 +72,13 @@ public String processCreationForm(@Valid Owner owner, BindingResult result) {
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
}
else {
//creating owner
this.clinicService.saveOwner(owner);
User user = owner.getUser();
this.userService.saveUser(user);
//creating user
this.userService.saveUser(owner.getUser());
//creating authorities
this.authoritiesService.saveAuthorities(owner.getUser().getUsername(), "owner");

return "redirect:/owners/" + owner.getId();
}
}
Expand Down

0 comments on commit 8910433

Please sign in to comment.