-
Notifications
You must be signed in to change notification settings - Fork 0
feat: [ALT-214] 회원가입 약관 동의 API 구현 #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7ae573b
feat: UserTermsAgreement 도메인 엔티티 및 포트 추가
93a0565
feat: 필수 약관 목록 조회 포트 메서드 및 구현체 추가
879f50a
feat: 회원가입 약관 동의 검증 및 저장 로직 추가
e0703f4
feat: 공개 약관 목록 조회 API 추가
1ffd035
test: 약관 동의 검증 및 회원가입 약관 연동 테스트 추가
140107c
refactor: UserTermsAgreement를 type/version 직접 저장 방식으로 변경
d459c18
refactor: GetPublishedTermsList를 타입별 최신 버전 조회로 변경
a653bcf
refactor: 회원가입 약관 동의를 ID 목록에서 TermsType Set으로 변경
991230c
refactor: GetPublishedTermsListUseCase 헥사고날 아키텍처 위반 수정
cd4f088
refactor: findLatestPublishedPerType 동일 effective_at 중복 반환 방어
80454be
refactor: 미사용 TERMS_NOT_FOUND ErrorCode 제거
52b66bb
refactor: TermsAgreementValidator에 @Transactional(readOnly = true) 추가
29d7c96
refactor: UserTermsAgreementRepository 헥사고날 패턴 준수
f2319fa
test: anyList() 느슨한 검증을 구체적인 인자 검증으로 강화
509338e
refactor: GetPublishedTermsList UseCase 반환 타입을 Result 레코드로 변경
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...a/com/dreamteam/alter/adapter/inbound/general/terms/controller/TermsPublicController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.dreamteam.alter.adapter.inbound.general.terms.controller; | ||
|
|
||
| import com.dreamteam.alter.adapter.inbound.common.dto.CommonApiResponse; | ||
| import com.dreamteam.alter.adapter.inbound.general.terms.dto.PublishedTermsItemResponseDto; | ||
| import com.dreamteam.alter.domain.terms.port.inbound.GetPublishedTermsListUseCase; | ||
| import jakarta.annotation.Resource; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/public/terms") | ||
| @RequiredArgsConstructor | ||
| @Validated | ||
| public class TermsPublicController implements TermsPublicControllerSpec { | ||
|
|
||
| @Resource(name = "getPublishedTermsList") | ||
| private final GetPublishedTermsListUseCase getPublishedTermsList; | ||
|
|
||
| @Override | ||
| @GetMapping | ||
| public ResponseEntity<CommonApiResponse<List<PublishedTermsItemResponseDto>>> getPublishedTermsList() { | ||
| return ResponseEntity.ok(CommonApiResponse.of( | ||
| getPublishedTermsList.execute() | ||
| .stream() | ||
| .map(PublishedTermsItemResponseDto::from) | ||
| .toList() | ||
| )); | ||
| } | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
...m/dreamteam/alter/adapter/inbound/general/terms/controller/TermsPublicControllerSpec.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.dreamteam.alter.adapter.inbound.general.terms.controller; | ||
|
|
||
| import com.dreamteam.alter.adapter.inbound.common.dto.CommonApiResponse; | ||
| import com.dreamteam.alter.adapter.inbound.general.terms.dto.PublishedTermsItemResponseDto; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import org.springframework.http.ResponseEntity; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Tag(name = "Public - 약관") | ||
| public interface TermsPublicControllerSpec { | ||
|
|
||
| @Operation(summary = "게시된 약관 목록 조회") | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = "200", description = "약관 목록 조회 성공") | ||
| }) | ||
| ResponseEntity<CommonApiResponse<List<PublishedTermsItemResponseDto>>> getPublishedTermsList(); | ||
| } |
54 changes: 54 additions & 0 deletions
54
.../com/dreamteam/alter/adapter/inbound/general/terms/dto/PublishedTermsItemResponseDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.dreamteam.alter.adapter.inbound.general.terms.dto; | ||
|
|
||
| import com.dreamteam.alter.adapter.inbound.common.dto.DescribedEnumDto; | ||
| import com.dreamteam.alter.domain.terms.result.GetPublishedTermsListResult; | ||
| import com.dreamteam.alter.domain.terms.type.TermsType; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
| @AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
| @Builder(access = AccessLevel.PRIVATE) | ||
| @Schema(description = "게시된 약관 항목 응답 DTO") | ||
| public class PublishedTermsItemResponseDto { | ||
|
|
||
| @Schema(description = "약관 ID", example = "1") | ||
| private Long id; | ||
|
|
||
| @Schema(description = "약관 유형") | ||
| private DescribedEnumDto<TermsType> type; | ||
|
|
||
| @Schema(description = "약관 버전", example = "v1.0") | ||
| private String version; | ||
|
|
||
| @Schema(description = "약관 제목", example = "서비스 이용약관") | ||
| private String title; | ||
|
|
||
| @Schema(description = "약관 문서 URL", example = "https://example.com/terms/service/v1.0") | ||
| private String docUrl; | ||
|
|
||
| @Schema(description = "필수 동의 여부", example = "true") | ||
| private boolean required; | ||
|
|
||
| @Schema(description = "게시 일시", example = "2025-01-01T12:00:00") | ||
| private LocalDateTime effectiveAt; | ||
|
|
||
| public static PublishedTermsItemResponseDto from(GetPublishedTermsListResult result) { | ||
| return PublishedTermsItemResponseDto.builder() | ||
| .id(result.id()) | ||
| .type(DescribedEnumDto.of(result.type(), TermsType.describe())) | ||
| .version("v" + result.version()) | ||
|
hodoon marked this conversation as resolved.
|
||
| .title(result.title()) | ||
| .docUrl(result.docUrl()) | ||
| .required(result.required()) | ||
| .effectiveAt(result.effectiveAt()) | ||
| .build(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...m/dreamteam/alter/adapter/outbound/terms/persistence/UserTermsAgreementJpaRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.dreamteam.alter.adapter.outbound.terms.persistence; | ||
|
|
||
| import com.dreamteam.alter.domain.terms.entity.UserTermsAgreement; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface UserTermsAgreementJpaRepository extends JpaRepository<UserTermsAgreement, Long> { | ||
| } |
22 changes: 22 additions & 0 deletions
22
.../dreamteam/alter/adapter/outbound/terms/persistence/UserTermsAgreementRepositoryImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.dreamteam.alter.adapter.outbound.terms.persistence; | ||
|
|
||
| import com.dreamteam.alter.domain.terms.entity.UserTermsAgreement; | ||
| import com.dreamteam.alter.domain.terms.port.outbound.UserTermsAgreementRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| public class UserTermsAgreementRepositoryImpl implements UserTermsAgreementRepository { | ||
|
|
||
| private final UserTermsAgreementJpaRepository userTermsAgreementJpaRepository; | ||
|
|
||
| @Override | ||
| public List<UserTermsAgreement> saveAll(List<UserTermsAgreement> agreements) { | ||
| return userTermsAgreementJpaRepository.saveAll(agreements); | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/dreamteam/alter/application/terms/service/TermsAgreementValidator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.dreamteam.alter.application.terms.service; | ||
|
|
||
| import com.dreamteam.alter.common.exception.CustomException; | ||
| import com.dreamteam.alter.common.exception.ErrorCode; | ||
| import com.dreamteam.alter.domain.terms.entity.Terms; | ||
| import com.dreamteam.alter.domain.terms.port.outbound.TermsQueryRepository; | ||
| import com.dreamteam.alter.domain.terms.type.TermsType; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| @Component("termsAgreementValidator") | ||
| @RequiredArgsConstructor | ||
| public class TermsAgreementValidator { | ||
|
|
||
| private final TermsQueryRepository termsQueryRepository; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public List<Terms> validateAndResolve(Set<TermsType> agreedTermsTypes) { | ||
| List<Terms> latestPublishedTerms = termsQueryRepository.findLatestPublishedPerType(); | ||
|
|
||
| boolean allRequiredAgreed = latestPublishedTerms.stream() | ||
| .filter(Terms::isRequired) | ||
| .allMatch(t -> agreedTermsTypes.contains(t.getType())); | ||
|
|
||
| if (!allRequiredAgreed) { | ||
| throw new CustomException(ErrorCode.REQUIRED_TERMS_NOT_AGREED); | ||
| } | ||
|
|
||
| return latestPublishedTerms.stream() | ||
| .filter(t -> agreedTermsTypes.contains(t.getType())) | ||
| .toList(); | ||
|
hodoon marked this conversation as resolved.
|
||
| } | ||
| } | ||
26 changes: 26 additions & 0 deletions
26
src/main/java/com/dreamteam/alter/application/terms/usecase/GetPublishedTermsList.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.dreamteam.alter.application.terms.usecase; | ||
|
|
||
| import com.dreamteam.alter.domain.terms.port.inbound.GetPublishedTermsListUseCase; | ||
| import com.dreamteam.alter.domain.terms.port.outbound.TermsQueryRepository; | ||
| import com.dreamteam.alter.domain.terms.result.GetPublishedTermsListResult; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Service("getPublishedTermsList") | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class GetPublishedTermsList implements GetPublishedTermsListUseCase { | ||
|
|
||
| private final TermsQueryRepository termsQueryRepository; | ||
|
|
||
| @Override | ||
| public List<GetPublishedTermsListResult> execute() { | ||
| return termsQueryRepository.findLatestPublishedPerType() | ||
| .stream() | ||
| .map(GetPublishedTermsListResult::from) | ||
| .toList(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.