Skip to content

Commit

Permalink
fix: cycle 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
junseokkim committed Jan 2, 2024
1 parent 549348f commit a0ffb18
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
25 changes: 23 additions & 2 deletions src/main/java/com/teami/domain/member/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import com.teami.domain.member.dto.response.VisitorCommentRes;
import com.teami.domain.member.entitty.Member;
import com.teami.domain.member.repository.MemberRepository;
import com.teami.domain.reward.entity.MemberReward;
import com.teami.domain.reward.entity.Reward;
import com.teami.domain.reward.repository.MemberRewardRepository;
import com.teami.domain.reward.service.RewardService;
import com.teami.global.apiPayload.ExceptionHandler;
import com.teami.global.apiPayload.code.status.ErrorStatus;
Expand All @@ -19,13 +22,16 @@
import java.util.List;
import java.util.Optional;

import static com.teami.domain.reward.entity.Reward.*;
import static com.teami.domain.reward.entity.Reward.SIGNUP_AND_CALENDAR_CREATE;

@Service
@RequiredArgsConstructor
public class MemberService {
private final MemberRepository memberRepository;
private final FriendRepository friendRepository;
private final CalendarVisitorRepository calendarVisitorRepository;
private final RewardService rewardService;
private final MemberRewardRepository memberRewardRepository;

public Member findMemberById(Long memberId) {
Optional<Member> member = memberRepository.findById(memberId);
Expand Down Expand Up @@ -61,7 +67,13 @@ else if(memberRepository.findMemberByNickname(nickname) != null){
Member member = new Member(memberRequest);

memberRepository.save(member);
rewardService.createReward_Member(member);

createReward_Reward(member);

if (!memberRewardRepository.existsByMemberAndReward(member, SIGNUP_AND_CALENDAR_CREATE)) {
memberRewardRepository.save(MemberReward.createMemberReward(member, SIGNUP_AND_CALENDAR_CREATE));
}

return true;
}

Expand Down Expand Up @@ -137,4 +149,13 @@ public String checkFirstLetter(Long memberId) {
}
return null;
}
private Reward createReward_Reward(Member member) {
if (!memberRewardRepository.existsByMemberAndReward(member, COMPLETE_FIRST_MISSION)) {
if (memberRewardRepository.countMemberRewardByMember(member) == 0L) {
memberRewardRepository.save(MemberReward.createMemberReward(member, EARN_FIVE_REWARDS));
return EARN_FIVE_REWARDS;
}
}
return null;
}
}
20 changes: 11 additions & 9 deletions src/main/java/com/teami/domain/reward/service/RewardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,7 @@ public Reward createReward_Mission2(Member member) {
return null;
}

public Reward createReward_Reward(Member member) {
if (!memberRewardRepository.existsByMemberAndReward(member, COMPLETE_FIRST_MISSION)) {
if (memberRewardRepository.countMemberRewardByMember(member) == 0L) {
memberRewardRepository.save(MemberReward.createMemberReward(member, EARN_FIVE_REWARDS));
return EARN_FIVE_REWARDS;
}
}
return null;
}


public Reward createReward_Friend1(Member member) {

Expand All @@ -116,4 +108,14 @@ public Reward createReward_Friend2(Member member) {
public List<RewardResponse> getMyRewardList(Long memberId) {
return memberRewardRepository.findByMemberId(memberId);
}

private Reward createReward_Reward(Member member) {
if (!memberRewardRepository.existsByMemberAndReward(member, COMPLETE_FIRST_MISSION)) {
if (memberRewardRepository.countMemberRewardByMember(member) == 0L) {
memberRewardRepository.save(MemberReward.createMemberReward(member, EARN_FIVE_REWARDS));
return EARN_FIVE_REWARDS;
}
}
return null;
}
}

0 comments on commit a0ffb18

Please sign in to comment.