emptyAnswers(int size) {
+ return size == 0 ? List.of() : Collections.nCopies(size, null);
+ }
+
/**
- * 클럽 기수 전용 — 계정 ID 별 rosterAnswer(명단에 보이기 질문의 답). showInRoster 질문이 없거나 답이 없으면 해당 계정은 맵에 없다.
+ * 클럽 기수 전용 — 계정 ID 별 rosterAnswers(질문 순서대로, 답이 없으면 null). 신청이 없는 계정은 맵에 없다.
*
* 같은 studyId 에 신청이 여럿이면 ID 가 큰(나중) 행의 답을 쓴다 — 이어서 참여로 복사된 최신 답이 앞에 온다.
*/
- private Map rosterAnswersOf(Study study, Set accountIds) {
- String rosterQuestionId =
- formQuestionReader.questionsOf(study).stream()
- .filter(q -> Boolean.TRUE.equals(q.showInRoster()))
- .map(ApplicationFormQuestion::id)
- .findFirst()
- .orElse(null);
- if (rosterQuestionId == null || accountIds.isEmpty()) {
+ private Map> rosterAnswersOf(
+ Study study, List questionIds, Set accountIds) {
+ if (questionIds.isEmpty() || accountIds.isEmpty()) {
return Map.of();
}
List applications =
studyApplicationRepository.findByStudyIdAndAccountIdInOrderByIdDesc(
study.getId(), accountIds);
- Map result = new HashMap<>();
+ Map> result = new HashMap<>();
for (StudyApplication app : applications) {
if (result.containsKey(app.getAccountId())) {
continue; // ID 가 큰(나중) 행을 이미 저장했다
}
- String answer = extractAnswer(app.getFormAnswer(), rosterQuestionId);
- if (answer != null) {
- result.put(app.getAccountId(), answer);
+ List answers = new ArrayList<>(questionIds.size());
+ for (String questionId : questionIds) {
+ answers.add(extractAnswer(app.getFormAnswer(), questionId));
}
+ result.put(app.getAccountId(), answers);
}
return result;
}
@@ -278,7 +289,7 @@ private String extractAnswer(String formAnswerJson, String questionId) {
}
return value.asText();
} catch (JacksonException e) {
- log.warn("rosterAnswer 추출 실패 — questionId={}", questionId, e);
+ log.warn("rosterAnswers 추출 실패 — questionId={}", questionId, e);
return null;
}
}
diff --git a/backend/api/src/test/java/com/studyclub/api/application/StudyApplicationFormIntegrationTest.java b/backend/api/src/test/java/com/studyclub/api/application/StudyApplicationFormIntegrationTest.java
index 716ab111b..adc49dfac 100644
--- a/backend/api/src/test/java/com/studyclub/api/application/StudyApplicationFormIntegrationTest.java
+++ b/backend/api/src/test/java/com/studyclub/api/application/StudyApplicationFormIntegrationTest.java
@@ -7,6 +7,7 @@
import com.studyclub.domain.account.SystemRole;
import java.sql.Timestamp;
import java.time.Instant;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
@@ -381,6 +382,52 @@ void rejectsAllowOtherOnUnsupportedType() {
assertThat(response.getBody()).containsEntry("errorCode", "INVALID_INPUT");
}
+ @Test
+ @DisplayName("성공 - 출석부에 표시는 질문 2개까지 켤 수 있다")
+ void acceptsTwoRosterQuestions() {
+ var response =
+ rest.exchange(
+ "/api/admin/studies/" + EDITABLE_STUDY_ID + "/application-form",
+ HttpMethod.PUT,
+ authenticatedJsonRequest(CAPTAIN_ID, rosterRequest(2)),
+ Map.class);
+
+ assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
+ }
+
+ @Test
+ @DisplayName("실패 - 출석부에 표시를 질문 3개에 켜면 INVALID_INPUT이다")
+ void rejectsThreeRosterQuestions() {
+ var response =
+ rest.exchange(
+ "/api/admin/studies/" + EDITABLE_STUDY_ID + "/application-form",
+ HttpMethod.PUT,
+ authenticatedJsonRequest(CAPTAIN_ID, rosterRequest(3)),
+ Map.class);
+
+ assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
+ assertThat(response.getBody()).containsEntry("errorCode", "INVALID_INPUT");
+ }
+
+ private Map rosterRequest(int rosterCount) {
+ List