mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Delete from playlist_videos table on user deletion
This commit is contained in:
parent
c56cb6eec5
commit
4fc05674f3
1 changed files with 23 additions and 9 deletions
|
@ -642,15 +642,29 @@ public class ResponseHelper {
|
|||
return Constants.mapper.writeValueAsBytes(new IncorrectCredentialsResponse());
|
||||
|
||||
try {
|
||||
CriteriaBuilder plCriteria = s.getCriteriaBuilder();
|
||||
CriteriaQuery<me.kavin.piped.utils.obj.db.Playlist> plQuery =
|
||||
plCriteria.createQuery(me.kavin.piped.utils.obj.db.Playlist.class);
|
||||
Root<me.kavin.piped.utils.obj.db.Playlist> plRoot =
|
||||
plQuery.from(me.kavin.piped.utils.obj.db.Playlist.class);
|
||||
plQuery.select(plRoot).where(plCriteria.equal(plRoot.get("owner"), user.getId()));
|
||||
List<me.kavin.piped.utils.obj.db.Playlist> playlists = s.createQuery(plQuery).getResultList();
|
||||
|
||||
for (me.kavin.piped.utils.obj.db.Playlist pl : playlists) {
|
||||
Iterator<PlaylistVideo> pvIter = pl.getVideos().iterator();
|
||||
|
||||
while (pvIter.hasNext())
|
||||
s.delete(pvIter.next());
|
||||
}
|
||||
|
||||
Iterator<me.kavin.piped.utils.obj.db.Playlist> iter = playlists.iterator();
|
||||
|
||||
while (iter.hasNext())
|
||||
s.delete(iter.next());
|
||||
|
||||
s.delete(user);
|
||||
|
||||
s.getTransaction().begin();
|
||||
|
||||
s.createNativeQuery("delete from users_subscribed where subscriber = :id")
|
||||
.setParameter("id", user.getId()).executeUpdate();
|
||||
s.createNativeQuery("delete from playlists where owner = :ownerId")
|
||||
.setParameter("ownerId", user.getId()).executeUpdate();
|
||||
s.createNativeQuery("delete from users where id = :id")
|
||||
.setParameter("id", user.getId()).executeUpdate();
|
||||
|
||||
s.getTransaction().commit();
|
||||
|
||||
return Constants.mapper.writeValueAsBytes(new DeleteUserResponse(user.getUsername()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue