feat: PersonRepository, PersonService
This commit is contained in:
parent
9212750021
commit
bc99e561b5
2 changed files with 53 additions and 0 deletions
|
@ -0,0 +1,8 @@
|
||||||
|
package com.application.munera.repositories;
|
||||||
|
|
||||||
|
import com.application.munera.data.Person;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
|
public interface PersonRepository extends JpaRepository<Person, Long>, JpaSpecificationExecutor<Person> {
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.application.munera.services;
|
||||||
|
|
||||||
|
import com.application.munera.data.Person;
|
||||||
|
import com.application.munera.repositories.PersonRepository;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PersonService {
|
||||||
|
|
||||||
|
private final PersonRepository personRepository;
|
||||||
|
|
||||||
|
public PersonService(PersonRepository personRepository) {
|
||||||
|
this.personRepository = personRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Person> get(Long id) {
|
||||||
|
return personRepository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Person> findAll() {
|
||||||
|
return this.personRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Person update(Person person) {
|
||||||
|
return this.personRepository.save(person);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(Long id) {
|
||||||
|
this.personRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<Person> list(Pageable pageable, Specification<Person> filter) {
|
||||||
|
return this.personRepository.findAll(filter, pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int count() {
|
||||||
|
return (int) this.personRepository.count();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue