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/study-close.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 백오피스 「운영 종료」 (ZAPP #196)

대상: stage (`backend-develop` · `back-office-front-develop` · `core-front-develop`). 스펙 [study 「운영 종료」](../../specs/study/spec.md#스터디-운영-종료). 스테이지의 테스트 계정만 쓴다. 캡틴 계정 하나, 스터디 A 의 크루 계정 하나, 네비게이터 계정 하나로 한다. 결과 · 캡처에 실제 회원 정보와 토큰을 남기지 않는다.

준비: 운영 종료는 되돌리는 API 가 없으므로 테스트 스터디로만 하고, 끝나면 DB 권한자가 `STUDY.STATUS` 를 원래 값으로 돌린다. 화면에서는 `ENDED` 를 바로 만들 수 없으므로 DB 권한자가 아래처럼 바꿔 둔다.

- 스터디 A — 일반 스터디(기수 하나). `STATUS = ENDED`, `END_AT` 은 지난 시각. 명부에 완료(`COMPLETED`) 크루 하나와 참여 중단(`WITHDRAWN`) 크루 하나가 있다
- 클럽 B — 같은 프로그램의 기수 둘. 앞 기수 B1 은 `STATUS = ENDED`, 뒤 기수 B2(ID 가 더 크다)는 `STATUS = DRAFT`
- 스터디 C — `STATUS = OPEN`, `END_AT` 은 2주 뒤

| ID | 절차 | 기대 결과 |
|---|---|---|
| SC-VIEW-01 | 캡틴으로 백오피스 › 스터디 › C 상세 | 머리의 「사이트 공개」 아래에 「운영 종료」 버튼이 있고 잠겨 있다. 버튼 아래에 `종료일이 지나 종료된 뒤에 운영 종료할 수 있습니다.` 가 보인다. 눌러도 창이 뜨지 않는다 |
| SC-VIEW-02 | B1 상세 | 버튼이 잠겨 있고 `다음 기수가 있는 기수는 운영 종료할 수 없습니다.` 가 보인다(뒤 기수가 작성 중이어도 같다) |
| SC-VIEW-03 | A 상세 | 버튼을 누를 수 있고 아래에 이유 글이 없다 |
| SC-CONFIRM-01 | A 에서 「운영 종료」를 누른다 | 확인 창이 뜬다. 제목 `운영 종료`, 본문 `디스코드 채널을 모두 지웠나요?` 와 되돌릴 수 없다는 안내가 보인다. 포커스는 「취소」에 있고 Enter 로 실행되지 않는다 |
| SC-CONFIRM-02 | 확인 창에서 「취소」 | 창이 닫힌다. 새로고침해도 상태 배지가 `종료` 다 |
| SC-CLOSE-01 | 다시 열어 창의 「운영 종료」(빨간 버튼) | 창이 닫히고 배지가 `운영 종료` 로 바뀐다. 「운영 종료」 버튼이 사라진다 |
| SC-CLOSE-02 | 캡틴 토큰으로 `GET /api/admin/studies/{A}` | `status` 가 `CLOSED`, `canClose` 가 `false`, `closeBlockedReason` 이 `ALREADY_CLOSED` |
| SC-CLOSE-03 | A 의 신청자 탭 | 완료 크루가 그대로 보이고 선택 칸이 잠겨 있다(명부는 바뀌지 않는다). 참여 중단 크루는 지금처럼 보이지 않는다 |
| SC-CLOSE-04 | 크루로 사용자 사이트 › 내 스터디룸 | A 카드가 「참여 종료」 탭에 있고 「완주」 배지가 그대로다 |
| SC-CLOSE-05 | 사용자 사이트 › 스터디 목록 | A 가 「종료」 탭에 있다(운영 종료와 종료를 사용자에게는 나누지 않는다) |
| SC-API-01 | 캡틴 토큰으로 `POST /api/admin/studies/{A}/close` 를 한 번 더 | 409 `STUDY_ALREADY_CLOSED` |
| SC-API-02 | 캡틴 토큰으로 B1 · C 에 `POST /api/admin/studies/{id}/close` | B1 은 409 `STUDY_NOT_LATEST_COHORT`, C 는 409 `STUDY_NOT_ENDED`. 두 스터디의 상태는 그대로다 |
| SC-DENY-01 | 네비게이터 · 크루 토큰으로 각각 `POST /api/admin/studies/{C}/close` | 둘 다 403 `FORBIDDEN`(상태보다 권한을 먼저 본다). C 의 상태 그대로 |

로컬 회귀 테스트: `backend/api/src/test/java/com/studyclub/api/study/AdminStudyCloseIntegrationTest`, `backend/domain/src/test/java/com/studyclub/domain/study/StudyTest` (`close_endedLatestCohort` · `close_blockedReasons`), 백오피스 `src/features/studies/CloseStudyButton.test.tsx` · `response-schema.test.ts`.
2 changes: 1 addition & 1 deletion 01-planning/_registry/policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
| 2 | `STUDY_KIND` 를 `STUDY` 에서 `STUDY_PROGRAM` 으로 이동 | [POL-0002](policies/POL-0002-study-status.md) · [POL-0003](policies/POL-0003-study-fields.md) |
| 3 | `IS_HIDDEN`·`PUBLISH_AT`·`SLUG`·`STUDY.CAPACITY`·`STUDY_DELIVERY_FORMAT` 삭제. 공개 여부는 `STATUS != DRAFT` 로 판정(`STUDY_RECRUITMENT.START_AT` 은 판정에 쓰지 않는다 — 별개 필드라 동기화 버그 여지가 있다) | [POL-0002](policies/POL-0002-study-status.md) · [POL-0003](policies/POL-0003-study-fields.md) |
| 4 | `RECRUIT_DEADLINE_AT` 을 NOT NULL 로 — 상시 모집을 두지 않는다 | [POL-0002](policies/POL-0002-study-status.md) |
| 5 | ~~`END_AT` 경과로 `ENDED` 저장 · 명부 완료 전환~~ ✅ 2026-12-05 — #591 이 반영했다(2026-12-06 정책 개정). `ENDED → CLOSED` 는 캡틴 수동 확인만(디스코드 채널 삭제를 시스템이 검증하지 않는다) — 운영 종료 버튼은 아직 없다 | [POL-0002](policies/POL-0002-study-status.md) |
| 5 | ~~`END_AT` 경과로 `ENDED` 저장 · 명부 완료 전환~~ ✅ 2026-12-05 — #591 이 반영했다(2026-12-06 정책 개정). `ENDED → CLOSED` 는 캡틴 수동 확인만(디스코드 채널 삭제를 시스템이 검증하지 않는다) — 운영 종료 버튼은 2026-12-06 ZAPP #196 으로 생겼다 | [POL-0002](policies/POL-0002-study-status.md) |
| 6 | 등록·수정 API 가 `startAt`·`discordChannelUrl`·`driveUrl` 을 입력으로 받도록 확장 | [POL-0003](policies/POL-0003-study-fields.md) |
| 7 | ~~`PARTICIPANT_ROLE` 에서 `CO_LEADER`(부반장) 삭제~~ ✅ 2026-10-09 — V35 가 남은 부반장을 `LEADER` 로 올리고 enum 에서 지웠다 | [POL-0001](policies/POL-0001-roles.md) |
| 8 | `study-recruit-status` 의 신청 상태 전제(`PENDING`·`WAITLISTED` 등) 정리 — [POL-0004](policies/POL-0004-application.md)와 지금 `study-recruit-status/spec.md` 가 서로 다른 전제를 쓰고 있어 먼저 확인 필요 | [POL-0004](policies/POL-0004-application.md) |
Expand Down
4 changes: 2 additions & 2 deletions 01-planning/_registry/policies/POL-0002-study-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ STUDY_KIND(스터디/클럽)는 기수가 아니라 프로그램의 속성이라
- **공개 취소(`OPEN → DRAFT`) 조건** — ERD 다이어그램은 「신청 0건일 때만」이고, 프로토타입은 조건
없이 언제나 허용한다. 신청이 있는 스터디를 내리면 신청자는 어떻게 되는지 정하지 못했다
([study/spec.md](../../../specs/study/spec.md#스터디-공개--공개-취소)).
- **종료일 입력 칸 · 운영 종료 버튼** — 백오피스에 아직 없다. 그전까지 종료일은 DB 에서 직접 넣는다.
- ~~**종료일 입력 칸 · 운영 종료 버튼** — 백오피스에 아직 없다. 그전까지 종료일은 DB 에서 직접 넣는다.~~ ✅ 종료일 입력 칸은 2026-12-06 #598, 운영 종료 버튼은 2026-12-06 ZAPP #196 ([study/spec.md](../../../specs/study/spec.md#스터디-운영-종료)).
- **운영 종료 이후 재개** — `CLOSED` 인 프로그램에 새 기수(새 채널)를 만드는 것은 막지 않는다. 형제
기수의 `STATUS` 는 새 기수 생성 조건이 아니다.
- **`ONGOING` 판정 방식이 실제 구현과 갈린다(#129 PR 리뷰)** — PR #114 가 이미 머지한
Expand All @@ -113,5 +113,5 @@ STUDY_KIND(스터디/클럽)는 기수가 아니라 프로그램의 속성이라
| `STUDY_KIND` | `STUDY` 컬럼(기수 단위) | `STUDY_PROGRAM` 으로 이동(프로그램 단위). 한 번 정하면 변경 불가 — [POL-0003](POL-0003-study-fields.md) |
| 공개 여부 | `IS_HIDDEN` 플래그. 등록 시 `START_AT=now` 를 채움 | `IS_HIDDEN` 삭제. 공개 = `STATUS != DRAFT`. 등록 직후는 항상 `DRAFT`(미공개)이고 `START_AT` 은 비어 있다 — 공개 때 채우고 공개 취소 때 비운다 (V49 에서 반영) |
| 상시 모집 | `RECRUIT_DEADLINE_AT` NULL 허용 | NOT NULL — 상시 모집 없음. 이어지는 참여는 클럽의 기수 이월로 표현 |
| 종료 전환 | ~~「운영자 종료 또는 `END_AT` 경과」로 `CLOSED`~~ ✅ 2026-12-05 #591 — `END_AT` 이 지나면 `ENDED` 로 저장하고 명부를 완료로 바꾼다 | `OPEN` · `ONGOING` → `ENDED` 는 `END_AT` 경과로 자동. `ENDED → CLOSED` 는 캡틴 수동 확인만 (버튼 미구현) |
| 종료 전환 | ~~「운영자 종료 또는 `END_AT` 경과」로 `CLOSED`~~ ✅ 2026-12-05 #591 — `END_AT` 이 지나면 `ENDED` 로 저장하고 명부를 완료로 바꾼다 | `OPEN` · `ONGOING` → `ENDED` 는 `END_AT` 경과로 자동. `ENDED → CLOSED` 는 캡틴 수동 확인만 — ✅ 2026-12-06 ZAPP #196 백오피스 「운영 종료」 버튼 |
| 모집 회차 | 1개로 가정 | 여러 개 허용(추가 모집). id 최대인 회차 기준으로 판정 — [study-recruit-status](../../../specs/study-recruit-status/spec.md) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.studyclub.api.study;

import com.studyclub.api.participant.StudyParticipantCompletionService;
import com.studyclub.common.error.BusinessException;
import com.studyclub.common.error.ErrorCode;
import com.studyclub.domain.study.Study;
import com.studyclub.domain.study.StudyRepository;
import java.time.Instant;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* 백오피스 「운영 종료」 — 종료(ENDED)된 최신 기수를 운영 종료(CLOSED)로 바꾼다. 캡틴이 디스코드 채널을 지운 뒤 누르는 수동 전환이라 채널 삭제는 보지 않는다
* (specs/study/spec.md 「운영 종료」).
*/
@Service
public class AdminStudyCloseService {

private final StudyRepository studyRepository;
private final StudyCaptainGuard studyCaptainGuard;
private final StudyParticipantCompletionService completionService;

public AdminStudyCloseService(
StudyRepository studyRepository,
StudyCaptainGuard studyCaptainGuard,
StudyParticipantCompletionService completionService) {
this.studyRepository = studyRepository;
this.studyCaptainGuard = studyCaptainGuard;
this.completionService = completionService;
}

/**
* 스터디 행을 잠그고 바꾼다 — 두 번 누름과 완료 전환 스케줄러가 줄을 선다. 같은 프로그램의 새 기수 등록과는 겹쳐도 잠그지 않는다: 운영 종료 뒤 새 기수를 여는
* 것은 막지 않는 재개라 결과가 같다.
*/
@Transactional
public void close(Long accountId, Long studyId) {
studyCaptainGuard.assertCaptain(accountId, "스터디 운영 종료 권한이 없습니다.");
Study study =
studyRepository
.findByIdForUpdate(studyId)
.orElseThrow(
() ->
new BusinessException(
ErrorCode.NOT_FOUND, "스터디를 찾을 수 없습니다."));
// 완료 전환은 CLOSED 를 건너뛰어, 닫은 뒤에 남은 참여 중 행은 영영 완료로 넘어가지 못한다. 그래서 닫기 전에 같은 트랜잭션에서 한 번 돌린다 —
// 종료일이 지나고 스케줄러가 돌기 전 1분이거나 종료 뒤 명부에 더한 행이 있을 때만 바뀌고, 보통은 아무것도 바꾸지 않는다
completionService.complete(studyId, Instant.now());
study.close(studyRepository.findLatestIdByProgramId(study.getProgramId()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.springframework.web.bind.annotation.RestController;

/**
* 백오피스의 스터디 — 목록·상세·등록·수정·삭제. 캡틴만 ({@code @RequireAdmin}).
* 백오피스의 스터디 — 목록·상세·등록·수정·삭제·공개·운영 종료. 캡틴만 ({@code @RequireAdmin}).
*
* <p>사용자 사이트는 {@link StudyController}({@code /api/studies})를 쓴다. 로직은 {@link StudyService} 를 같이 쓴다 —
* specs/study/spec.md 「관객별 엔드포인트」 · specs/authz-guards/spec.md
Expand Down Expand Up @@ -61,16 +61,19 @@ public class AdminStudyController {
private final StudyService studyService;
private final StudyDiscordLinkService studyDiscordLinkService;
private final DisplayTimeZoneResolver displayTimeZoneResolver;
private final AdminStudyCloseService adminStudyCloseService;

public AdminStudyController(
BackofficeStudyListService backofficeStudyListService,
StudyService studyService,
StudyDiscordLinkService studyDiscordLinkService,
DisplayTimeZoneResolver displayTimeZoneResolver) {
DisplayTimeZoneResolver displayTimeZoneResolver,
AdminStudyCloseService adminStudyCloseService) {
this.backofficeStudyListService = backofficeStudyListService;
this.studyService = studyService;
this.studyDiscordLinkService = studyDiscordLinkService;
this.displayTimeZoneResolver = displayTimeZoneResolver;
this.adminStudyCloseService = adminStudyCloseService;
}

@Operation(
Expand Down Expand Up @@ -214,4 +217,15 @@ public ResponseEntity<Void> unpublish(
studyService.unpublish((Long) authentication.getPrincipal(), studyId);
return ResponseEntity.noContent().build();
}

@Operation(
summary = "스터디 운영 종료",
description =
"ADMIN만 호출 가능. ENDED → CLOSED, 되돌릴 수 없다. 그 프로그램의 최신(ID 최대) 기수만."
+ " 디스코드 채널 삭제는 확인하지 않는다. 완료된 명부는 바꾸지 않고, 남은 완료 전환만 닫기 전에 마친다.")
@PostMapping("/{studyId}/close")
public ResponseEntity<Void> close(@PathVariable Long studyId, Authentication authentication) {
adminStudyCloseService.close((Long) authentication.getPrincipal(), studyId);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.studyclub.domain.study.RecruitStatus;
import com.studyclub.domain.study.RecruitmentTimeZones;
import com.studyclub.domain.study.Study;
import com.studyclub.domain.study.StudyCloseBlockedReason;
import com.studyclub.domain.study.StudyProgram;
import java.time.Instant;

Expand Down Expand Up @@ -34,6 +35,8 @@ public record StudyDetailResponse(
Instant endAt,
String endDate,
boolean canChangeEndAt,
boolean canClose,
StudyCloseBlockedReason closeBlockedReason,
String discordChannelUrl,
String driveUrl,
boolean discordLinked) {
Expand All @@ -44,6 +47,10 @@ public record StudyDetailResponse(
*
* <p>{@code studyKind} · {@code programTitle} 은 기수가 아니라 프로그램의 값이다 — docs/erd/STUDY_PROGRAM.md.
* 콘솔 정보 탭이 「프로그램 제목 · 종류 · 변경할 수 없음」을 읽기 전용으로 보여 주는 데 쓴다.
*
* @param latestStudyIdInProgram 그 프로그램의 최신 기수 ID — 운영 종료 판정에 쓴다. {@code null} 이면 판정하지 않고 {@code
* canClose=false} · {@code closeBlockedReason=null} 로 둔다(사이트 상세 — 공개하지 않은 다음 기수가 있다는 것을
* {@code NOT_LATEST_COHORT} 로 알리지 않는다)
*/
public static StudyDetailResponse from(
Study study,
Expand All @@ -53,8 +60,14 @@ public static StudyDetailResponse from(
Integer recruitmentCapacity,
RecruitmentTimeZones recruitmentTimeZones,
boolean discordLinked,
Long latestStudyIdInProgram,
String displayTimeZone,
Instant now) {
StudyCloseBlockedReason closeBlocked =
latestStudyIdInProgram == null
? null
: study.closeBlockedReason(latestStudyIdInProgram);
boolean canClose = latestStudyIdInProgram != null && closeBlocked == null;
return new StudyDetailResponse(
study.getId(),
study.getProgramId(),
Expand Down Expand Up @@ -84,6 +97,8 @@ public static StudyDetailResponse from(
? null
: StudyDateInput.lastDayOf(study.getEndAt(), displayTimeZone).toString(),
study.canChangeEndAt(now),
canClose,
closeBlocked,
study.getDiscordChannelUrl(),
study.getDriveUrl(),
discordLinked);
Expand Down Expand Up @@ -117,6 +132,8 @@ public StudyDetailResponse withoutPrivateLinks() {
endAt,
endDate,
canChangeEndAt,
canClose,
closeBlockedReason,
null,
null,
discordLinked);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public StudyDetailResponse getDetail(Long studyId, Long accountId, String displa
&& !studyCaptainGuard.isCaptainOrNavigator(accountId, studyId)) {
throw new BusinessException(ErrorCode.NOT_FOUND, "스터디를 찾을 수 없습니다.");
}
StudyDetailResponse detail = toDetail(study, displayTimeZone);
StudyDetailResponse detail = toDetail(study, displayTimeZone, false);
return studyCaptainGuard.canSeePrivateLinks(accountId, studyId)
? detail
: detail.withoutPrivateLinks();
Expand All @@ -430,11 +430,12 @@ public StudyDetailResponse getDetail(Long studyId, Long accountId, String displa
/** 백오피스 상세 — 권한은 {@code @RequireAdmin}. DRAFT 도 보여 준다. */
@Transactional(readOnly = true)
public StudyDetailResponse getDetailForBackOffice(Long studyId, String displayTimeZone) {
return toDetail(findStudy(studyId), displayTimeZone);
return toDetail(findStudy(studyId), displayTimeZone, true);
}

// 상세 본문 — 권한을 검사하지 않는다
private StudyDetailResponse toDetail(Study study, String displayTimeZone) {
// 상세 본문 — 권한을 검사하지 않는다. 운영 종료 판정은 백오피스 상세에만 싣는다
private StudyDetailResponse toDetail(
Study study, String displayTimeZone, boolean withCloseJudgement) {
StudyRecruitment latestRecruitment =
studyRecruitmentRepository
.findFirstByStudyIdOrderByIdDesc(study.getId())
Expand All @@ -458,6 +459,9 @@ private StudyDetailResponse toDetail(Study study, String displayTimeZone) {
? latestRecruitment.timeZones()
: RecruitmentTimeZones.UNSET,
studyDiscordLinkRepository.existsByStudyId(study.getId()),
withCloseJudgement
? studyRepository.findLatestIdByProgramId(study.getProgramId())
: null,
displayTimeZone,
Instant.now());
}
Expand Down
Loading
Loading