mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Avoid raw SQL in unsubscribeResponse()
This commit is contained in:
parent
4fc05674f3
commit
b38c641b5f
1 changed files with 8 additions and 4 deletions
|
@ -794,10 +794,14 @@ public class ResponseHelper {
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
try (Session s = DatabaseSessionFactory.createSession()) {
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
s.getTransaction().begin();
|
if (user.getSubscribed().contains(channelId)) {
|
||||||
s.createNativeQuery("delete from users_subscribed where subscriber = :id and channel = :channel")
|
|
||||||
.setParameter("id", user.getId()).setParameter("channel", channelId).executeUpdate();
|
user.getSubscribed().removeIf(sub -> sub.equals(channelId));
|
||||||
s.getTransaction().commit();
|
s.update(user);
|
||||||
|
s.getTransaction().begin();
|
||||||
|
s.getTransaction().commit();
|
||||||
|
}
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(new AcceptedResponse());
|
return Constants.mapper.writeValueAsBytes(new AcceptedResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue