-
Notifications
You must be signed in to change notification settings - Fork 1
[Feat] 약관 관련 API 구현 #210
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
[Feat] 약관 관련 API 구현 #210
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
18eab5d
[Feat] #202 약관(Term) 및 약관 동의(TermAgreement) 엔티티 생성
hyomee2 92ac995
[Feat] #202 약관 조회 API 구현
hyomee2 797ef9d
[Feat] #202 약관 동의 API 구현
hyomee2 e39e0df
Merge branch 'develop' of https://github.com/team-kareer/kareer-serve…
hyomee2 6c46e8d
[Refactor] #202 도메인에 맞게 로직 이동
hyomee2 6f1871a
[Refactor] #202 Swagger 명세 추가
hyomee2 0d016a9
[Chore] #202 약관 조회 응답에 필수 여부 컬럼 추가
hyomee2 a86a968
[Chore] #202 MemberTermRequest에 @NotNull 제약조건 추가
hyomee2 0500d2a
[Feat] #202 MemberTerm 테이블에 unique 제약 조건 추가 및 이미 약관 동의한 경우 예외처리
hyomee2 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
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
25 changes: 25 additions & 0 deletions
25
src/main/java/org/sopt/kareer/domain/member/dto/request/MemberTermsRequest.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,25 @@ | ||
| package org.sopt.kareer.domain.member.dto.request; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.Valid; | ||
| import jakarta.validation.constraints.NotEmpty; | ||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Schema(description = "약관 동의 요청") | ||
| public record MemberTermsRequest( | ||
| @Schema(description = "약관 동의 리스트") | ||
| @NotEmpty(message = "약관 동의 목록은 비어있을 수 없습니다.") | ||
| List<@NotNull(message = "약관 동의 항목은 null일 수 없습니다.") @Valid TermAgreement> agreements | ||
| ) { | ||
| public record TermAgreement( | ||
| @Schema(description = "약관 고유번호", example="1") | ||
| @NotNull(message = "약관 ID는 필수입니다.") | ||
| Long termId, | ||
|
|
||
| @Schema(description = "약관 동의여부", example="true") | ||
| @NotNull(message = "동의 여부는 필수입니다.") | ||
| boolean agreed | ||
| ) {} | ||
| } |
49 changes: 49 additions & 0 deletions
49
src/main/java/org/sopt/kareer/domain/member/entity/MemberTerm.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,49 @@ | ||
| package org.sopt.kareer.domain.member.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
| import org.sopt.kareer.domain.term.entity.Term; | ||
| import org.sopt.kareer.global.entity.BaseEntity; | ||
|
|
||
| @Table( | ||
| name = "member_terms", | ||
| uniqueConstraints = { | ||
| @UniqueConstraint( | ||
| name = "uk_member_term", | ||
| columnNames = {"member_id", "term_id"} | ||
| ) | ||
| } | ||
| ) | ||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class MemberTerm extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "term_agreement_id") | ||
| private Long id; | ||
|
|
||
| @Column(nullable = false) | ||
| private boolean agreed; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "member_id", nullable = false) | ||
| private Member member; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "term_id", nullable = false) | ||
| private Term term; | ||
|
|
||
| public MemberTerm(boolean agreed, Member member, Term term) { | ||
| this.agreed = agreed; | ||
| this.member = member; | ||
| this.term = term; | ||
| } | ||
|
|
||
| public static MemberTerm create(boolean agreed, Member member, Term term) { | ||
| return new MemberTerm(agreed, member, term); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/sopt/kareer/domain/member/repository/MemberTermRepository.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,9 @@ | ||
| package org.sopt.kareer.domain.member.repository; | ||
|
|
||
| import org.sopt.kareer.domain.member.entity.MemberTerm; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface MemberTermRepository extends JpaRepository<MemberTerm, Long> { | ||
|
|
||
| boolean existsByMemberId(Long memberId); | ||
| } |
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
30 changes: 30 additions & 0 deletions
30
src/main/java/org/sopt/kareer/domain/term/controller/TermController.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,30 @@ | ||
| package org.sopt.kareer.domain.term.controller; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.sopt.kareer.domain.term.dto.response.TermsResponse; | ||
| import org.sopt.kareer.domain.term.service.TermService; | ||
| import org.sopt.kareer.global.response.BaseResponse; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/v1/terms") | ||
| @Tag(name = "Term API") | ||
| public class TermController { | ||
|
|
||
| private final TermService termService; | ||
|
|
||
| @GetMapping | ||
| @Operation(summary = "약관 조회", description = "약관 내용을 조회합니다.") | ||
| public ResponseEntity<BaseResponse<TermsResponse>> getTerms() { | ||
| return ResponseEntity | ||
| .status(HttpStatus.OK) | ||
| .body(BaseResponse.ok(termService.getTerms(), "약관 조회에 성공했습니다.")); | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/sopt/kareer/domain/term/dto/response/TermsResponse.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,39 @@ | ||
| package org.sopt.kareer.domain.term.dto.response; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import org.sopt.kareer.domain.term.entity.Term; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Schema(description = "약관 응답") | ||
| public record TermsResponse( | ||
| @Schema(description = "약관 리스트") | ||
| List<TermResponse> terms | ||
| ) { | ||
| public static TermsResponse from(List<TermResponse> terms) { | ||
| return new TermsResponse(terms); | ||
| } | ||
|
|
||
| public record TermResponse( | ||
| @Schema(description = "약관 고유번호", example="1") | ||
| Long termId, | ||
|
|
||
| @Schema(description = "약관 제목", example="Terms of Service") | ||
| String title, | ||
|
|
||
| @Schema(description = "약관 내용", example="1. Purpose ~") | ||
| String content, | ||
|
|
||
| @Schema(description = "필수 여부", example="true") | ||
| boolean required | ||
| ) { | ||
| public static TermResponse from(Term term) { | ||
| return new TermResponse( | ||
| term.getId(), | ||
| term.getTitle(), | ||
| term.getContent(), | ||
| term.isRequired() | ||
| ); | ||
| } | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/sopt/kareer/domain/term/entity/Term.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,39 @@ | ||
| package org.sopt.kareer.domain.term.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
| import org.sopt.kareer.domain.term.entity.enums.TermType; | ||
| import org.sopt.kareer.global.entity.BaseEntity; | ||
|
|
||
| @Table(name = "terms") | ||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class Term extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "term_id") | ||
| private Long id; | ||
|
|
||
| @Column(nullable = false) | ||
| private String title; | ||
|
|
||
| @Column(nullable = false, columnDefinition = "TEXT") | ||
| private String content; | ||
|
|
||
| @Column(nullable = false) | ||
| @Enumerated(EnumType.STRING) | ||
| private TermType type; | ||
|
|
||
| @Column(nullable = false) | ||
| private String version; | ||
|
|
||
| @Column(nullable = false) | ||
| private boolean required; | ||
|
|
||
| @Column(nullable = false) | ||
| private boolean active; | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/sopt/kareer/domain/term/entity/enums/TermType.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,18 @@ | ||
| package org.sopt.kareer.domain.term.entity.enums; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum TermType { | ||
|
|
||
| SERVICE(1), | ||
| PERSONAL(2), | ||
| IDENTIFICATION(3), | ||
| SENSITIVE(4), | ||
| ENTRUSTMENT(5), | ||
| MARKETING(6); | ||
|
|
||
| private final int order; | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/sopt/kareer/domain/term/exception/TermErrorCode.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 org.sopt.kareer.domain.term.exception; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import org.sopt.kareer.global.exception.errorcode.ErrorCode; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| @AllArgsConstructor | ||
| @Getter | ||
| public enum TermErrorCode implements ErrorCode { | ||
|
|
||
| TERM_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "존재하지 않는 약관입니다."), | ||
| DUPLICATE_TERM(HttpStatus.BAD_REQUEST.value(), "중복된 약관 ID가 존재합니다."), | ||
| REQUIRED_TERM_NOT_AGREED(HttpStatus.BAD_REQUEST.value(), "필수 약관에 동의해야 합니다."), | ||
| MISSING_TERM(HttpStatus.BAD_REQUEST.value(), "누락된 약관 동의가 존재합니다."), | ||
| INVALID_ARGUMENT(HttpStatus.BAD_REQUEST.value(), "잘못된 요청 파라미터입니다."), | ||
| ALREADY_AGREED_TERMS(HttpStatus.CONFLICT.value(), "이미 약관 동의가 완료되었습니다.") | ||
| ; | ||
|
|
||
| private final int httpStatus; | ||
| private final String message; | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/sopt/kareer/domain/term/exception/TermException.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,9 @@ | ||
| package org.sopt.kareer.domain.term.exception; | ||
|
|
||
| import org.sopt.kareer.global.exception.customexception.CustomException; | ||
|
|
||
| public class TermException extends CustomException { | ||
| public TermException(TermErrorCode errorCode) { | ||
| super(errorCode); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/sopt/kareer/domain/term/repository/TermRepository.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,11 @@ | ||
| package org.sopt.kareer.domain.term.repository; | ||
|
|
||
| import org.sopt.kareer.domain.term.entity.Term; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface TermRepository extends JpaRepository<Term, Long> { | ||
|
|
||
| List<Term> findByActiveTrue(); | ||
| } |
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.