Skip to content

Commit

Permalink
feat: Withdraw user (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmizz authored Sep 8, 2024
1 parent b2abaeb commit 059cb9c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 5 deletions.
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());
}
}

0 comments on commit 059cb9c

Please sign in to comment.