-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathuserService.java
More file actions
46 lines (36 loc) · 1.2 KB
/
userService.java
File metadata and controls
46 lines (36 loc) · 1.2 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.jtspringproject.JtSpringProject.services;
import com.jtspringproject.JtSpringProject.models.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import com.jtspringproject.JtSpringProject.dao.userDao;
import com.jtspringproject.JtSpringProject.models.User;
@Service
public class userService {
@Autowired
private userDao userDao;
public List<User> getUsers(){
return this.userDao.getAllUser();
}
public User addUser(User user) {
try {
return this.userDao.saveUser(user);
} catch (DataIntegrityViolationException e) {
// handle unique constraint violation, e.g., by throwing a custom exception
throw new RuntimeException("Add user error");
}
}
public User checkLogin(String username,String password) {
return this.userDao.getUser(username, password);
}
public boolean checkUserExists(String username) {
return this.userDao.userExists(username);
}
public User getUserByUsername(String username) {
return userDao.getUserByUsername(username);
}
public void deleteUser(int id) {
userDao.deleteUser(id);
}
}