-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathUserServiceImpl.java
45 lines (37 loc) · 1.38 KB
/
UserServiceImpl.java
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
package com.tata.webstoreapp.services;
import com.tata.webstoreapp.models.Address;
import com.tata.webstoreapp.models.UserAccount;
import com.tata.webstoreapp.repositories.UserRepository;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserRepository userRepository;
public UserAccount addUserAccount(UserAccount userAccount){
if(userAccount.getAddressList()!=null){
for(Address address : userAccount.getAddressList()){
address.setUserAccount(userAccount);
}
}
return this.userRepository.save(userAccount);
}
public List<UserAccount> getAllUserAccounts(){
return this.userRepository.findAll();
}
public UserAccount getUserByUserId(long id){
return this.userRepository.findById(id).orElse(null);
}
public List<UserAccount> getUserByPhoneNo(long phoneNo){
return this.userRepository.findByPhoneNo(phoneNo);
}
public boolean deleteUserById(long userId){
this.userRepository.deleteById(userId);
boolean status=true;
if(getUserByUserId(userId)!=null)
status=false;
return status;
}
}