Skip to content

Commit

Permalink
refactor : 멤버가 팀에서 제거될 시 관련 데이터 벌크연산 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
songhyeon99 committed May 7, 2024
1 parent 1ee3df5 commit 802a47a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public class DeleteTeamAdapter implements DeleteTeamPort {

@Override
public void delete(Team team) {
teamRepository.delete(team);
teamRepository.delete(team.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,28 @@
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public class DeleteTeamMemberAdapter implements DeleteTeamMemberPort {

private final LoadMemberPort loadMemberPort;
private final LoadTeamPort loadTeamPort;
private final DeleteTeamPort deleteTeamPort;

private final LoadMemberPort loadMemberPort;

private final LoadTeamCalendarPort loadTeamCalendarPort;

private final DeleteSleepoverCalendarPort deleteSleepoverCalendarPort;
private final DeleteTeamPort deleteTeamPort;

@Override
public void deleteTeamMember(Long memberId) {
final Member member = loadMemberPort.loadMember(memberId);
final Team team = loadTeamPort.findByMemberId(member.getId());
final List<TeamCalendar> teamCalendars = loadTeamCalendarPort.findByMemberId(member.getId());

deleteSleepoverCalendarPort.deleteByMemberId(memberId);
teamCalendars
.forEach(teamCalendar -> teamCalendar.deletePariticipant(member.getId()));
team.deleteMember(member);
if (team.getMembers().isEmpty()) {
deleteTeamPort.delete(team);
} else {
deleteSleepoverCalendarPort.deleteByMemberId(memberId);
teamCalendars
.forEach(teamCalendar -> teamCalendar.deletePariticipant(member.getId()));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
Expand All @@ -15,5 +16,6 @@ public interface SleepoverCalendarRepository
List<SleepoverCalendar> findByMemberId(Long memberId);

@Modifying
@Query("delete from SleepoverCalendar sc where sc.memberId = :memberId")
void deleteByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import idorm.idormServer.calendar.entity.Team;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface TeamRepository extends JpaRepository<Team, Long>, TeamCustomRepository {

@Modifying
@Query("delete from Team t where t.id = :teamId")
void delete(Long teamId);
}

0 comments on commit 802a47a

Please sign in to comment.