-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClientServiceImpl.java
More file actions
46 lines (36 loc) · 1.03 KB
/
ClientServiceImpl.java
File metadata and controls
46 lines (36 loc) · 1.03 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
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.ffong.demo.client.service;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ffong.demo.client.model.Client;
import com.ffong.demo.client.repository.ClientRepository;
@Service
public class ClientServiceImpl implements ClientService {
@Autowired
private ClientRepository clientRepository;
@Override
public List<Client> list() {
List<Client> clients = new ArrayList<Client>();
clients = clientRepository.findAll();
return clients;
}
@Override
public Client insert(Client client) {
return clientRepository.save(client);
}
@Override
public Client update(Long idClient, Client client) {
Optional<Client> clientFind = clientRepository.findById(idClient);
if (clientFind.isPresent()) {
client.setId(idClient);
return clientRepository.save(client);
}
return null;
}
@Override
public void delete(Long idClient) {
clientRepository.deleteById(idClient);
}
}