-
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: 스터디 수료 쿠폰을 스터디 당 하나만 가지도록 변경 #851
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,10 +109,7 @@ public void createAndIssueCouponByStudyHistories(List<Long> studyHistoryIds) { | |
List<Member> students = memberRepository.findAllById(studentIds); | ||
Study study = studyHistories.get(0).getStudy(); | ||
|
||
String couponName = couponNameUtil.generateStudyCompletionCouponName(study); | ||
// TODO: 요청할 때마다 새로운 쿠폰 생성되는 문제 수정: 스터디마다 하나의 쿠폰만 존재하도록 쿠폰 타입 및 참조 식별자 추가 | ||
Coupon coupon = Coupon.createAutomatic(couponName, Money.from(5000L), CouponType.STUDY_COMPLETION, study); | ||
couponRepository.save(coupon); | ||
Coupon coupon = findOrCreate(CouponType.STUDY_COMPLETION, study); | ||
|
||
List<IssuedCoupon> issuedCoupons = students.stream() | ||
.map(student -> IssuedCoupon.create(coupon, student)) | ||
|
@@ -123,4 +120,12 @@ public void createAndIssueCouponByStudyHistories(List<Long> studyHistoryIds) { | |
"[CouponService] 스터디 수료 쿠폰 발급: issuedCouponIds={}", | ||
issuedCoupons.stream().map(IssuedCoupon::getId).toList()); | ||
} | ||
|
||
private Coupon findOrCreate(CouponType couponType, Study study) { | ||
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. 저번에 findOrCreate 계열 따닥 이슈 있었는데, 이것도 unique constraint 있어야 방지할 수 있지 않을까 싶네요 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. 오 그렇겠네요 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. 그리고 해당 로직에서는 find 분기로 가져온 과제제출이력을 수정할 니즈가 있어서, 바깥에서도 save를 항상 호출 가능한 상황이었지만... 그래도 AssignmentHistory의 findOrCreate 내부에서 save를 호출하도록 투두 하나 추가해주면 좋을 것 같아요 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. 네네 todo 추가하고 issue도 만들어둘게요 |
||
return couponRepository.findByCouponTypeAndStudy(couponType, study).orElseGet(() -> { | ||
String couponName = couponNameUtil.generateStudyCompletionCouponName(study); | ||
Coupon coupon = Coupon.createAutomatic(couponName, Money.FIVE_THOUSAND, couponType, study); | ||
return couponRepository.save(coupon); | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
package com.gdschongik.gdsc.domain.coupon.dao; | ||
|
||
import com.gdschongik.gdsc.domain.coupon.domain.Coupon; | ||
import com.gdschongik.gdsc.domain.coupon.domain.CouponType; | ||
import com.gdschongik.gdsc.domain.study.domain.Study; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CouponRepository extends JpaRepository<Coupon, Long> {} | ||
public interface CouponRepository extends JpaRepository<Coupon, Long> { | ||
Optional<Coupon> findByCouponTypeAndStudy(CouponType couponType, Study study); | ||
} |
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
🛠️ Refactor suggestion
스터디 히스토리 유효성 검사 추가가 필요합니다
현재 구현에서는 다음과 같은 잠재적인 문제가 있습니다:
리뷰 코멘트에서 제안된 검증 로직 추가를 권장드립니다:
추가로 INVALID_STUDY_HISTORIES 에러 코드도 정의가 필요합니다.
🔗 Analysis chain
studyHistories의 유효성 검사가 필요합니다.
다음 사항들을 확인해주세요:
아래는 검증을 위한 코드 제안입니다:
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
Length of output: 26389