[7a0bf79] | 1 | package com.wediscussmovies.project.service.impl;
|
---|
| 2 |
|
---|
[3ded84d] | 3 | import com.wediscussmovies.project.model.*;
|
---|
[7fafead] | 4 | import com.wediscussmovies.project.model.enumerations.PersonType;
|
---|
[7a0bf79] | 5 | import com.wediscussmovies.project.repository.PersonRepository;
|
---|
| 6 | import com.wediscussmovies.project.service.PersonService;
|
---|
| 7 | import org.springframework.stereotype.Service;
|
---|
| 8 |
|
---|
| 9 | import java.util.List;
|
---|
| 10 | import java.util.Optional;
|
---|
| 11 |
|
---|
| 12 | @Service
|
---|
| 13 | public class PersonServiceImpl implements PersonService {
|
---|
| 14 | private final PersonRepository personRepository;
|
---|
| 15 |
|
---|
[7fafead] | 16 |
|
---|
[7a0bf79] | 17 | public PersonServiceImpl(PersonRepository personRepository) {
|
---|
| 18 | this.personRepository = personRepository;
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | @Override
|
---|
| 22 | public List<Person> findAllDirectors() {
|
---|
[3ded84d] | 23 | return personRepository.findAllByType('D');
|
---|
[7a0bf79] | 24 | }
|
---|
| 25 |
|
---|
| 26 | @Override
|
---|
| 27 | public Optional<Person> findActorById(Integer id) {
|
---|
[3ded84d] | 28 | return personRepository.findPersonByPersonIdAndType(id, 'A');
|
---|
[7a0bf79] | 29 | }
|
---|
| 30 |
|
---|
[2a5d6a3] | 31 | @Override
|
---|
| 32 | public Optional<Person> findById(Integer person_id) {
|
---|
| 33 | return personRepository.findById(person_id);
|
---|
| 34 | }
|
---|
[7a0bf79] | 35 |
|
---|
| 36 | @Override
|
---|
| 37 | public Optional<Person> findDirectorById(Integer id) {
|
---|
[3ded84d] | 38 | return personRepository.findPersonByPersonIdAndType(id, 'D');
|
---|
[7a0bf79] | 39 | }
|
---|
| 40 |
|
---|
| 41 | @Override
|
---|
| 42 | public List<Person> findAllActors() {
|
---|
[3ded84d] | 43 | return personRepository.findAllByType('A');
|
---|
[7a0bf79] | 44 | }
|
---|
[2a5d6a3] | 45 |
|
---|
| 46 | @Override
|
---|
| 47 | public boolean save(Person person) {
|
---|
| 48 | Person p = personRepository.save(person);
|
---|
| 49 | if(p != null)
|
---|
| 50 | return true;
|
---|
| 51 | return false;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | @Override
|
---|
| 55 | public List<Person> findActorsByNameLike(String name) {
|
---|
[3ded84d] | 56 | return personRepository.findAllByTypeAndNameLike('A', name);
|
---|
[2a5d6a3] | 57 | }
|
---|
| 58 |
|
---|
| 59 | @Override
|
---|
| 60 | public List<Person> findActorsBySurnameLike(String surname) {
|
---|
[3ded84d] | 61 | return personRepository.findAllByTypeAndSurnameLike('A', surname);
|
---|
[2a5d6a3] | 62 | }
|
---|
| 63 |
|
---|
| 64 | @Override
|
---|
| 65 | public List<Person> findDirectorsByNameLike(String name) {
|
---|
[3ded84d] | 66 | return personRepository.findAllByTypeAndNameLike('D', name);
|
---|
[2a5d6a3] | 67 | }
|
---|
| 68 |
|
---|
| 69 | @Override
|
---|
| 70 | public List<Person> findDirectorsBySurnameLike(String surname) {
|
---|
[3ded84d] | 71 | return personRepository.findAllByTypeAndSurnameLike('D', surname);
|
---|
[2a5d6a3] | 72 | }
|
---|
[7a0bf79] | 73 | }
|
---|