From 8ac47b0fdfa5394f9695c3364be9335c2f3a7265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=91=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D1=81=D0=BA=D0=B0=D1=8F?= Date: Fri, 21 Jun 2024 01:37:26 +0400 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B5?= =?UTF-8?q?=D1=89=D0=B5=20=D0=B8=20=D1=83=D0=B4=D0=B0=D0=BB=D1=8F=D0=B5?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D0=B2=D1=81=D0=B5=20=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D1=82=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../favorites/repository/FavoriteRepository.java | 2 ++ .../example/backend/users/service/UserService.java | 14 ++++++++++++-- .../viewed/repository/ViewedRepository.java | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/example/backend/favorites/repository/FavoriteRepository.java b/backend/src/main/java/com/example/backend/favorites/repository/FavoriteRepository.java index 897c8c9..667dfea 100644 --- a/backend/src/main/java/com/example/backend/favorites/repository/FavoriteRepository.java +++ b/backend/src/main/java/com/example/backend/favorites/repository/FavoriteRepository.java @@ -16,4 +16,6 @@ public interface FavoriteRepository extends CrudRepository deleteByMovieId(Integer movieId); + Optional deleteByUserId(Integer user); + } diff --git a/backend/src/main/java/com/example/backend/users/service/UserService.java b/backend/src/main/java/com/example/backend/users/service/UserService.java index 900e891..f21be34 100644 --- a/backend/src/main/java/com/example/backend/users/service/UserService.java +++ b/backend/src/main/java/com/example/backend/users/service/UserService.java @@ -8,7 +8,6 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.security.core.Authentication; import org.springframework.stereotype.Service; import org.springframework.data.domain.Page; import org.springframework.data.domain.Sort; @@ -21,19 +20,27 @@ import java.util.stream.StreamSupport; import com.example.backend.core.configurations.Constants; import com.example.backend.core.errors.NotFoundException; import com.example.backend.core.security.UserPrincipal; +import com.example.backend.favorites.repository.FavoriteRepository; import com.example.backend.users.model.UserEntity; import com.example.backend.users.model.UserRole; import com.example.backend.users.repository.UserRepository; +import com.example.backend.viewed.repository.ViewedRepository; @Service public class UserService implements UserDetailsService { private final UserRepository repository; private final PasswordEncoder passwordEncoder; + private final FavoriteRepository favoriteRepository; + private final ViewedRepository viewedRepository; - public UserService(UserRepository repository, PasswordEncoder passwordEncoder) { + public UserService(UserRepository repository, PasswordEncoder passwordEncoder, + FavoriteRepository favoriteRepository, + ViewedRepository viewedRepository) { this.repository = repository; this.passwordEncoder = passwordEncoder; + this.favoriteRepository = favoriteRepository; + this.viewedRepository = viewedRepository; } private void checkLogin(Integer id, String login) { @@ -94,6 +101,9 @@ public class UserService implements UserDetailsService { @Transactional public UserEntity delete(Integer id) { final UserEntity existsentity = get(id); + favoriteRepository.deleteByUserId(existsentity.getId()); + viewedRepository.deleteByUserId(existsentity.getId()); + repository.delete(existsentity); return existsentity; } diff --git a/backend/src/main/java/com/example/backend/viewed/repository/ViewedRepository.java b/backend/src/main/java/com/example/backend/viewed/repository/ViewedRepository.java index fbad52f..604c54e 100644 --- a/backend/src/main/java/com/example/backend/viewed/repository/ViewedRepository.java +++ b/backend/src/main/java/com/example/backend/viewed/repository/ViewedRepository.java @@ -17,4 +17,6 @@ public interface ViewedRepository extends CrudRepository Optional deleteByMovieId(Integer movieId); + Optional deleteByUserId(Integer user); + }