Skip to content
Snippets Groups Projects
Commit a6fbb2ed authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

allow updating apps voted

parent 11c3a9c0
No related branches found
No related tags found
No related merge requests found
......@@ -74,16 +74,35 @@ public class AppsApi {
try {
session.beginTransaction();
Vote vote = (Vote) session.createQuery("" +
"SELECT v FROM Vote v, User u, App a " +
"WHERE u=v.user " +
"AND a=v.app " +
"AND u.username= :username " +
"AND a.id= :app_id")
.setString("username", user.getUsername())
.setLong("app_id", id)
.uniqueResult();
App app = (App) session.createQuery("FROM App where id= :id").setLong("id", id).uniqueResult();
Vote vote = new Vote();
vote.setUser(user);
vote.setValue(value);
vote.setApp(app);
if (vote != null) {
vote.setValue(value);
session.save(vote);
session.getTransaction().commit();
session.update(vote);
session.getTransaction().commit();
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
else
{
vote = new Vote();
vote.setUser(user);
vote.setValue(value);
vote.setApp(app);
session.save(vote);
session.getTransaction().commit();
return new ResponseEntity<>(HttpStatus.CREATED);
}
}
catch (ConstraintViolationException cve)
{
......@@ -108,8 +127,7 @@ public class AppsApi {
session.getTransaction().rollback();
throw e;
}
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<>(HttpStatus.CREATED);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment