Skip to content

Commit

Permalink
Created Spring Data JPA Service for PetType. closes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
Priyanshu-git committed May 31, 2021
1 parent 3e92057 commit 1e235cd
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package spring.framework.petclinic.services.springdatajpa;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;
import spring.framework.petclinic.model.PetType;
import spring.framework.petclinic.repositories.PetTypeRepository;
import spring.framework.petclinic.services.PetTypeService;

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

@Service
@Profile("springdatajpa")
public class PetTypeSDJpaService implements PetTypeService {

private final PetTypeRepository petTypeRepository;

public PetTypeSDJpaService(PetTypeRepository petTypeRepository) {
this.petTypeRepository = petTypeRepository;
}

@Override
public Set<PetType> findAll() {
Set<PetType> petTypes = new HashSet<>();
petTypeRepository.findAll().forEach(petTypes::add);
return petTypes;
}

@Override
public PetType findById(Long aLong) {
return petTypeRepository.findById(aLong).orElse(null);
}

@Override
public PetType save(PetType object) {
return petTypeRepository.save(object);
}

@Override
public void delete(PetType object) {
petTypeRepository.delete(object);
}

@Override
public void deleteById(Long aLong) {
petTypeRepository.deleteById(aLong);
}
}

0 comments on commit 1e235cd

Please sign in to comment.