теперь еще и удаляется все грамотно
This commit is contained in:
parent
f1de853000
commit
8ac47b0fdf
@ -16,4 +16,6 @@ public interface FavoriteRepository extends CrudRepository<FavoriteEntity, Integ
|
||||
|
||||
Optional<FavoriteEntity> deleteByMovieId(Integer movieId);
|
||||
|
||||
Optional<FavoriteEntity> deleteByUserId(Integer user);
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -17,4 +17,6 @@ public interface ViewedRepository extends CrudRepository<ViewedEntity, Integer>
|
||||
|
||||
Optional<ViewedEntity> deleteByMovieId(Integer movieId);
|
||||
|
||||
Optional<ViewedEntity> deleteByUserId(Integer user);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user