Skip to content

Instantly share code, notes, and snippets.

@kaansonmezoz
Created March 25, 2020 21:36
Show Gist options
  • Save kaansonmezoz/cb3bc703e6303a792be9ad1cb5c490d3 to your computer and use it in GitHub Desktop.
Save kaansonmezoz/cb3bc703e6303a792be9ad1cb5c490d3 to your computer and use it in GitHub Desktop.
public List<Trip> getTripsByUser(User user) throws UserNotLoggedInException {
User loggedUser = UserSession.getInstance().getLoggedUser();
if(loggedUser == null){
throw new UserNotLoggedInException();
}
List<Trip> tripList = new ArrayList<Trip>();
boolean isFriend = isFriendOf(user, loggedUser);
if (isFriend) {
tripList = TripDAO.findTripsByUser(user);
}
return tripList;
}
private boolean isFriendOf(User user, User loggedUser){
return user.getFriends().contains(loggedUser);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment