https://stackoverflow.com/questions/24228279/proper-usage-of-optional-ifpresent
검색을 많이 해봤는데, 그냥 java ifPresent쳤을 때 가장 상위권에 나오는 Stackoverflow글이 가장 좋았다.
userRepository.findByEmail(userApiRequest.getEmail()).ifPresent(new Consumer<User>() {
@Override
public void accept(User user) {
throw new DuplicateException(ErrorCode.USER_DOES_NOT_EXIST);
}
});
userRepository.findByEmail(userApiRequest.getEmail()).ifPresent((user)->{throw new DuplicateException(ErrorCode.USER_DOES_NOT_EXIST);});
{} 안에 ;를 붙여줘야 되는것과, throw를 날려주는 것이 포인트였다.
userRepository.findByEmail(userApiRequest.getEmail()).ifPresent(()-> new DuplicateException(ErrorCode.USER_DOES_NOT_EXIST));
userRepository.findByEmail(userApiRequest.getEmail()).ifPresent(user->{throw new DuplicateException(ErrorCode.USER_DOES_NOT_EXIST);});
findArtist.getPostList().forEach(artistPost->{
postList.add(artistPost);
});
findArtist.getPostList().forEach(postList::add);
postList.addAll(findArtist.getPostList());