コード例 #1
0
  public QuestionUI create(QuestionUI uiBean, Principal principal) {
    Question newQ = qMapper.toPersistenceBean(uiBean);

    User user = userRepo.findByUserName(principal.getName());
    if (user != null) {
      newQ.setCreatedBy(user);
    }
    newQ.setCreatedDate(Calendar.getInstance().getTime());

    newQ = qaRepo.save(newQ);
    addTags(newQ);

    logger.debug(newQ);
    return qMapper.toUIBean(newQ);
  }
コード例 #2
0
  public QuestionUI addQuestionComment(CommentUI comment, Principal principal) {
    QuestionUI result = new QuestionUI();
    Comment newComment = cMapper.toPersistenceBean(comment);
    newComment.setId(UUID.randomUUID().toString());
    newComment.setCreatedDate(Calendar.getInstance().getTime());
    User user = userRepo.findByUserName(principal.getName());
    if (user != null) {
      newComment.setCreatedBy(user);
    }

    Query q = new Query(Criteria.where("id").is(comment.getQuestionId()));
    Update updateQ = new Update().set("comments." + newComment.getId(), newComment);
    template.updateFirst(q, updateQ, Question.class);

    result = qMapper.toUIBean(template.findOne(q, Question.class));
    return result;
  }
コード例 #3
0
  public QuestionUI addVote(String questionId, Principal principal) {
    QuestionUI result = new QuestionUI();
    User user = userRepo.findByUserName(principal.getName());

    Query q = new Query(Criteria.where("id").is(questionId));
    if (user != null) {
      Vote vote = new Vote();
      vote.setId(user.getId());
      vote.setUser(user.getUserName());
      vote.setCreatedDate(Calendar.getInstance().getTime());

      Update updateQ = new Update().set("votes." + user.getId(), vote);
      template.updateFirst(q, updateQ, Question.class);
    }

    result = qMapper.toUIBean(template.findOne(q, Question.class));
    return result;
  }
コード例 #4
0
  public QuestionUI addBookmark(String questionId, Principal principal) {
    QuestionUI result = new QuestionUI();
    User user = userRepo.findByUserName(principal.getName());

    Query q = new Query(Criteria.where("id").is(questionId));
    if (user != null) {
      Bookmark bookmark = new Bookmark();
      bookmark.setId(user.getId());
      bookmark.setUser(user.getUserName());
      bookmark.setQuestionId(questionId);
      bookmark.setCreatedDate(Calendar.getInstance().getTime());

      template.updateFirst(
          new Query(Criteria.where("id").is(user.getId())),
          new Update().set("bookmarks." + questionId, bookmark),
          User.class);

      Update updateQ = new Update().set("bookmarks." + user.getId(), bookmark);
      template.updateFirst(q, updateQ, Question.class);
    }

    result = qMapper.toUIBean(template.findOne(q, Question.class));
    return result;
  }
コード例 #5
0
  public QuestionUI update(QuestionUI question) {
    Question existing = qaRepo.findBySubject(question.getSubject());

    return qMapper.toUIBean(qaRepo.save(existing));
  }
コード例 #6
0
  public QuestionUI findById(String id, Principal principal) {
    template.updateFirst(
        new Query(Criteria.where("id").is(id)), new Update().inc("viewCount", 1), Question.class);

    return qMapper.toUIBean(qaRepo.findById(id));
  }
コード例 #7
0
  public List<QuestionUI> findById(List<String> id) {
    List<Question> questions = new ArrayList<Question>();
    questions = template.find(new Query(Criteria.where("id").in(id)), Question.class);

    return qMapper.toUIBean(questions);
  }
コード例 #8
0
 public QuestionUI findById(String id) {
   return qMapper.toUIBean(qaRepo.findById(id));
 }
コード例 #9
0
 public QuestionUI findBySubject(String subject) {
   return qMapper.toUIBean(qaRepo.findBySubject(subject));
 }
コード例 #10
0
 public Page<QuestionUI> findAll(Pageable pageable) {
   return qMapper.toUIBean(qaRepo.findAll(pageable), pageable);
 }
コード例 #11
0
 public List<QuestionUI> findAll() {
   return qMapper.toUIBean(qaRepo.findAll());
 }