package dev.openshift.tapestry.angular.services;

import dev.openshift.tapestry.angular.data.Comment;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class CommentDAOImpl implements CommentDAO
{
    private final Session session;

    public CommentDAOImpl(Session session)
    {
        this.session = session;
    }

    public List<Comment> getCommentsByPhoneId(int phoneId) {
        return session.createCriteria(Comment.class).add(Restrictions.eq("phoneid", phoneId)).addOrder(Order.desc("id")).list();
    }

    public void add(Comment comment) {
        session.save(comment);
    }
}

@@ -85,12 +85,14 @@
 lar.
-data
+entity
 .Com
@@ -215,59 +215,8 @@
 s;%0A%0A
-import java.util.ArrayList;%0Aimport java.util.Date;%0A
 impo
@@ -461,11 +461,14 @@
 eId(
+Str
 in
-t
+g
  pho
@@ -554,17 +554,17 @@
 q(%22phone
-i
+I
 d%22, phon
@@ -686,11 +686,528 @@
 );%0A    %7D
+%0A%0A    public Comment incLike(int commentId) %7B%0A        Comment comment = (Comment) session.createCriteria(Comment.class).add(Restrictions.eq(%22id%22, commentId)).uniqueResult();%0A        comment.setLikes(comment.getLikes()+1);%0A        session.save(comment);%0A        return comment;%0A    %7D%0A%0A    public Comment delete(int commentId) %7B%0A        Comment comment = (Comment) session.createCriteria(Comment.class).add(Restrictions.eq(%22id%22, commentId)).uniqueResult();%0A        session.delete(comment);%0A        return comment;%0A    %7D
 %0A%7D%0A

change CommentDAO implementation