22301102 | e0c7c6e | 2025-05-17 11:08:45 +0800 | [diff] [blame] | 1 | package com.pt.service; |
| 2 | |
| 3 | import com.pt.entity.User; |
| 4 | import com.pt.repository.UserRepository; |
| 5 | import org.springframework.beans.factory.annotation.Autowired; |
| 6 | import org.springframework.stereotype.Service; |
| 7 | |
22301102 | aa5adbc | 2025-05-18 17:51:55 +0800 | [diff] [blame] | 8 | import java.util.List; |
| 9 | |
22301102 | e0c7c6e | 2025-05-17 11:08:45 +0800 | [diff] [blame] | 10 | @Service |
| 11 | public class UserService { |
| 12 | |
| 13 | @Autowired |
| 14 | private UserRepository userRepository; |
| 15 | |
| 16 | public UserService(UserRepository userRepository) { |
| 17 | this.userRepository = userRepository; |
| 18 | } |
| 19 | |
| 20 | public User findByUsername(String username) { |
| 21 | return userRepository.findByUsername(username); |
| 22 | } |
| 23 | |
| 24 | public User findByEmail(String email) { |
| 25 | return userRepository.findByEmail(email); |
| 26 | } |
| 27 | |
| 28 | public User findByUsernameAndPassword(String username, String password) { |
| 29 | return userRepository.findByUsernameAndPassword(username, password); |
| 30 | } |
| 31 | |
| 32 | public User findByEmailAndPassword(String email, String password) { |
| 33 | return userRepository.findByEmailAndPassword(email, password); |
| 34 | } |
| 35 | |
| 36 | public User save(User user) { |
| 37 | return userRepository.save(user); |
| 38 | } |
| 39 | |
| 40 | public User findById(String uid) { |
| 41 | return userRepository.findById(uid).orElse(null); |
| 42 | } |
| 43 | |
| 44 | public void deleteById(String uid) { |
| 45 | userRepository.deleteById(uid); |
| 46 | } |
22301102 | aa5adbc | 2025-05-18 17:51:55 +0800 | [diff] [blame] | 47 | |
| 48 | public List<User> listAll() { |
| 49 | return userRepository.findAll(); |
| 50 | } |
22301102 | e0c7c6e | 2025-05-17 11:08:45 +0800 | [diff] [blame] | 51 | } |