Skip to content

Commit

Permalink
refactor: Member 삭제 재시도 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jjongwa committed Nov 28, 2023
1 parent 1a334fe commit e6c87c1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import hanglog.expense.domain.repository.ExpenseRepository;
import hanglog.member.domain.MemberDeleteEvent;
import hanglog.outbox.domain.repository.OutBoxRepository;
import hanglog.trip.domain.TripDeleteEvent;
import hanglog.trip.domain.repository.CustomDayLogRepository;
import hanglog.trip.domain.repository.CustomItemRepository;
Expand All @@ -12,7 +13,6 @@
import hanglog.trip.domain.repository.ItemRepository;
import hanglog.trip.domain.repository.PlaceRepository;
import hanglog.trip.domain.repository.TripCityRepository;
import hanglog.outbox.domain.repository.OutBoxRepository;
import hanglog.trip.domain.repository.TripRepository;
import hanglog.trip.dto.ItemElement;
import java.util.List;
Expand Down Expand Up @@ -50,6 +50,7 @@ public void deleteMember(final MemberDeleteEvent event) {

dayLogRepository.deleteByIds(dayLogIds);
tripRepository.deleteByMemberId(event.getMemberId());
outBoxRepository.deleteByTargetId(event.getMemberId());
}

@Async
Expand All @@ -65,7 +66,7 @@ public void deleteTrip(final TripDeleteEvent event) {

dayLogRepository.deleteByIds(dayLogIds);
tripCityRepository.deleteAllByTripId(event.getTripId());
outBoxRepository.deleteByTripId(event.getTripId());
outBoxRepository.deleteByTargetId(event.getTripId());
}

private void deletePlaces(final List<ItemElement> itemElements) {
Expand Down
5 changes: 5 additions & 0 deletions backend/src/main/java/hanglog/login/service/LoginService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
import hanglog.member.domain.Member;
import hanglog.member.domain.MemberDeleteEvent;
import hanglog.member.domain.repository.MemberRepository;
import hanglog.outbox.domain.OutBox;
import hanglog.outbox.domain.type.TargetType;
import hanglog.trip.domain.repository.CustomTripRepository;
import hanglog.trip.domain.repository.SharedTripRepository;
import hanglog.outbox.domain.repository.OutBoxRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
Expand All @@ -41,6 +44,7 @@ public class LoginService {
private final OauthProviders oauthProviders;
private final JwtProvider jwtProvider;
private final BearerAuthorizationExtractor bearerExtractor;
private final OutBoxRepository outBoxRepository;
private final ApplicationEventPublisher publisher;

public MemberTokens login(final String providerName, final String code) {
Expand Down Expand Up @@ -101,6 +105,7 @@ public void deleteAccount(final Long memberId) {
publishedTripRepository.deleteByTripIds(tripIds);
sharedTripRepository.deleteByTripIds(tripIds);
memberRepository.deleteByMemberId(memberId);
outBoxRepository.save(new OutBox(memberId, TargetType.MEMBER));
publisher.publishEvent(new MemberDeleteEvent(tripIds, memberId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public interface OutBoxRepository extends JpaRepository<OutBox, Long> {
SET outBox.status = 'DELETED'
WHERE outBox.targetId = :targetId
""")
void deleteByTripId(@Param("targetId") final Long targetId);
void deleteByTargetId(@Param("targetId") final Long targetId);
}
15 changes: 11 additions & 4 deletions backend/src/main/java/hanglog/outbox/service/OutBoxExecutor.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package hanglog.outbox.service;

import hanglog.member.domain.MemberDeleteEvent;
import hanglog.outbox.domain.OutBox;
import hanglog.trip.domain.TripDeleteEvent;
import hanglog.outbox.domain.repository.OutBoxRepository;
import hanglog.trip.domain.TripDeleteEvent;
import hanglog.trip.domain.repository.CustomTripRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
Expand All @@ -16,15 +18,20 @@
public class OutBoxExecutor {

private final OutBoxRepository outBoxRepository;
private final CustomTripRepository customTripRepository;
private final ApplicationEventPublisher publisher;

@Scheduled(cron = "*/2 * * * * *")
public void deleteUnprocessedTrip() {
public void execute() {
final List<OutBox> outBoxes = outBoxRepository.findAll();
for (final OutBox outBox : outBoxes) {
outBoxes.forEach(outBox -> {
if (outBox.isMember()) {
final List<Long> tripIds = customTripRepository.findTripIdsByMemberId(outBox.getTargetId());
publisher.publishEvent(new MemberDeleteEvent(tripIds, outBox.getTargetId()));
}
if (outBox.isTrip()) {
publisher.publishEvent(new TripDeleteEvent(outBox.getTargetId()));
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void deleteTrip() {
doNothing().when(itemRepository).deleteByIds(anyList());
doNothing().when(dayLogRepository).deleteByIds(anyList());
doNothing().when(tripCityRepository).deleteAllByTripId(anyLong());
doNothing().when(outBoxRepository).deleteByTripId(anyLong());
doNothing().when(outBoxRepository).deleteByTargetId(anyLong());

// when
listener.deleteTrip(event);
Expand All @@ -115,6 +115,6 @@ void deleteTrip() {
verify(itemRepository, times(1)).deleteByIds(anyList());
verify(dayLogRepository, times(1)).deleteByIds(anyList());
verify(tripCityRepository, times(1)).deleteAllByTripId(anyLong());
verify(outBoxRepository, times(1)).deleteByTripId(anyLong());
verify(outBoxRepository, times(1)).deleteByTargetId(anyLong());
}
}

0 comments on commit e6c87c1

Please sign in to comment.