Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Withdraw user #150

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void revive() {

@Override
public boolean isNew() {
return id != null;
return createdAt == null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface InterestShowRepository extends JpaRepository<InterestShow, UUID
Optional<InterestShow> findByShowIdAndUserIdAndIsDeletedFalse(UUID showId, UUID userId);

Long countInterestShowByUserIdAndIsDeletedFalse(UUID userId);

void deleteAllByUserId(UUID userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface ArtistSubscriptionRepository
List<ArtistSubscription> findAllByUserIdAndIsDeletedFalse(UUID userId);

Long countByUserIdAndIsDeletedFalse(UUID userId);

void deleteAllByUserId(UUID userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface GenreSubscriptionRepository extends JpaRepository<GenreSubscrip
List<GenreSubscription> findByUserIdAndIsDeletedFalse(UUID userId);

Long countByUserIdAndIsDeletedFalse(UUID uuid);

void deleteAllByUserId(UUID userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public interface TicketingAlertRepository extends JpaRepository<TicketingAlert,

List<TicketingAlert> findAllByUserIdAndIsDeletedFalse(UUID userId);

void deleteAllByUserId(UUID userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ Optional<SocialLogin> findBySocialLoginTypeAndIdentifier(
SocialLoginType socialLoginType,
String identifier
);

void deleteAllByUserId(UUID userId);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.example.repository.user;

import java.util.Optional;
import java.util.UUID;
import org.example.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository<User, UUID>, UserQuerydslRepository {

Optional<User> findByNickname(String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import org.example.entity.User;
import org.example.error.UserError;
import org.example.exception.BusinessException;
import org.example.repository.interest.InterestShowRepository;
import org.example.repository.subscription.artistsubscription.ArtistSubscriptionRepository;
import org.example.repository.subscription.genresubscription.GenreSubscriptionRepository;
import org.example.repository.ticketing.TicketingAlertRepository;
import org.example.repository.user.SocialLoginRepository;
import org.example.repository.user.UserRepository;
import org.springframework.stereotype.Component;
Expand All @@ -20,6 +24,10 @@ public class UserUseCase {

private final UserRepository userRepository;
private final SocialLoginRepository socialLoginRepository;
private final ArtistSubscriptionRepository artistSubscriptionRepository;
private final GenreSubscriptionRepository genreSubscriptionRepository;
private final InterestShowRepository interestShowRepository;
private final TicketingAlertRepository ticketingAlertRepository;

@Transactional
public User createNewUser(User user, SocialLogin socialLogin) {
Expand Down Expand Up @@ -53,8 +61,8 @@ public User findUser(LoginDomainRequest request) {
@Transactional
public void deleteUser(UUID userId) {
User user = userRepository.findById(userId).orElseThrow(NoSuchElementException::new);

user.softDelete();
userRepository.delete(user);
deleteAssociatedWith(user);
}

public UserProfileDomainResponse findUserProfile(UUID userId) {
Expand All @@ -64,4 +72,12 @@ public UserProfileDomainResponse findUserProfile(UUID userId) {
public String findUserFcmTokensByUserId(UUID userId) {
return userRepository.findUserFcmTokensByUserId(userId).orElseThrow(NoSuchElementException::new);
}

private void deleteAssociatedWith(User user) {
socialLoginRepository.deleteAllByUserId(user.getId());
artistSubscriptionRepository.deleteAllByUserId(user.getId());
genreSubscriptionRepository.deleteAllByUserId(user.getId());
interestShowRepository.deleteAllByUserId(user.getId());
ticketingAlertRepository.deleteAllByUserId(user.getId());
}
}
Loading