Skip to content

Commit

Permalink
feat: 회원가입 응모권 5장 발급
Browse files Browse the repository at this point in the history
  • Loading branch information
swa07016 committed Jul 21, 2024
1 parent 32ab35b commit d8ba521
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class QPrizeTicket extends EntityPathBase<PrizeTicket> {

public final NumberPath<Long> memberId = createNumber("memberId", Long.class);

public final EnumPath<com.nexters.dailyphrase.common.enums.PrizeTicketSource> source = createEnum("source", com.nexters.dailyphrase.common.enums.PrizeTicketSource.class);

public final EnumPath<com.nexters.dailyphrase.common.enums.PrizeTicketStatus> status = createEnum("status", com.nexters.dailyphrase.common.enums.PrizeTicketStatus.class);

//inherited
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public class DailyPhraseStatic {

public static final int MAX_EVENT_TICKETS_PER_DAY = 10;
public static final Long CURRENT_ACTIVE_EVENT_ID = 1L;

public static final int SIGN_UP_TICKET_COUNT = 5;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.nexters.dailyphrase.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum PrizeTicketSource {
SIGNUP("회원가입"),
SHARE("공유하기");

private final String description;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.nexters.dailyphrase.member.business;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.nexters.dailyphrase.common.enums.PrizeTicketSource;
import com.nexters.dailyphrase.prize.business.PrizeEventMapper;
import com.nexters.dailyphrase.prize.implement.PrizeTicketCommandAdapter;
import com.nexters.dailyphrase.prize.implement.PrizeTicketQueryAdapter;

import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
public class MemberLoginActionProcessor {

private final Logger logger = LogManager.getLogger(MemberLoginActionProcessor.class);
private final PrizeTicketQueryAdapter prizeTicketQueryAdapter;
private final PrizeTicketCommandAdapter prizeTicketCommandAdapter;
private final PrizeEventMapper prizeEventMapper;

@Transactional(propagation = Propagation.REQUIRES_NEW)
public void processLoginAction(final Long memberId) {
try {
if (!prizeTicketQueryAdapter.existsByMemberIdAndSource(
memberId, PrizeTicketSource.SIGNUP))
prizeTicketCommandAdapter.createMultiple(
prizeEventMapper.toPrizeTicketList(memberId, PrizeTicketSource.SIGNUP));
} catch (Exception e) {
logger.error("MemberService) 회원가입 응모권 발급 중 에러가 발생했습니다.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class MemberService {
private final FavoriteQueryAdapter favoriteQueryAdapter;
private final FavoriteCommandAdapter favoriteCommandAdapter;
private final SocialLoginServiceFactory socialLoginServiceFactory;
private final MemberLoginActionProcessor memberLoginActionProcessor;
private final JwtTokenService jwtTokenService;
private final MemberMapper memberMapper;

Expand All @@ -46,6 +47,9 @@ public MemberResponseDTO.LoginMember login(
jwtTokenService.generateAccessToken(member.getId(), member.getRole().name());
// TODO - Refresh 토큰을 Jwt로 발급하지 않고, Redis를 사용하는 방식도 고려하기
String refreshToken = jwtTokenService.generateRefreshToken(member.getId());

// NOTE - 회원가입 응모권 발급
memberLoginActionProcessor.processLoginAction(member.getId());
return memberMapper.toLoginMember(member, accessToken, refreshToken);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.nexters.dailyphrase.prize.business;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import com.nexters.dailyphrase.common.annotation.Mapper;
import com.nexters.dailyphrase.common.consts.DailyPhraseStatic;
import com.nexters.dailyphrase.common.enums.PrizeEntryStatus;
import com.nexters.dailyphrase.common.enums.PrizeTicketSource;
import com.nexters.dailyphrase.common.enums.PrizeTicketStatus;
import com.nexters.dailyphrase.prize.domain.Prize;
import com.nexters.dailyphrase.prize.domain.PrizeEntry;
Expand All @@ -14,11 +18,15 @@
@Mapper
public class PrizeEventMapper {
public PrizeTicket toPrizeTicket(
Long memberId, PrizeTicketStatus prizeTicketStatus, Long eventId) {
Long memberId,
PrizeTicketStatus prizeTicketStatus,
Long eventId,
PrizeTicketSource source) {
return PrizeTicket.builder()
.memberId(memberId)
.status(prizeTicketStatus)
.eventId(eventId)
.source(source)
.build();
}

Expand Down Expand Up @@ -73,4 +81,18 @@ public PrizeEventResponseDTO.EnterPrizeEvent toEnterPrizeEvent(final PrizeEntry
.status(prizeEntry.getStatus())
.build();
}

public List<PrizeTicket> toPrizeTicketList(Long memberId, PrizeTicketSource prizeTicketSource) {
Long eventId = DailyPhraseStatic.CURRENT_ACTIVE_EVENT_ID;
int limit = DailyPhraseStatic.SIGN_UP_TICKET_COUNT;
return IntStream.range(0, limit)
.mapToObj(
i ->
toPrizeTicket(
memberId,
PrizeTicketStatus.AVAILABLE,
eventId,
prizeTicketSource))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.nexters.dailyphrase.common.consts.DailyPhraseStatic;
import com.nexters.dailyphrase.common.enums.PrizeEntryStatus;
import com.nexters.dailyphrase.common.enums.PrizeEventStatus;
import com.nexters.dailyphrase.common.enums.PrizeTicketSource;
import com.nexters.dailyphrase.common.enums.PrizeTicketStatus;
import com.nexters.dailyphrase.common.jwt.JwtTokenService;
import com.nexters.dailyphrase.common.jwt.dto.AccessTokenInfo;
Expand Down Expand Up @@ -89,7 +90,8 @@ public void issuePrizeTicket(final KakaolinkCallbackRequestDTO request) {
if (count >= MAX_EVENT_TICKETS_PER_DAY) return;

PrizeTicket prizeTicket =
prizeEventMapper.toPrizeTicket(memberId, PrizeTicketStatus.AVAILABLE, eventId);
prizeEventMapper.toPrizeTicket(
memberId, PrizeTicketStatus.AVAILABLE, eventId, PrizeTicketSource.SHARE);
prizeTicketCommandAdapter.create(prizeTicket);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.persistence.*;

import com.nexters.dailyphrase.common.domain.BaseDateTimeEntity;
import com.nexters.dailyphrase.common.enums.PrizeTicketSource;
import com.nexters.dailyphrase.common.enums.PrizeTicketStatus;

import lombok.*;
Expand All @@ -24,6 +25,9 @@ public class PrizeTicket extends BaseDateTimeEntity {
@Enumerated(EnumType.STRING)
private PrizeTicketStatus status;

@Enumerated(EnumType.STRING)
private PrizeTicketSource source;

public void setStatus(PrizeTicketStatus status) {
this.status = status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

import org.springframework.data.jpa.repository.JpaRepository;

import com.nexters.dailyphrase.common.enums.PrizeTicketStatus;
import com.nexters.dailyphrase.common.enums.PrizeTicketSource;
import com.nexters.dailyphrase.prize.domain.PrizeTicket;

public interface PrizeTicketRepository
extends JpaRepository<PrizeTicket, Long>, PrizeTicketCustomRepository {
int countByMemberIdAndCreatedAtBetween(
Long memberId, LocalDateTime startDateTime, LocalDateTime endDateTime);
int countByMemberIdAndCreatedAtBetweenAndSource(
Long memberId,
LocalDateTime startDateTime,
LocalDateTime endDateTime,
PrizeTicketSource source);

int countByMemberIdAndStatus(Long memberId, PrizeTicketStatus status);
boolean existsByMemberIdAndSource(Long memberId, PrizeTicketSource source);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nexters.dailyphrase.prize.implement;

import java.util.List;

import com.nexters.dailyphrase.common.annotation.Adapter;
import com.nexters.dailyphrase.prize.domain.PrizeTicket;
import com.nexters.dailyphrase.prize.domain.repository.PrizeTicketRepository;
Expand All @@ -14,4 +16,8 @@ public class PrizeTicketCommandAdapter {
public void create(PrizeTicket prizeTicket) {
prizeTicketRepository.save(prizeTicket);
}

public void createMultiple(List<PrizeTicket> prizeTicketList) {
prizeTicketRepository.saveAll(prizeTicketList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;

import com.nexters.dailyphrase.common.annotation.Adapter;
import com.nexters.dailyphrase.common.enums.PrizeTicketSource;
import com.nexters.dailyphrase.common.enums.PrizeTicketStatus;
import com.nexters.dailyphrase.prize.domain.PrizeTicket;
import com.nexters.dailyphrase.prize.domain.repository.PrizeTicketRepository;
Expand All @@ -21,12 +22,16 @@ public Integer countPrizeTicketByMemberIdAndLocalDate(
LocalDateTime startOfDay = date.atStartOfDay();
LocalDateTime endOfDay = date.atTime(23, 59, 59);

return prizeTicketRepository.countByMemberIdAndCreatedAtBetween(
memberId, startOfDay, endOfDay);
return prizeTicketRepository.countByMemberIdAndCreatedAtBetweenAndSource(
memberId, startOfDay, endOfDay, PrizeTicketSource.SHARE);
}

public List<PrizeTicket> findPrizeTicketByMemberIdAndStatus(
final Long memberId, final PrizeTicketStatus status, final int count) {
return prizeTicketRepository.findByMemberIdAndStatus(memberId, status, count);
}

public boolean existsByMemberIdAndSource(Long memberId, PrizeTicketSource prizeTicketSource) {
return prizeTicketRepository.existsByMemberIdAndSource(memberId, prizeTicketSource);
}
}

0 comments on commit d8ba521

Please sign in to comment.