Skip to content

Commit

Permalink
Fix: 회원탈퇴 고아객체제거 사용할 수 없던 문제 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
onetuks committed Dec 1, 2023
1 parent 3594486 commit d182986
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public class Dashboard {
private Long lessonId;

@OneToMany(
mappedBy = "dashboard", fetch = LAZY,
cascade = {PERSIST, REMOVE}, orphanRemoval = true)
mappedBy = "dashboard",
fetch = LAZY,
cascade = {PERSIST})
private List<DashboardSchedule> dashboardSchedules;

@Embedded
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.guzzing.studayserver.domain.dashboard.repository;

import java.util.List;
import org.guzzing.studayserver.domain.dashboard.model.DashboardSchedule;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface DashboardScheduleJpaRepository extends JpaRepository<DashboardSchedule, Long> {

@Modifying(clearAutomatically = true)
@Query("""
delete from DashboardSchedule ds
where ds.dashboard.childId in :childIds
""")
void deleteByChildIds(final List<Long> childIds);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.guzzing.studayserver.domain.dashboard.model.Dashboard;
import org.guzzing.studayserver.domain.dashboard.model.vo.FeeInfo;
import org.guzzing.studayserver.domain.dashboard.repository.DashboardRepository;
import org.guzzing.studayserver.domain.dashboard.repository.DashboardScheduleJpaRepository;
import org.guzzing.studayserver.domain.dashboard.service.converter.DashboardServiceConverter;
import org.guzzing.studayserver.domain.dashboard.service.dto.request.DashboardPostParam;
import org.guzzing.studayserver.domain.dashboard.service.dto.request.DashboardPutParam;
Expand All @@ -19,13 +20,16 @@ public class DashboardService {

private final DashboardServiceConverter serviceConverter;
private final DashboardRepository dashboardRepository;
private final DashboardScheduleJpaRepository dashboardScheduleJpaRepository;

public DashboardService(
final DashboardServiceConverter serviceConverter,
final DashboardRepository dashboardRepository
final DashboardRepository dashboardRepository,
final DashboardScheduleJpaRepository dashboardScheduleJpaRepository
) {
this.serviceConverter = serviceConverter;
this.dashboardRepository = dashboardRepository;
this.dashboardScheduleJpaRepository = dashboardScheduleJpaRepository;
}

@Transactional
Expand All @@ -44,6 +48,7 @@ public void deleteDashboard(final long dashboardId) {

@Transactional
public void removeDashboard(final List<Long> childIds) {
dashboardScheduleJpaRepository.deleteByChildIds(childIds);
dashboardRepository.deleteByChildIds(childIds);
}

Expand Down

0 comments on commit d182986

Please sign in to comment.