Skip to content
2 changes: 1 addition & 1 deletion 01-planning/_registry/policies/POL-0003-study-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
| 모집 마감일 | **필수** | 날짜 | 모집 상태 판정 축 ([POL-0002](POL-0002-study-status.md)). **그 스터디 시간대의 그날이 끝날 때**까지다 — 시각은 받지 않는다 ([POL-0006](POL-0006-timezone.md)) |
| 모집 정원 | 선택 | 수 | 비우면 제한 없음. **모집 회차의 정원**이다 — 회차가 여럿이면 회차마다 따로 정한다. 반별 정원은 `STUDY_GROUP` |
| 진행 시작일 | 선택 | 날짜 | 모임이 실제로 시작하는 날. 모집 마감일·진행 일정과는 다른 값 |
| 진행 종료일 | 선택 | 날짜 | 백오피스에서만 받는다. 그날까지 진행하고, 지나면 시스템이 종료로 저장한다. 끝난 스터디는 바꿀 수 없다 ([POL-0002](POL-0002-study-status.md), 2026-12-06 ZAPP #195) |
| 디스코드 채널 주소 | 선택 | URL | 참고용 링크 하나. 자동화(채널 목록 조회·삭제 감지)의 근거로 쓰지 않는다 — [POL-0002](POL-0002-study-status.md) |
| 자료 드라이브 주소 | 선택 | URL | 참고용 링크 |

Expand All @@ -33,7 +34,6 @@
| 신청 링크 | 사이트 자체가 신청 창구. 외부 폼 링크를 받지 않는다 |
| 모집 시작일 | 모집 상태를 가르는 축은 마감일 하나다. 모집 시작 = 공개(아래) |
| 공개일 | 등록하면 항상 미공개로 들어가고, 공개는 목록에서 캡틴이 따로 켠다. 예약 공개는 없다 — 준비가 됐는지는 날짜가 판단할 수 없다 |
| 진행 종료일 | 회차 일정을 규격화된 폼으로 받지 않아 종료일을 알 수 없다. 종료는 캡틴·네비게이터가 직접 전환한다([POL-0002](POL-0002-study-status.md)) |

## 판정 규칙

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ public StudyDetailResponse detail(
summary = "스터디 등록",
description =
"ADMIN만 호출 가능. 등록 후 STATUS=DRAFT 로 비공개. 디스코드 봇이 설정돼 있으면 등록 뒤"
+ " 디스코드 스터디를 만들어 연결한다 (실패해도 201). 날짜만 보낸 마감 · 시작일은 displayTimeZone(헤더)"
+ " 달력으로 해석한다.")
+ " 디스코드 스터디를 만들어 연결한다 (실패해도 201). 날짜만 보낸 마감 · 시작일 · 종료일은"
+ " displayTimeZone(헤더) 달력으로 해석한다 — 종료일은 그다음 날 0시에 끝난다.")
@PostMapping
public ResponseEntity<Void> create(
@Valid @RequestBody StudyCreateRequest request,
Expand All @@ -176,7 +176,7 @@ public ResponseEntity<Void> create(
summary = "스터디 수정 (백오피스)",
description =
"ADMIN만 호출 가능 — 네비게이터는 PATCH /api/studies/{studyId} 를 쓴다 (POL-0001)."
+ " 보낸 필드만 반영한다.")
+ " 보낸 필드만 반영한다. 끝난 스터디의 종료일(endAt)은 바꿀 수 없다 (409 STUDY_ENDED).")
@PatchMapping("/{studyId}")
public ResponseEntity<Void> update(
@PathVariable Long studyId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public StudyDetailResponse detail(
description =
"캡틴 또는 그 스터디의 네비게이터(LEADER)."
+ " 백오피스는 PATCH /api/admin/studies/{studyId} 를 쓰고 캡틴만 통과한다."
+ " 날짜만 보낸 마감 · 시작일은 프로필 → displayTimeZone Query → 서울 기준으로 해석한다.")
+ " 날짜만 보낸 마감 · 시작일은 프로필 → displayTimeZone Query → 서울 기준으로 해석한다."
+ " 종료일(endAt)은 받지 않는다 (400) — 백오피스에서만 바꾼다.")
@SecurityRequirement(name = "bearerAuth")
@RequireCaptainOrNavigator
@PatchMapping("/{studyId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
* (docs/flows/image-upload.md). 비우면 썸네일 없음.
*
* <p>{@code recruitmentTimeZones} 를 비우면 모집 시간대 미정({@code unset})이다. {@code recruitDeadline} ·
* {@code startAt} 은 순간 또는 날짜({@link StudyDateInput}) — 날짜면 요청의 {@code displayTimeZone} 으로 해석한다
* (specs/timezone/spec.md §7).
* {@code startAt} · {@code endAt} 은 순간 또는 날짜({@link StudyDateInput}) — 날짜면 요청의 {@code
* displayTimeZone} 으로 해석한다 (specs/timezone/spec.md §7). {@code endAt} 을 비우면 끝나지 않는다.
*/
public record StudyCreateRequest(
Long studyProgramId,
Expand All @@ -40,5 +40,6 @@ public record StudyCreateRequest(
RecruitmentTimeZonesRequest recruitmentTimeZones,
Integer capacity,
StudyDateInput startAt,
StudyDateInput endAt,
@Size(max = 2048) String discordChannelUrl,
@Size(max = 2048) String driveUrl) {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import java.time.format.DateTimeParseException;

/**
* 마감 · 시작일 입력. ISO-8601 순간({@code 2026-09-16T14:59:59Z})은 그대로, 날짜만({@code 2026-09-16}) 보내면 요청의 표시
* 시간대 달력으로 해석한다 — 마감은 23:59:59, 시작은 00:00:00 (PRD §6 · specs/timezone/spec.md §7).
* 마감 · 시작일 · 종료일 입력. ISO-8601 순간({@code 2026-09-16T14:59:59Z})은 그대로, 날짜만({@code 2026-09-16}) 보내면
* 요청의 표시 시간대 달력으로 해석한다 — 마감은 23:59:59, 시작은 00:00:00, 종료는 다음 날 00:00:00 (PRD §6 ·
* specs/timezone/spec.md §7 · specs/study/spec.md).
*/
public record StudyDateInput(Instant instant, LocalDate date) {

Expand Down Expand Up @@ -40,6 +41,30 @@ public Instant toStart(String displayTimeZone) {
return instant != null ? instant : TimeZoneFormatService.startOfDay(date, displayTimeZone);
}

/** 날짜는 그날까지 진행한다는 뜻이라 다음 날 0시에 끝난다 — 클럽 기수의 「다음 달 1일 0시」와 같은 방식. */
public Instant toEnd(String displayTimeZone) {
return instant != null
? instant
: TimeZoneFormatService.startOfDay(date.plusDays(1), displayTimeZone);
}

/**
* {@link #toEnd} 의 반대 — 종료 순간의 1ms 앞 날짜, 곧 마지막 진행일. 클럽 기수의 「다음 달 1일 0시」는 그달 말일이다. 백오피스 정보 탭의
* 종료일 칸 (`endAtToLastDay`)과 같은 규칙이다.
*/
public static LocalDate lastDayOf(Instant endAt, String displayTimeZone) {
return TimeZoneFormatService.localDate(endAt.minusMillis(1), displayTimeZone);
}

/** 마감 순간이 속한 날이 끝나는 순간(그다음 날 0시). 종료가 이보다 늦어야 마지막 진행일이 마감일 뒤다. */
public static Instant dayEndOf(Instant deadline, String displayTimeZone) {
return deadline == null
? null
: TimeZoneFormatService.startOfDay(
TimeZoneFormatService.localDate(deadline, displayTimeZone).plusDays(1),
displayTimeZone);
}

@JsonValue
public String value() {
return instant != null ? instant.toString() : date.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public record StudyDetailResponse(
Instant startAt,
FormattedInstant startAtFormatted,
Instant endAt,
String endDate,
boolean canChangeEndAt,
String discordChannelUrl,
String driveUrl,
boolean discordLinked) {
Expand Down Expand Up @@ -77,6 +79,11 @@ public static StudyDetailResponse from(
study.getStartAt(),
TimeZoneFormatService.format(study.getStartAt(), displayTimeZone),
study.getEndAt(),
// 종료일 칸과 같은 마지막 진행일 — 헤더가 종료 순간(다음 날 0시)을 보이면 하루 늦게 저장된 줄 안다
study.getEndAt() == null
? null
: StudyDateInput.lastDayOf(study.getEndAt(), displayTimeZone).toString(),
study.canChangeEndAt(now),
study.getDiscordChannelUrl(),
study.getDriveUrl(),
discordLinked);
Expand Down Expand Up @@ -108,6 +115,8 @@ public StudyDetailResponse withoutPrivateLinks() {
startAt,
startAtFormatted,
endAt,
endDate,
canChangeEndAt,
null,
null,
discordLinked);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.studyclub.domain.study.StudyRepository;
import com.studyclub.domain.study.StudyStatus;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -109,24 +110,29 @@ public Long create(Long accountId, StudyCreateRequest request, String displayTim
: request.recruitDeadline().toDeadline(displayTimeZone);
Instant startAt =
request.startAt() == null ? null : request.startAt().toStart(displayTimeZone);
Instant endAt = request.endAt() == null ? null : request.endAt().toEnd(displayTimeZone);
RecruitmentTimeZones recruitmentTimeZones =
request.recruitmentTimeZones() == null
? RecruitmentTimeZones.UNSET
: request.recruitmentTimeZones().toDomain();
Instant recruitDeadlineDayEnd = StudyDateInput.dayEndOf(recruitDeadline, displayTimeZone);
// 저장 전에 어긴 필드를 모두 모아 한 번에 답한다 — 하나씩 답하면 고쳐 보낼 때마다 다음 오류가 나온다 (스펙 등록 400)
List<String> violations = new ArrayList<>();
if (recruitDeadline != null && !now.isBefore(recruitDeadline)) {
throw new BusinessException(
ErrorCode.INVALID_INPUT, "recruitDeadline: 모집 마감일은 미래여야 합니다.");
violations.add("recruitDeadline: 모집 마감일은 미래여야 합니다.");
}
if (request.capacity() != null && request.capacity() < 1) {
throw new BusinessException(ErrorCode.INVALID_INPUT, "capacity: 1 이상의 정수여야 합니다.");
violations.add("capacity: 1 이상의 정수여야 합니다.");
}
if (!isHttpUrlOrBlank(request.discordChannelUrl())) {
throw new BusinessException(
ErrorCode.INVALID_INPUT, "discordChannelUrl: http(s):// 로 시작하는 주소여야 합니다.");
violations.add("discordChannelUrl: http(s):// 로 시작하는 주소여야 합니다.");
}
if (!isHttpUrlOrBlank(request.driveUrl())) {
throw new BusinessException(
ErrorCode.INVALID_INPUT, "driveUrl: http(s):// 로 시작하는 주소여야 합니다.");
violations.add("driveUrl: http(s):// 로 시작하는 주소여야 합니다.");
}
violations.addAll(Study.newPeriodViolations(startAt, endAt, recruitDeadlineDayEnd, now));
if (!violations.isEmpty()) {
throw new BusinessException(ErrorCode.INVALID_INPUT, String.join(", ", violations));
}

String trimmedTitle = request.title().trim();
Expand All @@ -149,7 +155,7 @@ public Long create(Long accountId, StudyCreateRequest request, String displayTim
.ownerCaptainId(accountId)
.build());

if (startAt != null) study.changeStartAt(startAt);
study.changePeriod(startAt, endAt, recruitDeadlineDayEnd, true, now);
if (request.discordChannelUrl() != null && !request.discordChannelUrl().isBlank()) {
study.changeDiscordChannelUrl(request.discordChannelUrl());
}
Expand Down Expand Up @@ -211,23 +217,41 @@ private StudyProgram resolveProgram(StudyCreateRequest request, String trimmedTi
return program;
}

/** 사용자 사이트 — 권한은 {@code @RequireCaptainOrNavigator} 가 검사한다. */
/**
* 사용자 사이트 — 권한은 {@code @RequireCaptainOrNavigator} 가 검사한다. 종료일은 받지 않는다 — 종료일이 지나면 명부 전체가 완료로
* 바뀌어 되돌릴 수 없어, 캡틴이 백오피스에서만 넣는다 (POL-0002).
*/
@Transactional
public void updateFromSite(
Long accountId, Long studyId, StudyUpdateRequest request, String displayTimeZone) {
// 인증 → 존재 순서. 없는 스터디에 네비게이터 판정을 먼저 돌리면 404 대신 403 이 나간다
if (!accountRepository.existsById(accountId)) {
throw new BusinessException(ErrorCode.UNAUTHORIZED);
}
Study study = findStudy(studyId);
// 시작일 · 마감일을 바꾸면 행을 잠근다 — 동시에 들어온 종료일 변경과 서로 옛 값으로 비교해 순서가 어긋난 채 저장되지 않게
Study study =
request.startAtPresent() || request.recruitDeadline() != null
? findStudyForUpdate(studyId)
: findStudy(studyId);
if (request.endAtPresent()) {
throw new BusinessException(ErrorCode.INVALID_INPUT, "endAt: 종료일은 백오피스에서만 바꿀 수 있습니다.");
}
applyUpdate(study, request, displayTimeZone);
}

/** 백오피스 — 권한은 {@code @RequireAdmin} 가 검사한다. 썸네일은 백오피스에서만 바꾼다. */
@Transactional
public void updateFromBackOffice(
Long accountId, Long studyId, StudyUpdateRequest request, String displayTimeZone) {
Study study = findStudy(studyId);
// 시작일 · 종료일 · 마감일을 바꾸면 행을 잠근다 — 완료 전환 스케줄러도 이 행을 잠그고 ENDED 로 저장하므로, 잠그지 않으면 종료
// 순간에 걸친 요청이 「끝난 판정」을 지나 ENDED 인 스터디에 미래 종료일을 덮어쓸 수 있다. 동시에 들어온 기간 변경끼리 서로 옛
// 값으로 비교해 순서가 어긋난 채 저장되는 것도 막는다
Study study =
request.startAtPresent()
|| request.endAtPresent()
|| request.recruitDeadline() != null
? findStudyForUpdate(studyId)
: findStudy(studyId);
applyUpdate(study, request, displayTimeZone);
if (request.thumbnailFileIdPresent()) {
replaceThumbnail(
Expand Down Expand Up @@ -265,6 +289,7 @@ private void applyUpdate(Study study, StudyUpdateRequest request, String display
: request.recruitDeadline().toDeadline(displayTimeZone);
Instant startAt =
request.startAt() == null ? null : request.startAt().toStart(displayTimeZone);
Instant endAt = request.endAt() == null ? null : request.endAt().toEnd(displayTimeZone);
RecruitmentTimeZones recruitmentTimeZones =
!request.recruitmentTimeZonesPresent()
? null
Expand Down Expand Up @@ -299,7 +324,21 @@ private void applyUpdate(Study study, StudyUpdateRequest request, String display
request.description(),
request.category(),
request.schedule());
if (request.startAtPresent()) study.changeStartAt(startAt);
if (request.startAtPresent() || request.endAtPresent() || recruitDeadline != null) {
// 마감일은 최신 모집 회차 기준 — 이 요청이 바꾸면 새 값, 아니면 저장된 값
Instant deadline =
recruitDeadline != null
? recruitDeadline
: studyRecruitmentRepository
.findLatestRecruitDeadlineByStudyId(study.getId())
.orElse(null);
study.changePeriod(
request.startAtPresent() ? startAt : study.getStartAt(),
request.endAtPresent() ? endAt : study.getEndAt(),
StudyDateInput.dayEndOf(deadline, displayTimeZone),
recruitDeadline != null,
Instant.now());
}
if (request.discordChannelUrlPresent()) {
study.changeDiscordChannelUrl(request.discordChannelUrl());
}
Expand Down Expand Up @@ -431,7 +470,7 @@ public void publish(Long accountId, Long studyId) {
throw new BusinessException(ErrorCode.CONFLICT, "DRAFT 상태인 스터디만 공개할 수 있습니다.");
}
validateApplicationFormHasQuestions(study.getApplicationForm());
study.publish();
study.publish(Instant.now());
studyRecruitmentRepository
.findFirstByStudyIdOrderByIdDesc(studyId)
.orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND, "모집 회차를 찾을 수 없습니다."))
Expand Down Expand Up @@ -461,6 +500,12 @@ private Study findStudy(Long studyId) {
.orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND, "스터디를 찾을 수 없습니다."));
}

private Study findStudyForUpdate(Long studyId) {
return studyRepository
.findByIdForUpdate(studyId)
.orElseThrow(() -> new BusinessException(ErrorCode.NOT_FOUND, "스터디를 찾을 수 없습니다."));
}

private static boolean isHttpUrlOrBlank(String value) {
return value == null || value.isBlank() || HTTP_URL.matcher(value.trim()).matches();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
*
* <p>title·oneLineSummary·description·category·recruitDeadline·schedule 은 null 이면 바꾸지 않는다.
*
* <p>capacity·startAt·recruitmentTimeZones·discordChannelUrl·driveUrl 은 스펙상 {@code null} 이 "제한
* 없음·미정으로 되돌림"이다. 그래서 "키를 안 보냄"과 "null 을 보냄"을 구분해야 하고, record 로는 둘이 같아진다. Jackson 은 JSON 에 키가 있을 때만
* setter 를 부르므로 setter 가 {@code *Present} 표시를 남긴다.
* <p>capacity·startAt·endAt·recruitmentTimeZones·discordChannelUrl·driveUrl 은 스펙상 {@code null} 이
* "제한 없음·미정·끝나지 않음으로 되돌림"이다. 그래서 "키를 안 보냄"과 "null 을 보냄"을 구분해야 하고, record 로는 둘이 같아진다. Jackson 은 JSON
* 에 키가 있을 때만 setter 를 부르므로 setter 가 {@code *Present} 표시를 남긴다.
*/
public class StudyUpdateRequest {

Expand All @@ -29,6 +29,11 @@ public class StudyUpdateRequest {
private boolean capacityPresent;
private StudyDateInput startAt;
private boolean startAtPresent;

/** 종료일. 키가 있고 {@code null} 이면 끝나지 않음으로 되돌린다. 백오피스 수정에서만 받는다. */
private StudyDateInput endAt;

private boolean endAtPresent;
private RecruitmentTimeZonesRequest recruitmentTimeZones;
private boolean recruitmentTimeZonesPresent;

Expand Down Expand Up @@ -103,6 +108,14 @@ public boolean startAtPresent() {
return startAtPresent;
}

public StudyDateInput endAt() {
return endAt;
}

public boolean endAtPresent() {
return endAtPresent;
}

public RecruitmentTimeZonesRequest recruitmentTimeZones() {
return recruitmentTimeZones;
}
Expand Down Expand Up @@ -161,6 +174,11 @@ public void setStartAt(StudyDateInput startAt) {
this.startAtPresent = true;
}

public void setEndAt(StudyDateInput endAt) {
this.endAt = endAt;
this.endAtPresent = true;
}

public void setRecruitmentTimeZones(RecruitmentTimeZonesRequest recruitmentTimeZones) {
this.recruitmentTimeZones = recruitmentTimeZones;
this.recruitmentTimeZonesPresent = true;
Expand Down
Loading
Loading