2121public class ParticipantService {
2222 private final ParticipantRepository participantRepo ;
2323 private final VoteRepository voteRepo ;
24+ private final ParticipantSelectionRepository selectionRepo ; // 추가!
25+ private final PriorityPreferenceRepository priorityRepo ; // 추가!
2426 private static final String CODE_ALPHABET = "abcdefghijkmnopqrstuvwxyz23456789" ;
2527 private final SecureRandom rnd = new SecureRandom ();
2628
27- public ParticipantService (ParticipantRepository participantRepo , VoteRepository voteRepo ) {
29+ // 생성자 수정
30+ public ParticipantService (
31+ ParticipantRepository participantRepo ,
32+ VoteRepository voteRepo ,
33+ ParticipantSelectionRepository selectionRepo , // 추가!
34+ PriorityPreferenceRepository priorityRepo ) { // 추가!
2835 this .participantRepo = participantRepo ;
2936 this .voteRepo = voteRepo ;
37+ this .selectionRepo = selectionRepo ; // 추가!
38+ this .priorityRepo = priorityRepo ; // 추가!
3039 }
3140
3241 public ParticipantDtos .ParticipantRes add (Long voteId , String displayName ) {
@@ -103,17 +112,21 @@ public ParticipantDtos.ParticipantScheduleRes submitSchedule(
103112 Long participantId ,
104113 ParticipantDtos .SubmitScheduleReq request ) {
105114
106- // participantRepository -> participantRepo로 수정!
107115 Participant participant = participantRepo .findById (participantId )
108116 .orElseThrow (() -> new IllegalArgumentException ("참가자를 찾을 수 없습니다." ));
109117
110118 Vote vote = participant .getVote ();
111119
112- // 1. 기존 선택 및 우선순위 삭제
120+ // 1. 기존 데이터 명시적으로 삭제 (Repository 사용) - 수정!
121+ selectionRepo .deleteByParticipantId (participantId );
122+ priorityRepo .deleteByParticipantId (participantId );
123+ selectionRepo .flush (); // DB에 즉시 반영!
124+
125+ // 2. 컬렉션 비우기
113126 participant .getSelections ().clear ();
114127 participant .getPriorities ().clear ();
115128
116- // 2 . 새로운 선택 저장
129+ // 3 . 새로운 선택 저장
117130 for (ParticipantDtos .DateSlotReq dateSlot : request .schedules ()) {
118131 for (ParticipantDtos .SlotReq slot : dateSlot .slots ()) {
119132 ParticipantSelection selection = ParticipantSelection .builder ()
@@ -127,7 +140,7 @@ public ParticipantDtos.ParticipantScheduleRes submitSchedule(
127140 }
128141 }
129142
130- // 3 . 우선순위 저장 (있는 경우)
143+ // 4 . 우선순위 저장 (있는 경우)
131144 if (request .priorities () != null && !request .priorities ().isEmpty ()) {
132145 for (ParticipantDtos .PriorityReq priority : request .priorities ()) {
133146 PriorityPreference pref = PriorityPreference .builder ()
@@ -143,15 +156,14 @@ public ParticipantDtos.ParticipantScheduleRes submitSchedule(
143156 }
144157 }
145158
146- // 4 . 제출 정보 업데이트
159+ // 5 . 제출 정보 업데이트
147160 participant .setSubmittedAt (LocalDateTime .now ());
148161 participant .setSubmitted (true );
149162
150- // participantRepository -> participantRepo로 수정!
151163 Participant saved = participantRepo .save (participant );
152164 participantRepo .flush ();
153165
154- // 5 . 응답 생성
166+ // 6 . 응답 생성
155167 List <ParticipantDtos .SelectionRes > selections = saved .getSelections ().stream ()
156168 .map (s -> new ParticipantDtos .SelectionRes (
157169 s .getDate (),
@@ -223,6 +235,4 @@ public ParticipantDtos.ParticipantChoicesRes getParticipantChoices(Long particip
223235 priorityInfos
224236 );
225237 }
226-
227-
228238}
0 commit comments