-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: 쿠폰 도메인에 메타데이터 필드 추가 #847
Open
Sangwook02
wants to merge
6
commits into
develop
Choose a base branch
from
feature/839-add-metadata-field-to-coupon
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6c0f086
feat: 쿠폰 도메인에 메타데이터 필드 추가
Sangwook02 8ceeb8d
feat: 쿠폰 생성 요청 dto 수정
Sangwook02 5fad801
fix: 발급 방식을 수동으로 수정
Sangwook02 b0069cb
feat: 쿠폰 타입에 null 검증 추가
Sangwook02 44f9086
rename: 쿠폰 발급 방식 enum 클래스명 변경
Sangwook02 144d2cd
refactor: 쿠폰 발급 방식에 따라 정적 팩토리 메서드 분리
Sangwook02 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 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 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 |
---|---|---|
|
@@ -4,13 +4,19 @@ | |
|
||
import com.gdschongik.gdsc.domain.common.model.BaseEntity; | ||
import com.gdschongik.gdsc.domain.common.vo.Money; | ||
import com.gdschongik.gdsc.domain.study.domain.Study; | ||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embedded; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
@@ -31,15 +37,45 @@ public class Coupon extends BaseEntity { | |
@Embedded | ||
private Money discountAmount; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private CouponType couponType; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private IssuanceType issuanceType; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "study_id") | ||
private Study study; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
private Coupon(String name, Money discountAmount) { | ||
private Coupon(String name, Money discountAmount, CouponType couponType, IssuanceType issuanceType, Study study) { | ||
this.name = name; | ||
this.discountAmount = discountAmount; | ||
this.couponType = couponType; | ||
this.issuanceType = issuanceType; | ||
this.study = study; | ||
} | ||
Comment on lines
+51
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 도메인 무결성 검증이 필요합니다. 생성자에서 다음과 같은 검증 메소드를 추가해주세요: private static void validateStudyRequirement(CouponType couponType, Study study) {
if (couponType == CouponType.STUDY_COMPLETION && study == null) {
throw new CustomException(STUDY_REQUIRED_FOR_STUDY_COMPLETION);
}
if (couponType == CouponType.ADMIN && study != null) {
throw new CustomException(STUDY_NOT_ALLOWED_FOR_ADMIN);
}
} |
||
|
||
public static Coupon createAutomatic(String name, Money discountAmount, CouponType couponType, Study study) { | ||
validateDiscountAmountPositive(discountAmount); | ||
return Coupon.builder() | ||
.name(name) | ||
.discountAmount(discountAmount) | ||
.couponType(couponType) | ||
.issuanceType(IssuanceType.AUTOMATIC) | ||
.study(study) | ||
.build(); | ||
} | ||
|
||
public static Coupon create(String name, Money discountAmount) { | ||
public static Coupon createManual(String name, Money discountAmount, CouponType couponType, Study study) { | ||
validateDiscountAmountPositive(discountAmount); | ||
return Coupon.builder().name(name).discountAmount(discountAmount).build(); | ||
return Coupon.builder() | ||
.name(name) | ||
.discountAmount(discountAmount) | ||
.couponType(couponType) | ||
.issuanceType(IssuanceType.MANUAL) | ||
.study(study) | ||
.build(); | ||
} | ||
|
||
// 검증 로직 | ||
|
13 changes: 13 additions & 0 deletions
13
src/main/java/com/gdschongik/gdsc/domain/coupon/domain/CouponType.java
This file contains 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,13 @@ | ||
package com.gdschongik.gdsc.domain.coupon.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum CouponType { | ||
ADMIN("어드민"), | ||
STUDY_COMPLETION("스터디 수료"); | ||
|
||
private final String value; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/gdschongik/gdsc/domain/coupon/domain/IssuanceType.java
This file contains 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,13 @@ | ||
package com.gdschongik.gdsc.domain.coupon.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum IssuanceType { | ||
AUTOMATIC("자동 발급"), | ||
MANUAL("수동 발급"); | ||
|
||
private final String value; | ||
} |
10 changes: 9 additions & 1 deletion
10
src/main/java/com/gdschongik/gdsc/domain/coupon/dto/request/CouponCreateRequest.java
This file contains 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 |
---|---|---|
@@ -1,7 +1,15 @@ | ||
package com.gdschongik.gdsc.domain.coupon.dto.request; | ||
|
||
import com.gdschongik.gdsc.domain.coupon.domain.CouponType; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.annotation.Nullable; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Positive; | ||
import java.math.BigDecimal; | ||
|
||
public record CouponCreateRequest(@NotBlank String name, @Positive BigDecimal discountAmount) {} | ||
public record CouponCreateRequest( | ||
@NotBlank String name, | ||
@Positive BigDecimal discountAmount, | ||
@NotNull(message = "쿠폰 타입은 null이 될 수 없습니다.") CouponType couponType, | ||
@Nullable @Schema(description = "스터디 관련 쿠폰이 아니라면 null을 가집니다.") Long studyId) {} |
This file contains 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
스터디 히스토리의 일관성 검증이 필요합니다.
코드베이스 분석 결과, 현재 구현에서는 모든 히스토리가 동일한 스터디에서 왔다고 가정하고 있으며, 이를 검증하는 로직이 없습니다. 이는 잘못된 쿠폰 발급으로 이어질 수 있습니다.
다음과 같은 검증 로직 추가를 제안합니다:
🔗 Analysis chain
스터디 히스토리의 일관성 검증이 필요합니다.
첫 번째 히스토리에서 스터디 정보를 가져오는 방식은 모든 히스토리가 동일한 스터디에서 왔다고 가정합니다. 이 가정이 깨질 경우 잘못된 쿠폰이 발급될 수 있습니다.
다음과 같은 검증 로직 추가를 제안합니다:
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
Length of output: 35307
Script:
Length of output: 108
Script:
Length of output: 7962