Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for Find Owner functionality #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface OwnerRepository extends CrudRepository<Owner, Long> {

Owner findByLastName(String lastName);

List<Owner> findAllByLastNameLike(String lastName);
List<Owner> findAllByLastNameLikeIgnoreCase(String lastName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
* Created by jt on 7/21/18.
Expand Down Expand Up @@ -85,8 +86,9 @@ public Owner findByLastName(String lastName) {

@Override
public List<Owner> findAllByLastNameLike(String lastName) {

//todo - impl
return null;
return this.findAll()
.stream()
.filter(owner -> owner.getLastName().toLowerCase().contains(lastName.toLowerCase()))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import guru.springframework.sfgpetclinic.model.Owner;
import guru.springframework.sfgpetclinic.repositories.OwnerRepository;
import guru.springframework.sfgpetclinic.repositories.PetRepository;
import guru.springframework.sfgpetclinic.repositories.PetTypeRepository;
import guru.springframework.sfgpetclinic.services.OwnerService;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

/**
* Created by jt on 8/5/18.
*/
Expand All @@ -20,14 +19,9 @@
public class OwnerSDJpaService implements OwnerService {

private final OwnerRepository ownerRepository;
private final PetRepository petRepository;
private final PetTypeRepository petTypeRepository;

public OwnerSDJpaService(OwnerRepository ownerRepository, PetRepository petRepository,
PetTypeRepository petTypeRepository) {
public OwnerSDJpaService(OwnerRepository ownerRepository) {
this.ownerRepository = ownerRepository;
this.petRepository = petRepository;
this.petTypeRepository = petTypeRepository;
}

@Override
Expand All @@ -37,7 +31,7 @@ public Owner findByLastName(String lastName) {

@Override
public List<Owner> findAllByLastNameLike(String lastName) {
return ownerRepository.findAllByLastNameLike(lastName);
return ownerRepository.findAllByLastNameLikeIgnoreCase("%" + lastName + "%");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void setAllowedFields(WebDataBinder dataBinder) {
}


@RequestMapping("/find")
@GetMapping("/find")
public String findOwners(Model model){
model.addAttribute("owner", Owner.builder().build());
return "owners/findOwners";
Expand All @@ -46,7 +46,7 @@ public String processFindForm(Owner owner, BindingResult result, Model model){
}

// find owners by last name
List<Owner> results = ownerService.findAllByLastNameLike("%"+ owner.getLastName() + "%");
List<Owner> results = ownerService.findAllByLastNameLike(owner.getLastName());

if (results.isEmpty()) {
// no owners found
Expand Down