Skip to content
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

fix: 가입 미완료인 이전 회차 멤버십 있어도 새로운 멤버십 생성 가능하도록 수정 #728

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public void submitMembership(Long recruitmentRoundId) {
.findById(recruitmentRoundId)
.orElseThrow(() -> new CustomException(RECRUITMENT_ROUND_NOT_FOUND));

boolean isMembershipAlreadySubmitted =
membershipRepository.existsByMemberAndRecruitment(currentMember, recruitmentRound.getRecruitment());
boolean isMembershipDuplicate = membershipRepository.existsByMemberAndRecruitmentWithSatisfiedRequirements(
currentMember, recruitmentRound.getRecruitment());

membershipValidator.validateMembershipSubmit(currentMember, recruitmentRound, isMembershipAlreadySubmitted);
membershipValidator.validateMembershipSubmit(currentMember, recruitmentRound, isMembershipDuplicate);

Membership membership = Membership.createMembership(currentMember, recruitmentRound);
membershipRepository.save(membership);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

public interface MembershipCustomRepository {

boolean existsByMemberAndRecruitment(Member member, Recruitment recruitment);
boolean existsByMemberAndRecruitmentWithSatisfiedRequirements(Member member, Recruitment recruitment);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import static com.gdschongik.gdsc.domain.membership.domain.QMembership.*;

import com.gdschongik.gdsc.domain.common.model.RequirementStatus;
import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.domain.recruitment.domain.Recruitment;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.EnumPath;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;

Expand All @@ -14,11 +16,14 @@ public class MembershipCustomRepositoryImpl implements MembershipCustomRepositor
private final JPAQueryFactory queryFactory;

@Override
public boolean existsByMemberAndRecruitment(Member member, Recruitment recruitment) {
public boolean existsByMemberAndRecruitmentWithSatisfiedRequirements(Member member, Recruitment recruitment) {
Integer fetchOne = queryFactory
.selectOne()
.from(membership)
.where(eqMember(member), eqRecruitment(recruitment))
.where(
eqMember(member),
eqRecruitment(recruitment),
eqRequirementStatus(membership.regularRequirement.paymentStatus, RequirementStatus.SATISFIED))
.fetchFirst();

return fetchOne != null;
Expand All @@ -31,4 +36,9 @@ private BooleanExpression eqMember(Member member) {
private BooleanExpression eqRecruitment(Recruitment recruitment) {
return recruitment != null ? membership.recruitmentRound.recruitment.eq(recruitment) : null;
}

private BooleanExpression eqRequirementStatus(
EnumPath<RequirementStatus> requirement, RequirementStatus requirementStatus) {
return requirementStatus != null ? requirement.eq(requirementStatus) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
public class MembershipValidator {

public void validateMembershipSubmit(
Member currentMember, RecruitmentRound recruitmentRound, boolean isMembershipAlreadySubmitted) {
Member currentMember, RecruitmentRound recruitmentRound, boolean isMembershipDuplicate) {
// 준회원인지 검증
// TODO: 어드민인 경우 리쿠르팅 지원 및 결제에 대한 정책 검토 필요. 현재는 불가능하도록 설정
if (!currentMember.isAssociate()) {
throw new CustomException(MEMBERSHIP_NOT_APPLICABLE);
}

// 이미 접수한 멤버십이 있는지 검증
if (isMembershipAlreadySubmitted) {
// 이미 멤버십이 있는지 검증
if (isMembershipDuplicate) {
throw new CustomException(MEMBERSHIP_ALREADY_SUBMITTED);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class 멤버십_가입신청시 {
.isInstanceOf(CustomException.class)
.hasMessage(RECRUITMENT_ROUND_NOT_FOUND.getMessage());
}

// todo: 1차 모집시 멤버십 생성 후 실제 가입은 하지 않고 2차 모집 시 가입하려고 하는 케이스 추가
}

@Test
Expand Down