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