use of org.springframework.samples.petclinic.visit.Visit in project spring-petclinic by spring-projects.
the class Pet method getVisits.
public List<Visit> getVisits() {
List<Visit> sortedVisits = new ArrayList<>(getVisitsInternal());
PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false));
return Collections.unmodifiableList(sortedVisits);
}
use of org.springframework.samples.petclinic.visit.Visit in project spring-petclinic by spring-projects.
the class ClinicServiceTests method shouldAddNewVisitForPet.
@Test
@Transactional
public void shouldAddNewVisitForPet() {
Pet pet7 = this.pets.findById(7);
int found = pet7.getVisits().size();
Visit visit = new Visit();
pet7.addVisit(visit);
visit.setDescription("test");
this.visits.save(visit);
this.pets.save(pet7);
pet7 = this.pets.findById(7);
assertThat(pet7.getVisits().size()).isEqualTo(found + 1);
assertThat(visit.getId()).isNotNull();
}
use of org.springframework.samples.petclinic.visit.Visit in project spring-petclinic by spring-projects.
the class VisitController method loadPetWithVisit.
/**
* Called before each and every @RequestMapping annotated method.
* 2 goals:
* - Make sure we always have fresh data
* - Since we do not use the session scope, make sure that Pet object always has an id
* (Even though id is not part of the form fields)
*
* @param petId
* @return Pet
*/
@ModelAttribute("visit")
public Visit loadPetWithVisit(@PathVariable("petId") int petId, Map<String, Object> model) {
Pet pet = this.pets.findById(petId);
model.put("pet", pet);
Visit visit = new Visit();
pet.addVisit(visit);
return visit;
}
Aggregations