Skip to content

Commit c9dd28c

Browse files
Merge pull request #199 from SSASINSA/refactor/193_sprint_fix
refactor: 행사 옵션 수정시 신청 제거 (#193)
2 parents df57fbe + 78a45a0 commit c9dd28c

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/main/java/com/ssasinsa/wearagain/domain/event/repository/EventApplicationRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ List<Long> findApplicationIdsForUser(
142142

143143
long countByEvent_IdAndStatusIn(Long eventId, Collection<EventApplicationStatus> statuses);
144144

145+
long countByEventOption_IdIn(Collection<Long> optionIds);
146+
145147
@Query("""
146148
select ea.checkedInAt
147149
from EventApplication ea

src/main/java/com/ssasinsa/wearagain/domain/event/service/EventAdminServiceImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@
7777
import java.util.regex.Pattern;
7878
import java.util.stream.Collectors;
7979
import lombok.RequiredArgsConstructor;
80+
import lombok.extern.slf4j.Slf4j;
8081

8182
@Service
83+
@Slf4j
8284
@RequiredArgsConstructor
8385
public class EventAdminServiceImpl implements EventAdminService {
8486

@@ -332,6 +334,7 @@ public EventAdminDetailResponse updateEvent(Long eventId, EventAdminUpdateReques
332334

333335
if (request.options() != null) {
334336
validateOptionDepthStructureForRequests(targetOptionDepth, request.options());
337+
logCascadeDeletion(event);
335338
List<EventOption> options = buildEventOptions(event, request.options());
336339
event.assignOptions(options);
337340
} else if (request.optionDepth() != null) {
@@ -1085,6 +1088,17 @@ private Set<Long> collectOptionIds(Collection<EventOption> roots) {
10851088
return ids;
10861089
}
10871090

1091+
private void logCascadeDeletion(Event event) {
1092+
Set<Long> existingOptionIds = collectOptionIds(event.getOptions());
1093+
if (existingOptionIds.isEmpty()) {
1094+
return;
1095+
}
1096+
long affected = eventApplicationRepository.countByEventOption_IdIn(existingOptionIds);
1097+
if (affected > 0) {
1098+
log.warn("행사 {} 옵션 재구성으로 신청 {}건이 삭제됩니다.", event.getId(), affected);
1099+
}
1100+
}
1101+
10881102
private Integer safeToInteger(long value) {
10891103
if (value > Integer.MAX_VALUE) {
10901104
return Integer.MAX_VALUE;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- 행사 옵션 삭제 시 연결된 신청까지 함께 제거되도록 FK를 재정의한다.
2+
ALTER TABLE event_applications
3+
DROP FOREIGN KEY FKmcvrh0u6bxk36ka5lrsw3n1rw;
4+
5+
ALTER TABLE event_applications
6+
ADD CONSTRAINT FKmcvrh0u6bxk36ka5lrsw3n1rw
7+
FOREIGN KEY (event_option_id) REFERENCES event_option (event_option_id)
8+
ON DELETE CASCADE;

0 commit comments

Comments
 (0)