Skip to content

Commit

Permalink
Merge pull request #232 from softeerbootcamp4th/fix/#231-get-applied-…
Browse files Browse the repository at this point in the history
…count

fix/#231-get-applied-count
  • Loading branch information
k000927 authored Aug 23, 2024
2 parents fc6c829 + 25cba11 commit e684461
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package JGS.CasperEvent.domain.event.controller.adminController;

import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto;
import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto;
import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto;
import JGS.CasperEvent.domain.event.dto.request.AdminRequestDto;
import JGS.CasperEvent.domain.event.dto.request.lotteryEventDto.LotteryEventRequestDto;
import JGS.CasperEvent.domain.event.dto.request.rushEventDto.RushEventRequestDto;
import JGS.CasperEvent.domain.event.dto.response.ImageUrlResponseDto;
import JGS.CasperEvent.domain.event.dto.response.ParticipantsListResponseDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.ExpectationsPagingResponseDto;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package JGS.CasperEvent.domain.event.controller.eventController;

import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.request.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.CasperBotResponseDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.LotteryEventParticipantResponseDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.LotteryEventResponseDto;
Expand Down Expand Up @@ -61,7 +61,7 @@ public ResponseEntity<LotteryEventResponseDto> getLotteryEvent() {
@PostMapping("/casperBot")
public ResponseEntity<CasperBotResponseDto> postCasperBot(
HttpServletRequest request,
@RequestBody @Valid CasperBotRequestDto postCasperBot) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
@RequestBody @Valid CasperBotRequestDto postCasperBot) {
BaseUser user = (BaseUser) request.getAttribute("user");
return ResponseEntity
.status(HttpStatus.CREATED)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JGS.CasperEvent.domain.event.dto.RequestDto;
package JGS.CasperEvent.domain.event.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto;
package JGS.CasperEvent.domain.event.dto.request.lotteryEventDto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto;
package JGS.CasperEvent.domain.event.dto.request.lotteryEventDto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto;
package JGS.CasperEvent.domain.event.dto.request.rushEventDto;

import io.swagger.v3.oas.annotations.media.Schema;
import JGS.CasperEvent.global.enums.Position;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto;
package JGS.CasperEvent.domain.event.dto.request.rushEventDto;

import io.swagger.v3.oas.annotations.media.Schema;
import JGS.CasperEvent.global.enums.CustomErrorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class LotteryEventResponseDto {
private EventStatus status;


private int appliedCount;
private Long appliedCount;
private Long activePeriod;

private Long casperId;
Expand Down Expand Up @@ -58,7 +58,7 @@ public static LotteryEventResponseDto of(LotteryEvent lotteryEvent, LocalDateTim

private LotteryEventResponseDto(LocalDate startDate, LocalTime startTime,
LocalDate endDate, LocalTime endTime,
int appliedCount, int winnerCount,
Long appliedCount, int winnerCount,
EventStatus status,
LocalDateTime createdAt, LocalDateTime updatedAt) {
this.startDate = startDate;
Expand All @@ -72,7 +72,7 @@ private LotteryEventResponseDto(LocalDate startDate, LocalTime startTime,
this.updatedAt = updatedAt;
}

public static LotteryEventResponseDto withDetail(LotteryEvent event) {
public static LotteryEventResponseDto withDetail(LotteryEvent event, Long appliedCount) {
EventStatus status;
LocalDateTime now = LocalDateTime.now();

Expand All @@ -85,7 +85,7 @@ public static LotteryEventResponseDto withDetail(LotteryEvent event) {
event.getStartDateTime().toLocalTime(),
event.getEndDateTime().toLocalDate(),
event.getEndDateTime().toLocalTime(),
event.getTotalAppliedCount(),
appliedCount,
event.getWinnerCount(),
status,
event.getCreatedAt(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package JGS.CasperEvent.domain.event.entity.casperBot;

import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.request.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.global.entity.BaseEntity;
import jakarta.persistence.*;
import lombok.EqualsAndHashCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,18 @@ public class BaseEvent extends BaseEntity {
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
protected LocalDateTime endDateTime;
protected int winnerCount;
protected int totalAppliedCount;

// 기본 생성자에서 디폴트 값 설정
public BaseEvent() {
this.startDateTime = LocalDateTime.now();
this.endDateTime = LocalDateTime.now().plusMinutes(10);
this.winnerCount = 0; // 기본 우승자 수를 0으로 설정
this.totalAppliedCount = 0;
}

// 특정 값을 설정할 수 있는 생성자
public BaseEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, int winnerCount) {
this.startDateTime = startDateTime;
this.endDateTime = endDateTime;
this.winnerCount = winnerCount;
this.totalAppliedCount = 0;
}

public void addAppliedCount() {
this.totalAppliedCount++;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package JGS.CasperEvent.domain.event.entity.event;

import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto;
import JGS.CasperEvent.domain.event.dto.request.rushEventDto.RushEventRequestDto;
import JGS.CasperEvent.domain.event.entity.participants.RushParticipants;
import JGS.CasperEvent.global.enums.CustomErrorCode;
import JGS.CasperEvent.global.enums.Position;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package JGS.CasperEvent.domain.event.entity.event;

import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventOptionRequestDto;
import JGS.CasperEvent.domain.event.dto.request.rushEventDto.RushEventOptionRequestDto;
import JGS.CasperEvent.global.entity.BaseEntity;
import JGS.CasperEvent.global.enums.Position;
import com.fasterxml.jackson.annotation.JsonBackReference;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package JGS.CasperEvent.domain.event.service.adminService;

import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto;
import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto;
import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventOptionRequestDto;
import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto;
import JGS.CasperEvent.domain.event.dto.request.AdminRequestDto;
import JGS.CasperEvent.domain.event.dto.request.lotteryEventDto.LotteryEventRequestDto;
import JGS.CasperEvent.domain.event.dto.request.rushEventDto.RushEventOptionRequestDto;
import JGS.CasperEvent.domain.event.dto.request.rushEventDto.RushEventRequestDto;
import JGS.CasperEvent.domain.event.dto.response.ImageUrlResponseDto;
import JGS.CasperEvent.domain.event.dto.response.ParticipantsListResponseDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.CasperBotResponseDto;
Expand Down Expand Up @@ -106,7 +106,8 @@ public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lottery

// 추첨 이벤트 조회
public LotteryEventResponseDto getLotteryEvent() {
return LotteryEventResponseDto.withDetail(getCurrentLotteryEvent());
long appliedCount = lotteryParticipantsRepository.count();
return LotteryEventResponseDto.withDetail(getCurrentLotteryEvent(), appliedCount);
}

// 추첨 이벤트 참여자 조회
Expand Down Expand Up @@ -318,7 +319,8 @@ else if (newStartDateTime.isBefore(now)) {
// 필드 업데이트
currentLotteryEvent.updateLotteryEvent(newStartDateTime, newEndDateTime, lotteryEventRequestDto.getWinnerCount());
eventCacheService.setLotteryEvent();
return LotteryEventResponseDto.withDetail(currentLotteryEvent);
Long appliedCount = lotteryParticipantsRepository.count();
return LotteryEventResponseDto.withDetail(currentLotteryEvent, appliedCount);
}

// 추첨 이벤트 조회
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package JGS.CasperEvent.domain.event.service.eventService;

import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.request.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.CasperBotResponseDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.LotteryEventParticipantResponseDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.LotteryEventResponseDto;
Expand Down Expand Up @@ -42,10 +42,9 @@ public class LotteryEventService {

public CasperBotResponseDto postCasperBot(BaseUser user, CasperBotRequestDto casperBotRequestDto) throws CustomException {
LotteryEvent lotteryEvent = eventCacheService.getLotteryEvent();
LotteryParticipants participants = registerUserIfNeed(lotteryEvent, user, casperBotRequestDto);
LotteryParticipants participants = registerUserIfNeed(user, casperBotRequestDto);

CasperBot casperBot = casperBotRepository.save(new CasperBot(casperBotRequestDto, user.getPhoneNumber()));
lotteryEvent.addAppliedCount();

participants.updateCasperId(casperBot.getCasperId());

Expand Down Expand Up @@ -74,15 +73,14 @@ public CasperBotResponseDto getCasperBot(Long casperId) {
}


public LotteryParticipants registerUserIfNeed(LotteryEvent lotteryEvent, BaseUser user, CasperBotRequestDto casperBotRequestDto) {
public LotteryParticipants registerUserIfNeed(BaseUser user, CasperBotRequestDto casperBotRequestDto) {
LotteryParticipants participant = lotteryParticipantsRepository.findByBaseUser(user).orElse(null);

if (participant == null) {
participant = new LotteryParticipants(user);
lotteryParticipantsRepository.save(participant);

addReferralAppliedCount(casperBotRequestDto);
} else lotteryEvent.addAppliedCount();
}

return participant;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package JGS.CasperEvent.global.jwt.filter;

import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto;
import JGS.CasperEvent.domain.event.dto.request.AdminRequestDto;
import JGS.CasperEvent.domain.event.entity.admin.Admin;
import JGS.CasperEvent.domain.event.service.adminService.AdminService;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package JGS.CasperEvent.domain.event.controller.adminController;

import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto;
import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto;
import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventOptionRequestDto;
import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto;
import JGS.CasperEvent.domain.event.dto.request.AdminRequestDto;
import JGS.CasperEvent.domain.event.dto.request.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.request.lotteryEventDto.LotteryEventRequestDto;
import JGS.CasperEvent.domain.event.dto.request.rushEventDto.RushEventOptionRequestDto;
import JGS.CasperEvent.domain.event.dto.request.rushEventDto.RushEventRequestDto;
import JGS.CasperEvent.domain.event.dto.response.ImageUrlResponseDto;
import JGS.CasperEvent.domain.event.dto.response.ParticipantsListResponseDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.ExpectationsPagingResponseDto;
Expand Down Expand Up @@ -162,7 +162,7 @@ void setUp() throws Exception {
this.lotteryEventParticipantsListResponseDto = new ParticipantsListResponseDto<>(participants, true, 1);

// 추첨 이벤트 상세 응답 DTO
lotteryEventDetailResponseDto = LotteryEventResponseDto.withDetail(lotteryEvent);
lotteryEventDetailResponseDto = LotteryEventResponseDto.withDetail(lotteryEvent, 1L);

// 캐스퍼 봇
casperBotRequestDto = CasperBotRequestDto.builder()
Expand Down Expand Up @@ -321,7 +321,7 @@ void postImageSuccessTest() throws Exception {
@DisplayName("추첨 이벤트 조회 성공 테스트")
void getLotteryEventSuccessTest() throws Exception {
//given
given(adminService.getLotteryEvent()).willReturn(LotteryEventResponseDto.withDetail(lotteryEvent));
given(adminService.getLotteryEvent()).willReturn(LotteryEventResponseDto.withDetail(lotteryEvent, 1L));

//when
ResultActions perform = mockMvc.perform(get("/admin/event/lottery").header("Authorization", accessToken).contentType(APPLICATION_JSON));
Expand All @@ -332,7 +332,7 @@ void getLotteryEventSuccessTest() throws Exception {
.andExpect(jsonPath("$.startTime").value("00:00:00"))
.andExpect(jsonPath("$.endDate").value("2100-09-27"))
.andExpect(jsonPath("$.endTime").value("00:00:00"))
.andExpect(jsonPath("$.appliedCount").value(0))
.andExpect(jsonPath("$.appliedCount").value(1L))
.andExpect(jsonPath("$.winnerCount").value(315))
.andExpect(jsonPath("$.status").value("DURING"))
.andDo(print());
Expand Down Expand Up @@ -619,7 +619,7 @@ void updateLotteryEventSuccessTest() throws Exception {
.andExpect(jsonPath("$.startTime").value("00:00:00"))
.andExpect(jsonPath("$.endDate").value("2100-09-27"))
.andExpect(jsonPath("$.endTime").value("00:00:00"))
.andExpect(jsonPath("$.appliedCount").value(0))
.andExpect(jsonPath("$.appliedCount").value(1L))
.andExpect(jsonPath("$.winnerCount").value(315))
.andExpect(jsonPath("$.status").value("DURING"))
.andDo(print());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package JGS.CasperEvent.domain.event.controller.eventController;

import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.request.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.CasperBotResponseDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.LotteryEventParticipantResponseDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.LotteryEventResponseDto;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package JGS.CasperEvent.domain.event.service.adminService;

import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto;
import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto;
import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventOptionRequestDto;
import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto;
import JGS.CasperEvent.domain.event.dto.request.AdminRequestDto;
import JGS.CasperEvent.domain.event.dto.request.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.request.lotteryEventDto.LotteryEventRequestDto;
import JGS.CasperEvent.domain.event.dto.request.rushEventDto.RushEventOptionRequestDto;
import JGS.CasperEvent.domain.event.dto.request.rushEventDto.RushEventRequestDto;
import JGS.CasperEvent.domain.event.dto.response.ImageUrlResponseDto;
import JGS.CasperEvent.domain.event.dto.response.ParticipantsListResponseDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.CasperBotResponseDto;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package JGS.CasperEvent.domain.event.service.eventService;

import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.request.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.CasperBotResponseDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.LotteryEventParticipantResponseDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.LotteryEventResponseDto;
Expand Down Expand Up @@ -65,7 +65,7 @@ class LotteryEventServiceTest {
private CasperBot casperBot;

@BeforeEach
void setUp() {
void setUp() {
byte[] decodedKey = "I0EM1X1NeXKJv4Q+ifZllg==".getBytes();
SecretKey secretKey = new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES");
ReflectionTestUtils.setField(lotteryEventService, "secretKey", secretKey);
Expand Down Expand Up @@ -100,7 +100,7 @@ void setUp() {

@Test
@DisplayName("캐스퍼 봇 등록 테스트 - 성공")
void postCasperBot_Success() throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
void postCasperBot_Success() {
//given
given(casperBotRepository.save(casperBot)).willReturn(casperBot);
given(eventCacheService.getLotteryEvent()).willReturn(lotteryEvent);
Expand Down

0 comments on commit e684461

Please sign in to comment.