Avoid raw SQL in unsubscribeResponse()

This commit is contained in:
theanonymousexyz 2022-04-23 00:06:50 +02:00
parent 4fc05674f3
commit b38c641b5f
No known key found for this signature in database
GPG key ID: 35EE09F5481049BB

View file

@ -794,10 +794,14 @@ public class ResponseHelper {
if (user != null) {
try (Session s = DatabaseSessionFactory.createSession()) {
s.getTransaction().begin();
s.createNativeQuery("delete from users_subscribed where subscriber = :id and channel = :channel")
.setParameter("id", user.getId()).setParameter("channel", channelId).executeUpdate();
s.getTransaction().commit();
if (user.getSubscribed().contains(channelId)) {
user.getSubscribed().removeIf(sub -> sub.equals(channelId));
s.update(user);
s.getTransaction().begin();
s.getTransaction().commit();
}
return Constants.mapper.writeValueAsBytes(new AcceptedResponse());
}