-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathPersonService.java
More file actions
33 lines (25 loc) · 1.01 KB
/
PersonService.java
File metadata and controls
33 lines (25 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package io.zipcoder.crudapp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class PersonService {
@Autowired
private PersonRepository repository;
public PersonService(PersonRepository repository){this.repository = repository;}
public Iterable<Person> showAll() {
return repository.findAll();}
public Person show(Long id){
return repository.findOne(id);} //todo something to do with get method
public Person create(Person person) {
return repository.save(person);}
public Person update(Long id, Person newPersonData) {
Person originalPerson = repository.findOne(id); //todo something to do with get method
originalPerson.setFirstName(newPersonData.getFirstName());
originalPerson.setLastName(newPersonData.getLastName());
return repository.save(originalPerson);
}
public Boolean delete(Long id) {
repository.delete(id);
return true;
}
}