Skip to content

[feature] 약관 조회 API 추가 - #73

Open
gihhyeon wants to merge 3 commits into
developfrom
feat/consent-document-api
Open

gihhyeon wants to merge 3 commits into
developfrom
feat/consent-document-api

Conversation

@gihhyeon

@gihhyeon gihhyeon commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

📌 개요 (why, what)

  • 클라이언트가 정적 빌드로 바뀌면 노션에서 약관을 받아오던 경로가 사라지므로, 서버에서 약관을 내려주는 API를 추가했습니다.

🛠️ 구현 방법 (how)

  • GET /api/v1/consent-documents: 약관 유형별 활성 문서 1건씩 본문(마크다운)과 버전을 배열로 반환합니다.
    • 순서는 개인정보 처리방침 → 서비스 이용약관으로 고정합니다.
    • 한 유형이라도 활성 문서가 없으면 404(CONSENT_003)를 반환합니다.
  • consent_document에 is_active 컬럼을 추가해 유형별로 지금 내려줄 문서를 지정합니다.
    • 지난 버전은 사용자가 동의한 본문의 근거이므로 지우지 않고 비활성으로 둡니다.
  • 버전은 결과 제출 시 동의 버전(consents[].version)과 같은 v1.0.0 형식이며, Swagger 설명에도 명시했습니다.
  • consent_document.content를 NOT NULL로 변경했습니다.

⚠️ dev/prod 직접 실행 필요

배포 후(is_active 컬럼 생성 확인 후) 실행합니다. 배포 전 consent_document 테이블이 비어 있어야 ddl-auto: update가 NOT NULL 컬럼을 추가할 수 있습니다.

-- 1. 본문 필수 (ddl-auto: update는 기존 컬럼 제약을 바꾸지 않음)
ALTER TABLE consent_document ALTER COLUMN content SET NOT NULL;

-- 2. 유형당 활성 문서 최대 1건 보장 (JPA로는 조건부 인덱스를 만들 수 없음)
CREATE UNIQUE INDEX uk_consent_document_active_type ON consent_document (type) WHERE is_active;

-- 3. 현행 약관 적재
INSERT INTO consent_document (type, version, content, is_active, created_at) VALUES
('PRIVACY_POLICY',   'v1.0.0', $body$<개인정보 처리방침 마크다운>$body$, true, now()),
('TERMS_OF_SERVICE', 'v1.0.0', $body$<서비스 이용약관 마크다운>$body$, true, now());

약관 개정 / 롤백 시 (끄기를 먼저 해야 인덱스에 걸리지 않음)

-- 개정
BEGIN;
UPDATE consent_document SET is_active = false WHERE type = 'PRIVACY_POLICY' AND is_active;
INSERT INTO consent_document (type, version, content, is_active, created_at)
VALUES ('PRIVACY_POLICY', 'v1.1.0', $body$<개정 본문>$body$, true, now());
COMMIT;

-- 롤백
BEGIN;
UPDATE consent_document SET is_active = false WHERE type = 'PRIVACY_POLICY' AND is_active;
UPDATE consent_document SET is_active = true WHERE type = 'PRIVACY_POLICY' AND version = 'v1.0.0';
COMMIT;

🤔 검토한 대안과 선택 이유 (trade-off)

대안 장점 단점 선택 여부
버전 문자열로 최신 판단 별도 컬럼 없음 v1.10.0 < v1.9.0 문자 비교 오류, 날짜 형식 전환 시 깨짐 ❌
나중에 넣은 행(id 최댓값)을 최신으로 판단 별도 컬럼 없음 롤백하려면 새 버전 행을 지워야 해 동의 근거가 사라짐 ❌
is_active 컬럼으로 활성 문서 지정 롤백/시행일 전 미리 적재 가능, 지난 버전 보존 교체 시 끄기/켜기 쿼리 필요, 인덱스 수동 생성 ✅
약관 파일을 저장소에 두고 서버 시작 시 자동 적재 수동 쿼리 없음, 변경 이력이 git에 남음 개정마다 배포 필요, 작업 범위 증가 ❌ (개정 빈도가 낮아 수동 적재로 충분)

💭 리뷰 포인트

파일/영역 검토 내용 리뷰 요청 사항
ConsentDocument.version 버전 형식 v1.0.0 날짜(시행일) 형식 전환 여부 합의
DB 적재 인덱스 생성, 적재, 교체를 dev/prod 직접 실행 실행 주체/시점 합의

📚 Reference (Optional)

@gihhyeon
gihhyeon requested a review from kyer5 as a code owner September 30, 2026 12:45
@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Repository: Nexters/gotggam-server/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: e7d39784-5635-4f8a-b6e4-d55630a2c91d
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gihhyeon gihhyeon self-assigned this Sep 30, 2026
@gihhyeon gihhyeon added the 💫 feat 기능 구현 이슈 label Sep 30, 2026

@kyer5 kyer5 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다 ~!
코멘트 확인 부탁드립니닷

Comment on lines +62 to +71

// 버전 문자열은 정렬 기준으로 믿을 수 없어(v1.10.0 < v1.9.0, 날짜 형식 전환 가능성) 나중에 넣은 행을 최신으로 본다
@Transactional(readOnly = true)
public List<ConsentDocumentResponse> getLatestDocuments() {
return Arrays.stream(ConsentType.values())
.map(type -> consentDocumentRepository.findFirstByTypeOrderByIdDesc(type)
.orElseThrow(() -> new BusinessException(ConsentErrorCode.CONSENT_DOCUMENT_NOT_FOUND)))
.map(ConsentDocumentResponse::from)
.toList();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConsentDocument에 isActive(또는 active) boolean 컬럼을 추가한 후, 해당 컬럼을 기준으로 판별하는 방향은 어떨까요?

단순히 findFirstByTypeOrderByIdDesc로 "최신 = id 최댓값"을 판단하는 방식은 과거 버전으로 롤백하거나, 수동으로 활성 버전을 지정해야 하는 케이스 등에서 대응이 꼬이는 이슈가 발생할 수 있을 것 같아요 ..!

활성화 여부 컬럼 추가와 함께

  • 활성 문서 교체 로직(새 문서 활성화 + 기존 문서 비활성화를 같은 트랜잭션에서 처리)
  • DB에서 type당 is_active=true가 최대 1건이도록 보장하는 partial unique index
    를 적용하여 도입하는 방향성이 좀 더 적절하다고 생각합니다!

기현님 의견도 여쭤봅니당 ~~

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 의견 같습니다!
id 방식은 롤백하려면 새 버전 행을 지워야 해서, 그 버전에 동의한 본문 근거가 사라지는 문제는 놓쳤네요ㅠㅠ
반영해뒀습니다~

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영 감사합니다 ~!

배포 후에 dev, prod DB에 partial unique index 설정해주시면 좋을 것 같아요!
지금 active 교체를 DB에서 직접 하다보니, 실수로 active 문서를 2건 이상 등록하는 상황을 막기 위해 제약을 걸어둬야 할 것 같습니당

CREATE UNIQUE INDEX uk_consent_document_active_type                                    
      ON consent_document (type)                                                         
      WHERE is_active = true;

이런 수동 DDL이 앞으로도 종종 생길 것 같아서, 추후에 마이그레이션 도구 도입도 같이 얘기해보면 좋을 것 같아요 ㅎㅎ

고생하셨습니다 ~~

@gihhyeon gihhyeon changed the title [feat] 약관 조회 API 추가 [feature] 약관 조회 API 추가 Oct 9, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💫 feat 기능 구현 이슈

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] 약관 조회 API 추가

2 participants