// Path: src/main/java/com/yyqian/imagine/exception/BadRequestException.java
// public class BadRequestException extends RuntimeException {
//   public BadRequestException() {
//   }
// 
//   public BadRequestException(String message) {
//     super(message);
//   }
// 
//   public BadRequestException(String message, Throwable cause) {
//     super(message, cause);
//   }
// 
//   public BadRequestException(Throwable cause) {
//     super(cause);
//   }
// 
//   public BadRequestException(String message, Throwable cause, boolean enableSuppression,
//                              boolean writableStackTrace) {
//     super(message, cause, enableSuppression, writableStackTrace);
//   }
// }
// 
// Path: src/main/java/com/yyqian/imagine/exception/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//   public NotFoundException() {
//   }
// 
//   public NotFoundException(String message) {
//     super(message);
//   }
// 
//   public NotFoundException(String message, Throwable cause) {
//     super(message, cause);
//   }
// 
//   public NotFoundException(Throwable cause) {
//     super(cause);
//   }
// 
//   public NotFoundException(String message, Throwable cause, boolean enableSuppression,
//                            boolean writableStackTrace) {
//     super(message, cause, enableSuppression, writableStackTrace);
//   }
// }
// 
// Path: src/main/java/com/yyqian/imagine/repository/CommentVoteRepository.java
// @Repository
// public interface CommentVoteRepository extends JpaRepository<CommentVote, CommentVotePK> {
//   Optional<CommentVote> findOneByUserAndComment(User user, Comment comment);
//   Collection<Comment> findCommentsVotedByUser(User user);
// }
// 
// Path: src/main/java/com/yyqian/imagine/repository/PostVoteRepository.java
// @Repository
// public interface PostVoteRepository extends JpaRepository<PostVote, PostVotePK> {
//   Optional<PostVote> findOneByUserAndPost(User user, Post post);
//   Collection<Post> findPostsVotedByUser(User user);
// }


import com.yyqian.imagine.exception.BadRequestException;
import com.yyqian.imagine.exception.NotFoundException;
import com.yyqian.imagine.po.*;
import com.yyqian.imagine.repository.CommentVoteRepository;
import com.yyqian.imagine.repository.PostVoteRepository;
import com.yyqian.imagine.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.Collection;
import java.util.NoSuchElementException;
package com.yyqian.imagine.service.impl;



/**
 * Created on 12/15/15.
 *
 * @author Yinyin Qian
 */
@Service
public class VoteServiceImpl implements VoteService {

  @Autowired
  private PostService postService;
  @Autowired
  private CommentService commentService;
  @Autowired
  private PostVoteRepository postVoteRepository;
  @Autowired
  private CommentVoteRepository commentVoteRepository;
  @Autowired
  private SecurityService securityService;
  @Autowired
  private UserService userService;

  @Transactional
  @Override
  public PostVote createPostVote(PostVote postVote) {
    Post post = postService.getPostById(postVote.getPost().getId()).orElseThrow(
// Path: src/main/java/com/yyqian/imagine/exception/BadRequestException.java
// public class BadRequestException extends RuntimeException {
//   public BadRequestException() {
//   }
// 
//   public BadRequestException(String message) {
//     super(message);
//   }
// 
//   public BadRequestException(String message, Throwable cause) {
//     super(message, cause);
//   }
// 
//   public BadRequestException(Throwable cause) {
//     super(cause);
//   }
// 
//   public BadRequestException(String message, Throwable cause, boolean enableSuppression,
//                              boolean writableStackTrace) {
//     super(message, cause, enableSuppression, writableStackTrace);
//   }
// }
// 
// Path: src/main/java/com/yyqian/imagine/exception/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//   public NotFoundException() {
//   }
// 
//   public NotFoundException(String message) {
//     super(message);
//   }
// 
//   public NotFoundException(String message, Throwable cause) {
//     super(message, cause);
//   }
// 
//   public NotFoundException(Throwable cause) {
//     super(cause);
//   }
// 
//   public NotFoundException(String message, Throwable cause, boolean enableSuppression,
//                            boolean writableStackTrace) {
//     super(message, cause, enableSuppression, writableStackTrace);
//   }
// }
// 
// Path: src/main/java/com/yyqian/imagine/repository/CommentVoteRepository.java
// @Repository
// public interface CommentVoteRepository extends JpaRepository<CommentVote, CommentVotePK> {
//   Optional<CommentVote> findOneByUserAndComment(User user, Comment comment);
//   Collection<Comment> findCommentsVotedByUser(User user);
// }
// 
// Path: src/main/java/com/yyqian/imagine/repository/PostVoteRepository.java
// @Repository
// public interface PostVoteRepository extends JpaRepository<PostVote, PostVotePK> {
//   Optional<PostVote> findOneByUserAndPost(User user, Post post);
//   Collection<Post> findPostsVotedByUser(User user);
// }


// Path: src/main/java/com/yyqian/imagine/service/impl/VoteServiceImpl.java
import com.yyqian.imagine.exception.BadRequestException;
import com.yyqian.imagine.exception.NotFoundException;
import com.yyqian.imagine.po.*;
import com.yyqian.imagine.repository.CommentVoteRepository;
import com.yyqian.imagine.repository.PostVoteRepository;
import com.yyqian.imagine.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.Collection;
import java.util.NoSuchElementException;

package com.yyqian.imagine.service.impl;



/**
 * Created on 12/15/15.
 *
 * @author Yinyin Qian
 */
@Service
public class VoteServiceImpl implements VoteService {

  @Autowired
  private PostService postService;
  @Autowired
  private CommentService commentService;
  @Autowired
  private PostVoteRepository postVoteRepository;
  @Autowired
  private CommentVoteRepository commentVoteRepository;
  @Autowired
  private SecurityService securityService;
  @Autowired
  private UserService userService;

  @Transactional
  @Override
  public PostVote createPostVote(PostVote postVote) {
    Post post = postService.getPostById(postVote.getPost().getId()).orElseThrow(
        () -> new NotFoundException("Cannot find the post."));