Last active
March 27, 2018 12:10
-
-
Save aarshtalati/789d53ba6837bad7126ed0b11692de22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.gatech.epidemics.service; | |
import edu.gatech.epidemics.dao.UserRepository; | |
import edu.gatech.epidemics.model.User; | |
import javax.transaction.Transactional; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Service; | |
import java.util.*; | |
/** | |
* @author atalati | |
*/ | |
@Service | |
public class UserService { | |
@Autowired | |
private final UserRepository userRepository; | |
public UserService(UserRepository userRepository) { | |
this.userRepository = userRepository; | |
} | |
public List<User> findAll() { | |
List<User> users = new ArrayList<User>(); | |
userRepository.findAll().forEach(users::add); | |
return users; | |
} | |
public User findById(Integer id) { | |
Optional<User> user = userRepository.findById(id); | |
if (user.isPresent()) { | |
return user.get(); | |
} else { | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment