Skip to content
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 @@ -30,20 +30,17 @@ public class BattleProposalService {
private final CreditService creditService;
private final UserService userService;

private static final int PROPOSAL_COST = 30;
private static final int PROPOSAL_REWARD = 100;

@Transactional
public BattleProposalResponse propose(BattleProposalRequest request) {
User user = userService.findCurrentUser();

// 크레딧 잔액 확인
int cost = CreditType.TOPIC_SUGGEST.getDefaultAmount();

int totalCredits = creditService.getTotalPoints(user.getId());
if (totalCredits < PROPOSAL_COST) {
if (totalCredits < cost) {
throw new CustomException(ErrorCode.CREDIT_NOT_ENOUGH);
}

// 제안 저장
BattleProposal proposal = BattleProposal.builder()
.user(user)
.category(request.getCategory())
Expand All @@ -55,8 +52,7 @@ public BattleProposalResponse propose(BattleProposalRequest request) {

battleProposalRepository.save(proposal);

// 30크레딧 차감 (음수로 저장)
creditService.addCredit(user.getId(), CreditType.TOPIC_SUGGEST, -PROPOSAL_COST, proposal.getId());
creditService.addCredit(user.getId(), CreditType.TOPIC_SUGGEST, -cost, proposal.getId());

return new BattleProposalResponse(proposal);
}
Expand Down Expand Up @@ -87,8 +83,8 @@ public BattleProposalResponse review(Long proposalId, BattleProposalReviewReques

if (request.getAction() == BattleProposalReviewRequest.Action.ACCEPT) {
proposal.accept();
// 100크레딧 지급
creditService.addCredit(proposal.getUser().getId(), CreditType.TOPIC_ADOPTED, PROPOSAL_REWARD, proposalId);
int reward = CreditType.TOPIC_ADOPTED.getDefaultAmount();
creditService.addCredit(proposal.getUser().getId(), CreditType.TOPIC_ADOPTED, reward, proposalId);
} else {
proposal.reject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public enum CreditType {
MAJORITY_WIN(10), // 다수결 보상: 월요일 배치, 2주 전 배틀 TOP≥10 대상
BEST_COMMENT(50), // 베댓 보상: 월요일 배치, 2주 전 배틀 좋아요 1위
WEEKLY_CHARGE(40), // 주간 자동 충전: 매주 월요일 00:00 활성 사용자 전체
FREE_CHARGE(0); // 광고/자유 충전: 가변 금액
FREE_CHARGE(0), // 광고/자유 충전: 가변 금액
TOPIC_SUGGEST(30), // 주제 제안
TOPIC_ADOPTED(100); // 주제 채택

private final int defaultAmount;

Expand Down