Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .prober/tests/participant-completion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 종료된 스터디의 완료 전환 (ZAPP #193)

대상: stage (`backend-develop` · `back-office-front-develop` · `core-front-develop`). 스펙 [study-participant 「완료」](../../specs/study-participant/spec.md#완료-completed). 스테이지의 테스트 계정만 쓴다. 담당 캡틴 계정 하나, 같은 반의 네비게이터 · 크루 계정 하나씩, 그 반에서 참여를 중단한 크루 계정 하나로 한다. 결과 · 캡처에 실제 회원 정보와 토큰을 남기지 않는다.

준비: 진행 중(OPEN, 시작일 지남)인 테스트 스터디 하나와 지난 회차 하나 이상. 그 스터디의 최근 모집 회차는 마감일이 없거나 아직 지나지 않았고 정원이 남아 있어야 한다(모집이 이미 마감돼 있으면 `CP-LIST-01` · `CP-APPLY-01` 이 이번 변경 없이도 같은 결과를 낸다). 크루가 발표자인 회차가 하나 있으면 `CP-VIEW-01` 을 함께 본다. 화면에서는 종료일을 넣을 수 없으므로 **DB 권한자가 그 스터디의 `STUDY.END_AT` 을 지금보다 몇 분 뒤(UTC)로 바꿔 둔다**. `CP-CLOSED-01` 용으로 `ACTIVE` 참여자가 있는 다른 테스트 스터디 하나를 `STATUS = CLOSED`, `END_AT` 을 지난 시각으로 바꿔 둔다. 스테이지는 Flyway 를 끄고 있어 `V75` 가 돌지 않는다. 그래서 전환은 스케줄러로만 확인한다.

| ID | 절차 | 기대 결과 |
|---|---|---|
| CP-BEFORE-01 | `END_AT` 이 지나기 전에 캡틴으로 백오피스 › 스터디 › 신청자 탭을 연다 | 네비게이터 · 크루가 보이고 인원 수에 든다. 참여 중단한 크루는 보이지 않는다 |
| CP-BEFORE-02 | `END_AT` 이 지나기 전에 `GET /api/studies?keyword={스터디 제목}` | 그 스터디의 `canApply` 가 `true`, `recruitStatus` 가 `RECRUITING` |
| CP-RUN-01 | `END_AT` 이 지나고 1~2분 뒤 같은 탭을 새로고침한다 | 네비게이터 · 크루가 그대로 보이고, `참여 크루 N명` 과 반 카드의 인원도 그대로다(0명으로 바뀌지 않는다). 두 사람의 선택 칸이 잠긴다(완료 행은 반 · 역할을 고치지 않는다) |
| CP-RUN-02 | 서버 로그에서 `완료 전환 실패` 를 찾는다 | 이 스터디로 남은 줄이 없다 |
| CP-RUN-03 | `GET /api/studies/{id}` | `status` 가 `ENDED`(종료로 저장됐다), `recruitStatus` 가 `null`, `canApply` 가 `false` |
| CP-CLOSED-01 | 1~2분 뒤 `CLOSED` 로 둔 스터디를 캡틴으로 백오피스 › 신청자 탭에서 열고, `GET /api/studies/{id}` 를 부른다 | 참여자의 선택 칸이 잠기지 않는다(완료 행만 잠긴다 — 운영 종료는 완료로 넘기지 않는다). API 의 `status` 는 `CLOSED` 그대로다 |
| CP-VIEW-01 | 크루로 사용자 사이트 › 내 스터디룸 › 그 스터디 › 일정 탭 | 일정이 보인다(403 이 아니다). 크루가 맡은 발표자 칸이 `(참여 종료)` 로 바뀌지 않는다 |
| CP-VIEW-02 | 크루로 출석 탭 | 출석부가 보이고, 네비게이터 · 크루가 명단에 있다. 참여 중단한 크루는 없다 |
| CP-VIEW-03 | 크루로 `GET /api/me/studies/{id}/retros/status` (반을 주지 않는다) | 200 |
| CP-EDIT-01 | 네비게이터로 출석 탭에서 지난 회차의 크루 칸을 출석으로 바꿔 저장 | 저장된다. 새로고침해도 출석으로 남는다 |
| CP-EDIT-02 | 네비게이터로 출석 탭에서 크루의 선택 칸을 고른다 | 선택된다. 「출석 상태」 일괄 변경을 쓸 수 있고, 「참여 중단」 버튼은 잠기며 `끝난 스터디에서는 참여 중단할 수 없습니다.` 가 보인다 |
| CP-MY-01 | 크루로 사용자 사이트 › 내 스터디룸 | 그 스터디 카드가 「참여 종료」 탭에 있고 「완주」 배지와 `완주를 축하합니다!` 출석 점수판이 보인다(완료와 완주를 나눠 보이는 일은 따로 한다 — 지금은 완료한 사람 모두에게 붙는다) |
| CP-DENY-01 | 참여를 중단한 크루로 그 스터디의 일정 탭 | 지금처럼 볼 수 없다(403) |
| CP-LIST-01 | `GET /api/studies?keyword={스터디 제목}` | 그 스터디의 `currentApplicants` 가 0 이 아니라 완료한 사람 수다. `canApply` 는 `false`, `recruitStatus` 는 `null`(`ENDED` 로 저장된 뒤다. `CP-BEFORE-02` 에서는 `true` · `RECRUITING`) |
| CP-LIST-02 | 백오피스 스터디 목록을 `지원 현황` 열로 내림차순 정렬 | 그 스터디의 지원 현황이 완료한 사람 수로 보이고, 그 수로 정렬된다(0명으로 맨 뒤에 가지 않는다) |
| CP-APPLY-01 | 디스코드를 연동한 새 크루 계정으로 그 스터디에 `POST /api/studies/{id}/applications` | 404. 신청 행이 생기지 않는다(`ENDED` 로 저장된 뒤라 `STATUS = OPEN` 검사에서 막힌다) |
| CP-API-01 | 크루로 `GET /api/me/studies/{id}/attendances?studyGroupId={반}` | 200. 네비게이터 · 크루 줄의 `participantStatus` 가 `COMPLETED` |

로컬 회귀 테스트: `backend/api/src/test/java/com/studyclub/api/participant/` (`StudyParticipantCompletionIntegrationTest` · `StudyParticipantCompletionSchedulerTest` · `CompletedParticipantReadPathIntegrationTest`), `backend/api/src/test/java/com/studyclub/api/application/StudyApplicationSubmissionIntegrationTest` (`rejectsEndedStudy`), `backend/domain/src/test/java/com/studyclub/domain/participant/StudyParticipantTest`, `backend/domain/src/test/java/com/studyclub/domain/study/StudyTest` (`canApply_endedStudy` · `endIfDue`), 백오피스 `src/features/participants/ParticipantsTab.test.tsx`, core-front `src/features/attendance/AttendanceTabContent.test.tsx`.
2 changes: 1 addition & 1 deletion 01-planning/stories/captain-reregister-cohort/PRD.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ flowchart LR

- **조건**: 창을 열었을 때
- **동작**: 누르면 다음 달 기수를 미공개로 만들고 창을 닫는다. 이어서 참여한 인원을 알린다
- **데이터**: `POST /api/admin/studies/{studyId}/next-cohort` — `capacity` → 201, 미공개 스터디 · 모집 · 날마다 회차 · 이번 기수 `ACTIVE` 참여자 전원의 `STUDY_PARTICIPANT`
- **데이터**: `POST /api/admin/studies/{studyId}/next-cohort` — `capacity` → 201, 미공개 스터디 · 모집 · 날마다 회차 · 이번 기수 `ACTIVE` · `COMPLETED`(완료) 참여자 전원의 `STUDY_PARTICIPANT`

<!-- spec:end cohort -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public Long submit(Long accountId, Long studyId, SubmitStudyApplicationRequest r
if (study.getStatus() != StudyStatus.OPEN) {
throw new BusinessException(ErrorCode.NOT_FOUND);
}
// 끝난 스터디는 받지 않는다 — 종료일이 지나 스케줄러가 ENDED 로 저장하기 전 1분이다. 완료 전환으로 ACTIVE 가 줄면 정원이 다시 비고,
// 신청서 없는 완료 행이 아래 joinRoster 에서 되살아난다
if (study.isEnded(Instant.now())) {
throw new BusinessException(ErrorCode.CONFLICT, "모집이 마감되었습니다.");
}
StudyRecruitment recruitment = openRecruitment(studyId);
checkCapacity(recruitment, studyId);
List<ApplicationFormQuestion> questions = formQuestionReader.questionsOf(study);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public class AttendanceService {
// 자체가 실패할 때만 쓰인다 — 즉 DELETED(회원 탈퇴)인 참가자.
private static final String DELETED_ACCOUNT_NICKNAME = "탈퇴한 회원";

/** 기본 명단({@code includeWithdrawn=false}) — 참여 중과 완료. 끝난 스터디의 출석부가 비지 않게 완료자를 넣는다. */
private static final Set<ParticipantStatus> DEFAULT_ROSTER_STATUSES =
Set.of(ParticipantStatus.ACTIVE, ParticipantStatus.COMPLETED);

private final StudyRepository studyRepository;
private final StudyGroupRepository studyGroupRepository;
private final StudyParticipantRepository studyParticipantRepository;
Expand Down Expand Up @@ -101,7 +105,7 @@ public AttendanceResponse getAttendances(
includeWithdrawn
? allParticipants
: allParticipants.stream()
.filter(p -> p.getStatus() == ParticipantStatus.ACTIVE)
.filter(p -> DEFAULT_ROSTER_STATUSES.contains(p.getStatus()))
.toList();
List<StudyMeeting> allMeetings =
studyMeetingRepository.findByStudyGroupIdOrderByScheduledAt(studyGroupId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public MyAttendanceController(
@Operation(
summary = "출석 명부 조회",
description =
"지정한 분반의 명부. 그 스터디의 활성 참여자(크루 · 다른 반 네비게이터 포함, 보기만) · 그 분반 네비게이터 · 캡틴"
"지정한 분반의 명부. 그 스터디의 참여자(크루 · 다른 반 네비게이터 · 완료자 포함, 보기만) · 그 분반 네비게이터 · 캡틴"
+ " (specs/authz-guards).")
@SecurityRequirement(name = "bearerAuth")
@RequireOnboarding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ private void cancelEventRegistrations(Long accountId) {

// 참여 중단 · 발표 신청과 같은 분반 잠금을 먼저 쥔다 — 그 사이에 커밋된 참여 중단의 상태 · LEFT_AT 을 덮어쓰지 않는다 (share 10-18 D7).
// 분반은 ID 오름차순으로 잠근다 — 여러 분반을 잠그는 참여 중단도 이 순서다. 디스코드 출석은 분반이 아니라 회차만, 같은 분반 ID 오름차순으로 잠근다
// 표시하기 직전에 명부에 있던(ACTIVE·PAUSED) 행을 돌려준다 — 디스코드 role 이 남아 있을 수 있는 곳이다
// 표시하기 직전에 명부에 있던(ACTIVE·PAUSED·COMPLETED) 행을 돌려준다 — 디스코드 role 이 남아 있을 수 있는 곳이다. 완료해도 role 은 떼지
// 않는다
private List<StudyParticipant> anonymizeParticipations(Long accountId) {
List<Long> groupIds = studyParticipantRepository.findStudyGroupIdsByAccountId(accountId);
for (Long groupId : groupIds) {
Expand All @@ -234,8 +235,11 @@ private List<StudyParticipant> anonymizeParticipations(Long accountId) {
.filter(
p ->
p.getStatus() == ParticipantStatus.ACTIVE
|| p.getStatus() == ParticipantStatus.PAUSED)
|| p.getStatus() == ParticipantStatus.PAUSED
|| p.getStatus() == ParticipantStatus.COMPLETED)
.toList();
// 그중 LEADER 행은 권한 말소로 남긴다 — 완료한 네비게이터도 끝난 스터디의 출석 · 일정을 고칠 수 있다
// (StudyCaptainGuard.NAVIGATOR_STATUSES)
for (StudyParticipant participant : onRoster) {
if (participant.getParticipantRole() == ParticipantRole.LEADER) {
auditRecorder.record(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import org.springframework.web.servlet.HandlerMapping;

/**
* {@link RequireGroupRoster} 이 붙은 핸들러 앞에서 그 분반의 활성 참여자·네비게이터·캡틴 여부를 확인한다
* (specs/authz-guards/spec.md).
* {@link RequireGroupRoster} 이 붙은 핸들러 앞에서 그 분반의 참여자·네비게이터·캡틴 여부를 확인한다 (specs/authz-guards/spec.md).
*/
@Component
public class GroupRosterGuardInterceptor implements HandlerInterceptor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import java.lang.annotation.Target;

/**
* 그 분반의 활성 참여자(크루 포함) · 네비게이터 · 캡틴만 호출할 수 있다 — {@link GroupRosterGuardInterceptor} 가 검사한다
* (specs/authz-guards/spec.md). 조회 전용 엔드포인트에 사용하며, 수정 권한이 필요할 때는 {@link RequireCaptainOrNavigator}
* 를 쓴다.
* 그 분반의 참여자(크루 포함, {@code StudyCaptainGuard.VIEWER_STATUSES}) · 네비게이터 · 캡틴만 호출할 수 있다 — {@link
* GroupRosterGuardInterceptor} 가 검사한다 (specs/authz-guards/spec.md). 조회 전용 엔드포인트에 사용하며, 수정 권한이 필요할
* 때는 {@link RequireCaptainOrNavigator} 를 쓴다.
*
* <p>path {@code studyId} + query/path {@code studyGroupId} 조합으로 분반을 특정한다. 다른 분반 소속이면 403.
*/
Expand All @@ -20,6 +20,6 @@

String studyGroupIdParam() default "studyGroupId";

/** true 면 그 분반이 아니어도 같은 스터디의 활성 참여자는 통과한다 — 다른 반을 보기만 하는 조회용. */
/** true 면 그 분반이 아니어도 같은 스터디의 참여자는 통과한다 — 다른 반을 보기만 하는 조회용. */
boolean wholeStudy() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ private StudyMeetingListResponse listView(
List<String> navigatorNames =
roster.stream()
.filter(p -> p.getParticipantRole() == ParticipantRole.LEADER)
.filter(p -> StudyCaptainGuard.ROSTER_STATUSES.contains(p.getStatus()))
.filter(p -> StudyCaptainGuard.NAVIGATOR_STATUSES.contains(p.getStatus()))
.map(p -> nameByAccount.get(p.getAccountId()))
.filter(Objects::nonNull)
.toList();
String navigatorName = navigatorNames.isEmpty() ? null : String.join(", ", navigatorNames);
Long myParticipantId =
roster.stream()
.filter(p -> p.getAccountId().equals(accountId))
.filter(p -> StudyCaptainGuard.ROSTER_STATUSES.contains(p.getStatus()))
.filter(p -> StudyCaptainGuard.VIEWER_STATUSES.contains(p.getStatus()))
.map(StudyParticipant::getId)
.findFirst()
.orElse(null);
Expand Down Expand Up @@ -506,7 +506,7 @@ private StudyMeetingListResponse.PresenterView presenter(
return new StudyMeetingListResponse.PresenterView(
participantId,
nameByAccount.get(participant.getAccountId()),
StudyCaptainGuard.ROSTER_STATUSES.contains(participant.getStatus()));
StudyCaptainGuard.VIEWER_STATUSES.contains(participant.getStatus()));
}

private Map<Long, String> nicknames(List<StudyParticipant> roster) {
Expand Down Expand Up @@ -537,13 +537,13 @@ private StudyGroup lockGroup(Long groupId) {
}

// 분반을 안 주면 이 스터디의 내 명부 행이 속한 분반 — 명부에 없는 캡틴은 분반을 골라 와야 한다.
// WITHDRAWN/COMPLETED 행을 건너뛰어 재합류(다른 반) 크루가 구 반 ID 를 받지 않도록 한다.
// 활성 네비게이터는 항상 ACTIVE/PAUSED 행이 있으므로 orElseThrow 에 도달하지 않는다.
// WITHDRAWN 행을 건너뛰어 재합류(다른 반) 크루가 구 반 ID 를 받지 않도록 한다. 완료(COMPLETED)는 끝난 스터디의 내 반이다.
// 네비게이터는 항상 NAVIGATOR_STATUSES 행이 있으므로 orElseThrow 에 도달하지 않는다.
private Long myGroupId(Long accountId, Long studyId) {
account(accountId);
return studyParticipantRepository
.findFirstByStudyIdAndAccountIdAndStatusIn(
studyId, accountId, StudyCaptainGuard.ROSTER_STATUSES)
studyId, accountId, StudyCaptainGuard.VIEWER_STATUSES)
.map(StudyParticipant::getStudyGroupId)
.orElseThrow(
() ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.studyclub.api.participant;

import java.time.Instant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
* 1분마다 종료일이 지난 스터디를 종료(ENDED)로 저장하고 명부를 완료로 바꾼다 ({@link StudyParticipantCompletionService}). 클럽 기수는
* {@code END_AT}(다음 달 1일 0시)이 지나면 1분 안에 넘어간다.
*
* <p>스케줄링을 켜는 다른 설정은 각자 끌 수 있어 여기서도 켠다. 테스트는 {@code study.participant-completion.enabled=false} 로
* 끄고 서비스를 직접 부른다.
*/
@Component
@EnableScheduling
@ConditionalOnProperty(value = "study.participant-completion.enabled", matchIfMissing = true)
public class StudyParticipantCompletionScheduler {

private static final Logger log =
LoggerFactory.getLogger(StudyParticipantCompletionScheduler.class);

private final StudyParticipantCompletionService completionService;

public StudyParticipantCompletionScheduler(
StudyParticipantCompletionService completionService) {
this.completionService = completionService;
}

@Scheduled(fixedDelayString = "${study.participant-completion.fixed-delay-ms:60000}")
public void run() {
Instant now = Instant.now();
for (Long studyId : completionService.findCandidates(now)) {
try {
completionService.complete(studyId, now);
} catch (RuntimeException e) {
log.error("완료 전환 실패 studyId={}", studyId, e);
}
}
}
}
Loading
Loading