Skip to content

Commit 8f17612

Browse files
authored
Merge pull request #9 from DevKor-github/dev
feat: get /participants/{id}/choices 구현
2 parents 0aaf564 + 3731fd5 commit 8f17612

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

src/main/java/com/workingdead/meet/controller/ParticipantController.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,23 @@ public ResponseEntity<ParticipantDtos.ParticipantScheduleRes> submitSchedule(
158158
participantService.submitSchedule(participantId, request);
159159
return ResponseEntity.ok(response);
160160
}
161+
162+
@Operation(
163+
summary = "참여자의 선택 정보 조회",
164+
description = "특정 참여자가 선택한 일정과 우선순위를 조회합니다."
165+
)
166+
@ApiResponses({
167+
@ApiResponse(responseCode = "200", description = "조회 성공",
168+
content = @Content(schema = @Schema(implementation = ParticipantDtos.ParticipantChoicesRes.class))),
169+
@ApiResponse(responseCode = "404", description = "참여자를 찾을 수 없음", content = @Content)
170+
})
171+
@GetMapping("/participants/{participantId}/choices")
172+
public ResponseEntity<ParticipantDtos.ParticipantChoicesRes> getParticipantChoices(
173+
@PathVariable Long participantId) {
174+
175+
ParticipantDtos.ParticipantChoicesRes response =
176+
participantService.getParticipantChoices(participantId);
177+
178+
return ResponseEntity.ok(response);
179+
}
161180
}

src/main/java/com/workingdead/meet/dto/ParticipantDtos.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,36 @@ public record PriorityRes(
6262
int priorityIndex,
6363
double weight
6464
) {}
65+
66+
/**
67+
* 참여자의 선택 정보 조회 응답
68+
*/
69+
public record ParticipantChoicesRes(
70+
Long participantId,
71+
String displayName,
72+
List<SelectionInfo> selections,
73+
List<PriorityInfo> priorities
74+
) {}
75+
76+
/**
77+
* 일정 선택 정보
78+
*/
79+
public record SelectionInfo(
80+
Long id,
81+
String date,
82+
String period,
83+
boolean selected
84+
) {}
85+
86+
/**
87+
* 우선순위 정보
88+
*/
89+
public record PriorityInfo(
90+
Long id,
91+
String date,
92+
String period,
93+
Integer priorityIndex,
94+
Double weight
95+
) {}
6596
}
6697

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,43 @@ private String genCode(int len) {
165165
for (int i=0;i<len;i++) sb.append(CODE_ALPHABET.charAt(rnd.nextInt(CODE_ALPHABET.length())));
166166
return sb.toString();
167167
}
168+
169+
/**
170+
* 특정 참여자의 선택한 일정과 우선순위 조회 (participantId만 사용)
171+
*/
172+
public ParticipantDtos.ParticipantChoicesRes getParticipantChoices(Long participantId) {
173+
174+
// 참여자 존재 확인 및 조회
175+
Participant participant = participantRepo.findById(participantId)
176+
.orElseThrow(() -> new RuntimeException("Participant not found"));
177+
178+
// 일정 선택 정보 조회 (엔티티 관계 활용)
179+
List<ParticipantDtos.SelectionInfo> selectionInfos = participant.getSelections().stream()
180+
.map(s -> new ParticipantDtos.SelectionInfo(
181+
s.getId(),
182+
s.getDate().toString(),
183+
s.getPeriod(),
184+
s.isSelected()
185+
))
186+
.toList();
187+
188+
// 우선순위 정보 조회 (엔티티 관계 활용)
189+
List<ParticipantDtos.PriorityInfo> priorityInfos = participant.getPriorities().stream()
190+
.map(p -> new ParticipantDtos.PriorityInfo(
191+
p.getId(),
192+
p.getDate().toString(),
193+
p.getPeriod(),
194+
p.getPriorityIndex(),
195+
p.getWeight()
196+
))
197+
.sorted((p1, p2) -> p1.priorityIndex().compareTo(p2.priorityIndex()))
198+
.toList();
199+
200+
return new ParticipantDtos.ParticipantChoicesRes(
201+
participant.getId(),
202+
participant.getDisplayName(),
203+
selectionInfos,
204+
priorityInfos
205+
);
206+
}
168207
}

0 commit comments

Comments
 (0)