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: 당근 1등 리워드 팝업의 경우, 최근 1등인 경우에만 노출 #373

Merged
merged 1 commit into from
Jul 29, 2023
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
@@ -1,8 +1,10 @@
package kr.mashup.branding.service.danggn;

import kr.mashup.branding.domain.danggn.DanggnRankingReward;
import kr.mashup.branding.domain.danggn.DanggnRankingRound;
import kr.mashup.branding.domain.danggn.Exception.DanggnRankingRoundNotFoundException;
import kr.mashup.branding.domain.generation.Generation;
import kr.mashup.branding.repository.danggn.DanggnRankingRewardRepository;
import kr.mashup.branding.repository.danggn.DanggnRankingRoundRepository;
import kr.mashup.branding.util.DateUtil;
import lombok.RequiredArgsConstructor;
Expand All @@ -19,6 +21,7 @@
public class DanggnRankingRoundService {

private final DanggnRankingRoundRepository danggnRankingRoundRepository;
private final DanggnRankingRewardRepository danggnRankingRewardRepository;

public DanggnRankingRound findCurrentByGeneration(Integer generationNumber) {
return danggnRankingRoundRepository.retrieveCurrentByGenerationNum(generationNumber)
Expand Down Expand Up @@ -53,4 +56,22 @@ public List<DanggnRankingRound> getAllSorted() {
public void save(DanggnRankingRound danggnRankingRound) {
danggnRankingRoundRepository.save(danggnRankingRound);
}

public Boolean isLatestFirstPlaceMember(Integer generationNumber, Long memberId) {
Optional<DanggnRankingRound> current = danggnRankingRoundRepository.retrieveCurrentByGenerationNum(generationNumber);
if (current.isEmpty()) {
return false;
}

Optional<DanggnRankingRound> previous = danggnRankingRoundRepository.findByNumberAndGenerationId(current.get().getNumber() - 1, current.get().getGenerationId());
if (previous.isEmpty()) {
return false;
}

Long firstPlaceRecordMemberId = danggnRankingRewardRepository.findByDanggnRankingRoundId(previous.get().getId())
.map(DanggnRankingReward::getFirstPlaceRecordMemberId)
.orElse(null);

return memberId == firstPlaceRecordMemberId;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package kr.mashup.branding.service.popup;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Optional;

import org.springframework.stereotype.Service;

import kr.mashup.branding.domain.member.Member;
import kr.mashup.branding.domain.popup.MemberPopup;
import kr.mashup.branding.domain.popup.PopupType;
import kr.mashup.branding.repository.memberpopup.MemberPopupRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package kr.mashup.branding.facade.popup;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import kr.mashup.branding.domain.member.MemberGeneration;
import kr.mashup.branding.domain.member.exception.InactiveGenerationException;
import kr.mashup.branding.domain.popup.MemberPopup;
import kr.mashup.branding.domain.popup.PopupType;
import kr.mashup.branding.service.danggn.DanggnRankingRoundService;
import kr.mashup.branding.service.member.MemberService;
import kr.mashup.branding.service.popup.MemberPopupService;
import kr.mashup.branding.service.storage.StorageService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
Expand All @@ -24,7 +23,7 @@ public class MemberPopupFacadeService {

private final MemberPopupService memberPopupService;
private final MemberService memberService;
private final StorageService storageService;
private final DanggnRankingRoundService danggnRankingRoundService;

public List<PopupType> getEnabledPopupTypes(
Long memberGenerationId
Expand All @@ -44,6 +43,11 @@ public List<PopupType> getEnabledPopupTypes(
.filter(popupType -> memberPopupService.isEnabledMemberPopup(memberGeneration.getMember(), popupType))
.forEach(enabledMemberPopupTypes::add);

// 당근 1등 리워드 팝업의 경우, 최근 1등인 경우에만 노출
if (!danggnRankingRoundService.isLatestFirstPlaceMember(memberGeneration.getGeneration().getNumber(), memberGeneration.getMember().getId())) {
enabledMemberPopupTypes.remove(PopupType.DANGGN_REWARD);
}

return enabledMemberPopupTypes;
}

Expand Down
Loading