Skip to content

Commit

Permalink
Merge branch 'dev' into feat/#81-lottery-event
Browse files Browse the repository at this point in the history
  • Loading branch information
k000927 authored Aug 11, 2024
2 parents 5bb3d81 + 1cbf11c commit 57627e0
Show file tree
Hide file tree
Showing 24 changed files with 398 additions and 124 deletions.
1 change: 0 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ env:
jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions Server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5")
annotationProcessor('org.projectlombok:lombok')
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.3'

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package JGS.CasperEvent.domain.event.controller.eventController;


import JGS.CasperEvent.domain.event.dto.ResponseDto.RushEventListAndServerTimeResponseDto;
import JGS.CasperEvent.domain.event.dto.ResponseDto.RushEventListResponseDto;
import JGS.CasperEvent.domain.event.dto.ResponseDto.RushEventRateResponseDto;
import JGS.CasperEvent.domain.event.dto.ResponseDto.RushEventResultResponseDto;
import JGS.CasperEvent.domain.event.service.eventService.RushEventService;
import JGS.CasperEvent.global.entity.BaseUser;
import jakarta.servlet.http.HttpServletRequest;
Expand All @@ -20,7 +21,7 @@ public RushEventController(RushEventService rushEventService) {

// 전체 선착순 이벤트 조회
@GetMapping
public ResponseEntity<RushEventListAndServerTimeResponseDto> getRushEventListAndServerTime() {
public ResponseEntity<RushEventListResponseDto> getRushEventListAndServerTime() {
return ResponseEntity.ok(rushEventService.getAllRushEvents());
}

Expand All @@ -47,4 +48,19 @@ public ResponseEntity<RushEventRateResponseDto> rushEventRate (@PathVariable("ev
RushEventRateResponseDto rushEventRateResponseDto = rushEventService.getRushEventRate(eventId);
return ResponseEntity.ok(rushEventRateResponseDto);
}

// 밸런스 게임 결과 조회
@GetMapping("/{eventId}/result")
public ResponseEntity<RushEventResultResponseDto> rushEventResult(HttpServletRequest httpServletRequest, @PathVariable("eventId") Long eventId) {
BaseUser user = (BaseUser) httpServletRequest.getAttribute("user");
RushEventResultResponseDto result = rushEventService.getRushEventResult(user, eventId);
return ResponseEntity.ok(result);
}

// 레디스에 오늘의 이벤트 등록 테스트 api
@GetMapping("/today/test")
public ResponseEntity<Void> setTodayEvent() {
rushEventService.setTodayEventToRedis();
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

public record LotteryEventResponseDto(LocalDateTime serverDateTime, LocalDateTime eventStartDate,
LocalDateTime eventEndDate,
public record LotteryEventResponseDto(LocalDateTime serverDateTime, LocalDateTime eventStartDate, LocalDateTime eventEndDate,
long activePeriod) {
public static LotteryEventResponseDto of(LotteryEvent lotteryEvent, LocalDateTime serverDateTime) {
return new LotteryEventResponseDto(
serverDateTime,
lotteryEvent.getEventStartDate(),
lotteryEvent.getEventEndDate(),
ChronoUnit.DAYS.between(lotteryEvent.getEventStartDate(), lotteryEvent.getEventEndDate())
lotteryEvent.getStartDateTime(),
lotteryEvent.getEndDateTime(),
ChronoUnit.DAYS.between(lotteryEvent.getStartDateTime(), lotteryEvent.getEndDateTime())
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package JGS.CasperEvent.domain.event.dto.ResponseDto;

import JGS.CasperEvent.domain.event.entity.event.RushEvent;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
public class MainRushEventResponseDto {
private Long rushEventId;
private LocalDateTime startDateTime;
private LocalDateTime endDateTime;

public MainRushEventResponseDto(Long rushEventId, LocalDateTime startDateTime, LocalDateTime endDateTime) {
this.rushEventId = rushEventId;
this.startDateTime = startDateTime;
this.endDateTime = endDateTime;
}

public static MainRushEventResponseDto of (RushEvent rushEvent) {
return new MainRushEventResponseDto(
rushEvent.getRushEventId(),
rushEvent.getStartDateTime(),
rushEvent.getEndDateTime()
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package JGS.CasperEvent.domain.event.dto.ResponseDto;

import lombok.Getter;

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

@Getter
public class RushEventListResponseDto {
private List<MainRushEventResponseDto> events;
private LocalDateTime serverTime;
private Long todayEventId;
private LocalDate eventStartDate;
private LocalDate eventEndDate;
private Long activePeriod;

public RushEventListResponseDto(List<MainRushEventResponseDto> events, LocalDateTime serverTime, Long todayEventId, LocalDate eventStartDate, LocalDate eventEndDate, Long activePeriod) {
this.events = events;
this.serverTime = serverTime;
this.todayEventId = todayEventId;
this.eventStartDate = eventStartDate;
this.eventEndDate = eventEndDate;
this.activePeriod = activePeriod;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,5 @@
import lombok.Getter;

@Getter
public class RushEventRateResponseDto {
long leftOption;
long rightOption;

public RushEventRateResponseDto(long leftOption, long rightOption) {
this.leftOption = leftOption;
this.rightOption = rightOption;
}
public record RushEventRateResponseDto(long leftOption, long rightOption) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
import JGS.CasperEvent.domain.event.entity.event.RushEvent;
import JGS.CasperEvent.domain.event.entity.event.RushOption;

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

public record RushEventResponseDto(Long rushEventId, LocalDateTime startDate, LocalDateTime endDate,
public record RushEventResponseDto(Long rushEventId, LocalDateTime startDateTime, LocalDateTime endDateTime,
int winnerCount, String prizeImageUrl, String prizeDescription,
RushOption leftOption, RushOption rightOption){
Set<RushOption> options){

public static RushEventResponseDto of (RushEvent rushEvent){
return new RushEventResponseDto(
rushEvent.getRushEventId(),
rushEvent.getEventStartDate(),
rushEvent.getEventEndDate(),
rushEvent.getStartDateTime(),
rushEvent.getEndDateTime(),
rushEvent.getWinnerCount(),
rushEvent.getPrizeImageUrl(),
rushEvent.getPrizeDescription(),
rushEvent.getLeftOption(),
rushEvent.getRightOption()
rushEvent.getOptions()
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package JGS.CasperEvent.domain.event.dto.ResponseDto;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class RushEventResultResponseDto {
private final long leftOption;
private final long rightOption;
private final long rank;
private final long totalParticipants;
private final long winnerCount;

public RushEventResultResponseDto(RushEventRateResponseDto rushEventRateResponseDto, long rank, long totalParticipants, long winnerCount) {
this.leftOption = rushEventRateResponseDto.leftOption();
this.rightOption = rushEventRateResponseDto.rightOption();
this.rank = rank;
this.totalParticipants = totalParticipants;
this.winnerCount = winnerCount;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
package JGS.CasperEvent.domain.event.entity.event;

import JGS.CasperEvent.global.entity.BaseEntity;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;

import java.time.LocalDateTime;

@MappedSuperclass
@Getter
@MappedSuperclass
public class BaseEvent extends BaseEntity {
protected LocalDateTime eventStartDate;
protected LocalDateTime eventEndDate;
protected int winnerCount;
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime startDateTime;

@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime endDateTime;
private int winnerCount;

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

// 특정 값을 설정할 수 있는 생성자
public BaseEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, int winnerCount) {
this.startDateTime = startDateTime;
this.endDateTime = endDateTime;
this.winnerCount = winnerCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import JGS.CasperEvent.domain.event.entity.participants.RushParticipants;
import jakarta.persistence.*;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.Set;

@Entity
@Getter
public class RushEvent extends BaseEvent {
private String prizeImageUrl;
private String prizeDescription;
Expand All @@ -14,43 +17,26 @@ public class RushEvent extends BaseEvent {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long rushEventId;

@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "rush_event_id")
private RushOption leftOption;

@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "rush_event_id")
private RushOption rightOption;
private Set<RushOption> options;

@OneToMany(mappedBy = "rushEvent", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<RushParticipants> rushParticipants;

public RushEvent() {
}

// 파라미터가 있는 생성자
public RushEvent(String prizeImageUrl, String prizeDescription) {
super();
this.prizeImageUrl = prizeImageUrl;
this.prizeDescription = prizeDescription;
}

public String getPrizeImageUrl() {
return prizeImageUrl;
}

public String getPrizeDescription() {
return prizeDescription;
}

public RushOption getLeftOption() {
return leftOption;
}

public RushOption getRightOption() {
return rightOption;
}

public Long getRushEventId() {
return rushEventId;
public RushEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, int winnerCount, String prizeImageUrl, String prizeDescription) {
super(startDateTime, endDateTime, winnerCount);
this.prizeImageUrl = prizeImageUrl;
this.prizeDescription = prizeDescription;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@

import JGS.CasperEvent.global.entity.BaseEntity;
import jakarta.persistence.*;
import lombok.NoArgsConstructor;

@Entity
public class RushOption extends BaseEntity{
@NoArgsConstructor
public class RushOption extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long optionId;

@OneToOne
@ManyToOne
@JoinColumn(name = "rush_event_id")
private RushEvent rushEvent;

@Id
private int optionId;
private String mainText;
private String subText;
private String resultMainText;
private String resultSubText;
private String imageUrl;

public RushOption(RushEvent rushEvent, String mainText, String subText, String resultMainText, String resultSubText, String imageUrl) {
this.rushEvent = rushEvent;
this.mainText = mainText;
this.subText = subText;
this.resultMainText = resultMainText;
this.resultSubText = resultSubText;
this.imageUrl = imageUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import JGS.CasperEvent.domain.event.entity.event.RushEvent;
import JGS.CasperEvent.global.entity.BaseUser;
import com.fasterxml.jackson.annotation.JsonBackReference;
import jakarta.persistence.*;

@Entity
Expand All @@ -12,6 +13,7 @@ public class RushParticipants {
private int optionId;
@OneToOne
@JoinColumn(name = "base_user_id")
@JsonBackReference
private BaseUser baseUser;

@ManyToOne
Expand Down
Loading

0 comments on commit 57627e0

Please sign in to comment.