Search in sources :

Example 1 with Visit

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);
}
Also used : MutableSortDefinition(org.springframework.beans.support.MutableSortDefinition) Visit(org.springframework.samples.petclinic.visit.Visit) ArrayList(java.util.ArrayList)

Example 2 with Visit

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();
}
Also used : Visit(org.springframework.samples.petclinic.visit.Visit) Pet(org.springframework.samples.petclinic.owner.Pet) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Visit

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;
}
Also used : Visit(org.springframework.samples.petclinic.visit.Visit) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Aggregations

Visit (org.springframework.samples.petclinic.visit.Visit)3 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 MutableSortDefinition (org.springframework.beans.support.MutableSortDefinition)1 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)1 Pet (org.springframework.samples.petclinic.owner.Pet)1 Transactional (org.springframework.transaction.annotation.Transactional)1 ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)1