Skip to content

feat(#172): add user consent item APIs - #173

Merged
Hyunstone merged 7 commits into
developfrom
fix/#172
May 25, 2026
Merged

feat(#172): add user consent item APIs#173
Hyunstone merged 7 commits into
developfrom
fix/#172

Conversation

@Hyunstone

Copy link
Copy Markdown
Collaborator

Summary

  • AgreeUser/user_agreeConsentItem/UserConsent 모델로 교체했습니다.
  • GET /api/consents, PUT /api/users/consents를 추가하고 /api/users/join에서 선택 동의 저장을 지원했습니다.
  • 가입 실패 시 이미 업로드된 프로필 이미지를 보상 삭제하도록 처리했습니다.
  • 선택 동의 seed를 한국어 노출명으로 추가하고 ERD lifecycle 문서를 갱신했습니다.

Tests

  • sh gradlew test --tests com.mogak.spring.web.controller.UserControllerTest
  • sh gradlew clean test

Risk

  • 운영 DB의 기존 user_agree drop/migration은 baseline 변경만으로 자동 반영되지 않으므로 별도 배포 절차가 필요합니다.
  • ConsentItem.displayOrder는 nullable이라 운영 데이터에서 null active 항목이 생기면 정렬 정책 확인이 필요합니다.

Follow-up

  • 운영 DB 반영 시 user_agree 정리 또는 migration 계획을 별도 확정해야 합니다.

Closes #172

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

사용자 약관/선택 동의 모델을 ConsentItem/UserConsent 기반으로 재설계하고, 동의 항목 조회 및 사용자 동의 변경 API를 추가하며 회원가입 플로우에서 동의 저장과 업로드된 프로필 이미지의 보상 삭제를 지원하는 PR입니다.

Changes:

  • 동의 마스터/사용자 동의 엔티티(ConsentItem, UserConsent) 및 서비스/리포지토리 추가, 기존 AgreeUser 제거
  • GET /api/consents, PUT /api/users/consents 추가 및 회원가입(/api/users/join)에서 동의 목록 전달/저장 지원
  • 회원가입 실패 시 업로드된 프로필 이미지 삭제(보상 트랜잭션) 및 관련 테스트/시드/ERD 문서 갱신

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/test/java/com/mogak/spring/web/controller/UserControllerTest.java 회원가입 multipart 요청에 consents 전달 및 실패 시 이미지 삭제 보상 동작 테스트 추가
src/test/java/com/mogak/spring/web/controller/ConsentControllerTest.java consents 조회/갱신 API의 컨트롤러 계약 테스트 추가
src/test/java/com/mogak/spring/service/UserServiceImplTest.java UserServiceImpl에 ConsentService 의존성 추가에 따른 테스트 픽스처 갱신
src/test/java/com/mogak/spring/service/ConsentServiceImplTest.java ConsentServiceImpl의 항목 조회/저장/갱신/예외 케이스 단위 테스트 추가
src/test/java/com/mogak/spring/config/SecurityConfigTest.java /api/consents 공개 엔드포인트 및 join 시그니처 변경 반영
src/main/java/com/mogak/spring/web/dto/userdto/UserCreateRequest.java 회원가입 요청 DTO에 consents 추가 및 command 변환 로직 추가
src/main/java/com/mogak/spring/web/dto/consentdto/UserConsentUpdateRequest.java 사용자 동의 변경 요청 DTO 및 command 변환 로직 추가
src/main/java/com/mogak/spring/web/dto/consentdto/UserConsentAgreementRequest.java consentItemId/agreed 입력 DTO 추가
src/main/java/com/mogak/spring/web/dto/consentdto/ConsentItemResponse.java 동의 항목 응답 DTO 추가
src/main/java/com/mogak/spring/web/controller/UserController.java 회원가입 실패 시 업로드 이미지 삭제(보상) 및 consents 전달 추가
src/main/java/com/mogak/spring/web/controller/ConsentController.java 동의 항목 조회/사용자 동의 갱신 API 추가
src/main/java/com/mogak/spring/service/UserServiceImpl.java 회원가입 시 ConsentService를 통해 사용자 동의 저장 호출 추가
src/main/java/com/mogak/spring/service/UserService.java 회원가입 create 오버로드(동의 목록 포함) 시그니처 추가
src/main/java/com/mogak/spring/service/result/ConsentItemResult.java 서비스 레이어 동의 항목 조회 결과 record 추가
src/main/java/com/mogak/spring/service/ConsentServiceImpl.java 동의 항목 조회 및 사용자 동의 upsert 로직 구현
src/main/java/com/mogak/spring/service/ConsentService.java 동의 관련 서비스 인터페이스 추가
src/main/java/com/mogak/spring/service/command/UserConsentCommand.java 서비스 입력용 consent command record 추가
src/main/java/com/mogak/spring/repository/UserConsentRepository.java 사용자 동의 JPA repository 추가
src/main/java/com/mogak/spring/repository/ConsentItemRepository.java 동의 항목 JPA repository 및 정렬 조회 메서드 추가
src/main/java/com/mogak/spring/global/ErrorCode.java 동의 항목 관련 에러 코드(U014~U016) 추가
src/main/java/com/mogak/spring/domain/user/UserConsent.java 사용자-항목 동의 상태 엔티티 추가(유니크 제약 포함)
src/main/java/com/mogak/spring/domain/user/ConsentItem.java 동의 항목 마스터 엔티티 추가(code 유니크)
src/main/java/com/mogak/spring/domain/user/AgreeUser.java 기존 AgreeUser 엔티티 제거
src/main/java/com/mogak/spring/config/SecurityConfig.java /api/consents 공개 접근 허용 경로에 추가
sql/seed/00_initial_data.sql consent_item 초기 seed 데이터 추가
sql/schema/00_baseline.sql baseline 스키마에 consent_item/user_consent 테이블 및 인덱스 추가, user_agree 제거
docs/operations/policies/ERD_DECISIONS_AND_LIFECYCLE.md ERD lifecycle 문서에서 동의 모델 변경 반영

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to 21
@Valid
List<UserConsentAgreementRequest> consents
) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

반영했습니다. UserCreateRequest.consentsList<@NotNull @Valid UserConsentAgreementRequest>로 변경해서 배열 내부 null 요소가 Bean Validation 단계에서 400(Z005)으로 처리되도록 했습니다. 회원가입 multipart 요청에 "consents":[null]을 보내면 userService.create()가 호출되지 않고 400을 반환하는 컨트롤러 테스트도 추가했습니다. 반영 커밋: ebf9b3e

Comment on lines +8 to +18
public record UserConsentUpdateRequest(
@Valid
List<UserConsentAgreementRequest> consents
) {
public List<UserConsentCommand> toCommands() {
if (consents == null) {
return List.of();
}
return consents.stream()
.map(UserConsentAgreementRequest::toCommand)
.toList();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

반영했습니다. UserConsentUpdateRequest.consentsList<@NotNull @Valid UserConsentAgreementRequest>로 변경했습니다. PUT /api/users/consents 요청에 "consents":[null]이 들어오면 서비스 호출 전 400(Z005)으로 차단되는 테스트를 추가했습니다. 반영 커밋: ebf9b3e

private void validateConsentCommands(List<UserConsentCommand> consents) {
Set<Long> ids = new HashSet<>();
for (UserConsentCommand consent : consents) {
if (consent.consentItemId() == null || consent.agreed() == null) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

반영했습니다. DTO validation을 통과하지 못하게 막는 것과 별도로, 서비스 계층 방어도 추가했습니다. validateConsentCommands()에서 consent == null을 먼저 검사해 INVALID_PARAMETER_ERROR로 변환합니다. 서비스 직접 호출 케이스에 대한 단위 테스트도 추가했습니다. 반영 커밋: ebf9b3e

Comment on lines +5 to +7
import org.springframework.data.jpa.repository.JpaRepository;

public interface ConsentItemRepository extends JpaRepository<ConsentItem, Long> {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

이 코멘트는 현재 head 기준으로 stale입니다. 이후 리뷰 반영 과정에서 displayOrder/display_order 자체를 제거했고, ConsentItemRepositoryfindAllByActiveTrueOrderByIdAsc()를 사용하도록 정리되어 NULL 정렬 의존이 남아 있지 않습니다. rg "displayOrder|display_order|OrderByDisplayOrder" src sql docs로 잔존 없음도 확인했습니다.

@Hyunstone
Hyunstone merged commit 3ba7713 into develop May 25, 2026
2 checks passed
@Hyunstone
Hyunstone deleted the fix/#172 branch May 25, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

사용자 선택 동의 항목 및 동의 상태 ERD/API 설계

2 participants