Skip to content

Commit

Permalink
Move Visit to owner package (it's aggregate root)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyer committed Jan 5, 2022
1 parent 58fe629 commit 423a337
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.samples.petclinic.model.NamedEntity;
import org.springframework.samples.petclinic.visit.Visit;

/**
* Simple business object representing a pet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.samples.petclinic.visit;
package org.springframework.samples.petclinic.owner;

import java.time.LocalDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import javax.validation.Valid;

import org.springframework.samples.petclinic.visit.Visit;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
Expand Down Expand Up @@ -63,6 +62,7 @@ public Visit loadPetWithVisit(@PathVariable("ownerId") int ownerId, @PathVariabl
Owner owner = this.owners.findById(ownerId);
Pet pet = owner.getPet(petId);
model.put("pet", pet);
model.put("owner", owner);
Visit visit = new Visit();
pet.addVisit(visit);
return visit;
Expand All @@ -78,12 +78,11 @@ public String initNewVisitForm(@PathVariable("petId") int petId, Map<String, Obj
// Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is
// called
@PostMapping("/owners/{ownerId}/pets/{petId}/visits/new")
public String processNewVisitForm(@PathVariable("ownerId") int ownerId, @Valid Visit visit, BindingResult result) {
public String processNewVisitForm(@ModelAttribute Owner owner, @Valid Visit visit, BindingResult result) {
if (result.hasErrors()) {
return "pets/createOrUpdateVisitForm";
}
else {
Owner owner = this.owners.findById(ownerId);
owner.getPet(visit.getPetId()).addVisit(visit);
this.owners.save(owner);
return "redirect:/owners/{ownerId}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.samples.petclinic.visit.Visit;
import org.springframework.test.web.servlet.MockMvc;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import org.springframework.samples.petclinic.owner.OwnerRepository;
import org.springframework.samples.petclinic.owner.Pet;
import org.springframework.samples.petclinic.owner.PetType;
import org.springframework.samples.petclinic.owner.Visit;
import org.springframework.samples.petclinic.vet.Vet;
import org.springframework.samples.petclinic.vet.VetRepository;
import org.springframework.samples.petclinic.visit.Visit;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down

0 comments on commit 423a337

Please sign in to comment.