Skip to content

Commit 6283d76

Browse files
authored
Merge pull request #21 from DevKor-github/dev
Dev
2 parents d729da8 + 2184917 commit 6283d76

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

src/main/java/com/workingdead/meet/repository/PriorityPreferenceRepository.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@
55

66
import java.util.List;
77

8+
import org.springframework.data.jpa.repository.Modifying;
9+
import org.springframework.data.jpa.repository.Query;
10+
import org.springframework.data.repository.query.Param;
11+
812
public interface PriorityPreferenceRepository extends JpaRepository<PriorityPreference, Long> {
913
List<PriorityPreference> findByParticipantIdAndVoteId(Long participantId, Long voteId);
1014
List<PriorityPreference> findByVoteId(Long voteId);
1115

12-
void deleteByParticipantIdAndVoteId(Long participantId, Long voteId);
16+
// void deleteByParticipantIdAndVoteId(Long participantId, Long voteId);
17+
@Modifying
18+
@Query("DELETE FROM PriorityPreference pp WHERE pp.participant.id = :participantId")
19+
void deleteByParticipantId(@Param("participantId") Long participantId);
1320
}

src/main/java/com/workingdead/meet/service/ParticipantService.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,21 @@
2121
public 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

Comments
 (0)