Не могу получить количество лайков или голосов
Я написал код для кнопок (нравится и не нравится), где я включил значки для отображения количества симпатий и антипатий. И при получении счетчика это изменяется для всех кнопок, так как я использовал ng-repeat, чтобы повторить каждый вопрос и отобразить подобное и неприязнь
HTML-код
<button class="btn btn-default" id="{{$index}}"
ng-click='tagForm.like(key)' ng-init="'tagForm.like(key)'">
Upvote <span class="badge">{{tagForm.liked}}</span>
</button>
<button class="btn btn-default" id="{{$index}}"
ng-click='tagForm.dislike(key)' ng-init="tagForm.dislike(key)">
Downvote<span class="badge">{{tagForm.disliked}}</span>
</button>
Контроллер илит
$scope.tagForm.like=function(val){
$scope.tagForm.liked = 0;
var data = JSON.stringify($scope.tagForm);
$http.get(URI + "tag/like/"+val,data).then(function(response) {
$scope.tagForm.liked =response.data.upvotes;
}, function(response) {
$scope.tagForm.message = null;
});
};
$scope.tagForm.dislike=function(val){
$scope.tagForm.disliked = 0;
var data = JSON.stringify($scope.tagForm);
$http.get(URI + "tag/dislike/"+val,data).then(function(response) {
$scope.tagForm.disliked =response.data.downvotes;
}, function(response) {
$scope.tagForm.message = null;
});
};
Дао класс
public Integer upvote(Integer questionId) throws Exception {
SessionFactory sessionFactory = null;
Session session = null;
Integer updatedUpvote = null;
try {
sessionFactory = HibernateUtility.createSessionFactory();
session = sessionFactory.openSession();
System.out.println("key in like dao" + questionId);
QuestionEntity qe = (QuestionEntity) session.get(
QuestionEntity.class, questionId);
if (qe != null) {
// session.getTransaction().begin();
updatedUpvote = qe.getUpvotes() + 1;
System.out.println(updatedUpvote);
qe.setUpvotes(updatedUpvote);
System.out.println(qe.getUpvotes() + "entity");
session.saveOrUpdate(qe);
// session.getTransaction().commit();
}
}
tablescript
CREATE TABLE Question(
questionId INTEGER,
userId varchar2(40) NOT NULL,
upvotes INTEGER NOT NULL,
downvotes INTEGER NOT NULL,
questionString VARCHAR2(400) NOT NULL,
tagId varchar2(400) NOT NULL,
CONSTRAINT pk_question_quesId PRIMARY KEY(questionId,tagId)
);