Skip to content

Commit

Permalink
Merge pull request #193 from softeerbootcamp4th/feature/#192-rush-eve…
Browse files Browse the repository at this point in the history
…nt-result-fix

Feature/#192 rush event result fix
  • Loading branch information
k000927 authored Aug 20, 2024
2 parents f83e54d + bc6f748 commit 3ac281d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package JGS.CasperEvent.domain.event.dto.RequestDto;

import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.*;

@Getter
@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@Getter
@AllArgsConstructor
public class RushEventResultResponseDto {
private final Integer optionId;
private final Long leftOption;
private final Long rightOption;
private final Long rank;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public RushEventResultResponseDto getRushEventResult(BaseUser user) {
Optional<Integer> optionIdOptional = rushParticipantsRepository.getOptionIdByUserId(user.getId());
if (optionIdOptional.isEmpty()) {
return new RushEventResultResponseDto(
null,
leftOption,
rightOption,
null,
Expand All @@ -123,6 +124,9 @@ public RushEventResultResponseDto getRushEventResult(BaseUser user) {
);
}

// optionId 를 꺼냄
int optionId = optionIdOptional.get();

// 동점인 경우
if (leftOption == rightOption) {
// 전체 참여자에서 등수 계산하기
Expand All @@ -134,25 +138,23 @@ public RushEventResultResponseDto getRushEventResult(BaseUser user) {
// 당첨 여부
boolean isWinner = rank <= todayRushEvent.winnerCount();

return new RushEventResultResponseDto(leftOption, rightOption, rank, totalParticipants, isWinner);
return new RushEventResultResponseDto(optionId, leftOption, rightOption, rank, totalParticipants, isWinner);
}

int optionId = optionIdOptional.get();

long totalParticipants = (optionId == 1 ? leftOption : rightOption);

// eventId, userId, optionId 를 이용하여 해당 유저가 응모한 선택지에서 등수를 가져옴
long rank = rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(todayRushEvent.rushEventId(), user.getId(), optionId);

// 해당 유저가 선택한 옵션이 패배한 경우
if ((optionId == 1 && leftOption < rightOption) || (optionId == 2 && leftOption > rightOption)) {
return new RushEventResultResponseDto(leftOption, rightOption, rank, totalParticipants, false);
return new RushEventResultResponseDto(optionId, leftOption, rightOption, rank, totalParticipants, false);
}

// 당첨 여부
boolean isWinner = rank <= todayRushEvent.winnerCount();

return new RushEventResultResponseDto(leftOption, rightOption, rank, totalParticipants, isWinner);
return new RushEventResultResponseDto(optionId, leftOption, rightOption, rank, totalParticipants, isWinner);
}

// 오늘의 이벤트를 DB에 꺼내서 반환
Expand Down
92 changes: 8 additions & 84 deletions Server/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<configuration>

<!-- 공통 콘솔 출력 설정 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
Expand All @@ -11,118 +10,43 @@
<springProfile name="local">
<appender name="INFO_FILE_LOCAL" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./logs/info.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>./logs/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg [%X{requestId}]%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>

<appender name="ERROR_FILE_LOCAL" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./logs/error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>./logs/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg [%X{requestId}]%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>

<appender name="WARN_FILE_LOCAL" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./logs/warn.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>./logs/warn.%d{yyyy-MM-dd}.log</fileNamePattern>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>./logs/info.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg [%X{requestId}]%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>

<!-- 루트 로거 설정 -->
<root level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="INFO_FILE_LOCAL" />
<appender-ref ref="ERROR_FILE_LOCAL" />
<appender-ref ref="WARN_FILE_LOCAL" />
</root>
</springProfile>

<!-- 프로덕션 환경 -->
<springProfile name="prod">
<appender name="INFO_FILE_PROD" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/logs/info.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/logs/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>/logs/info.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg [%X{requestId}]%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>

<appender name="ERROR_FILE_PROD" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/logs/error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/logs/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg [%X{requestId}]%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>

<appender name="WARN_FILE_PROD" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/logs/warn.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/logs/warn.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg [%X{requestId}]%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>

<!-- 루트 로거 설정 -->
<root level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="INFO_FILE_PROD" />
<appender-ref ref="ERROR_FILE_PROD" />
<appender-ref ref="WARN_FILE_PROD" />
</root>
</springProfile>

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void setUp() throws Exception {
given(rushEventService.getRushEventRate(any())).willReturn(rushEventRateResponseDto);

RushEventResultResponseDto rushEventResultResponseDto = new RushEventResultResponseDto(
1,
315L,
1000L,
1L,
Expand Down Expand Up @@ -245,6 +246,7 @@ public void getRushEventResultTest() throws Exception {

// then
perform.andExpect(status().isOk())
.andExpect(jsonPath("$.optionId").value(1))
.andExpect(jsonPath("$.leftOption").value(315))
.andExpect(jsonPath("$.rightOption").value(1000))
.andExpect(jsonPath("$.rank").value(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ void getRushEventResult() {

// then
assertNotNull(result);
assertEquals(1, result.getOptionId());
assertEquals(700, result.getLeftOption());
assertEquals(500, result.getRightOption());
assertEquals(700, result.getTotalParticipants());
Expand Down Expand Up @@ -258,6 +259,7 @@ void getRushEventResult2() {

// then
assertNotNull(result);
assertEquals(2, result.getOptionId());
assertEquals(700, result.getLeftOption());
assertEquals(500, result.getRightOption());
assertEquals(500, result.getTotalParticipants());
Expand Down Expand Up @@ -292,6 +294,7 @@ void getRushEventResult3() {

// then
assertNotNull(result);
assertEquals(1, result.getOptionId());
assertEquals(700, result.getLeftOption());
assertEquals(500, result.getRightOption());
assertEquals(700, result.getTotalParticipants());
Expand Down Expand Up @@ -325,6 +328,7 @@ void getRushEventResult4() {

// then
assertNotNull(result);
assertEquals(1, result.getOptionId());
assertEquals(500, result.getLeftOption());
assertEquals(500, result.getRightOption());
assertEquals(1000, result.getTotalParticipants());
Expand Down Expand Up @@ -358,6 +362,7 @@ void getRushEventResult5() {

// then
assertNotNull(result);
assertEquals(1, result.getOptionId());
assertEquals(500, result.getLeftOption());
assertEquals(500, result.getRightOption());
assertEquals(1000, result.getTotalParticipants());
Expand Down

0 comments on commit 3ac281d

Please sign in to comment.