Skip to content

Commit

Permalink
Merge pull request #107 from softeerbootcamp4th/feat/#106-get-rush-ev…
Browse files Browse the repository at this point in the history
…ents

Feat/#106 get rush events
  • Loading branch information
wjddn2165 authored Aug 13, 2024
2 parents 4b7b7ee + dde40bc commit a2e659e
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto;
import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto;
import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsListResponseDto;
import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventResponseDto;
import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventResponseDto;
import JGS.CasperEvent.domain.event.service.adminService.AdminService;
import JGS.CasperEvent.global.response.ResponseDto;
Expand Down Expand Up @@ -71,4 +72,12 @@ public ResponseEntity<RushEventResponseDto> createRushEvent(
.status(HttpStatus.CREATED)
.body(adminService.createRushEvent(rushEventRequestDto, prizeImg, leftOptionImg, rightOptionImg));
}

// 선착순 이벤트 전체 조회
@GetMapping("/event/rush")
public ResponseEntity<List<AdminRushEventResponseDto>> getRushEvents(){
return ResponseEntity
.status(HttpStatus.OK)
.body(adminService.getRushEvents());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto;

import JGS.CasperEvent.domain.event.entity.event.RushEvent;
import JGS.CasperEvent.global.enums.EventStatus;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public record AdminRushEventResponseDto(Long rushEventId, LocalDate eventDate,
LocalTime startTime, LocalTime endTime,
int winnerCount, String prizeImageUrl,
String prizeDescription, LocalDateTime createdAt, LocalDateTime updatedAt,
EventStatus status, Set<RushEventOptionResponseDto> options) {

public static List<AdminRushEventResponseDto> of(List<RushEvent> rushEvents) {
List<AdminRushEventResponseDto> dtoList = new ArrayList<>();
for (RushEvent rushEvent : rushEvents) {
Set<RushEventOptionResponseDto> options = rushEvent.getOptions().stream()
.map(RushEventOptionResponseDto::of)
.collect(Collectors.toSet());

LocalDateTime now = LocalDateTime.now();
EventStatus status;
if (now.isBefore(rushEvent.getStartDateTime())) status = EventStatus.BEFORE;
else if (now.isAfter(rushEvent.getEndDateTime())) status = EventStatus.AFTER;
else status = EventStatus.DURING;

dtoList.add(new AdminRushEventResponseDto(
rushEvent.getRushEventId(),
rushEvent.getStartDateTime().toLocalDate(),
rushEvent.getStartDateTime().toLocalTime(),
rushEvent.getEndDateTime().toLocalTime(),
rushEvent.getWinnerCount(),
rushEvent.getPrizeImageUrl(),
rushEvent.getPrizeDescription(),
rushEvent.getCreatedAt(),
rushEvent.getUpdatedAt(),
status,
options
));
}

return dtoList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@
import JGS.CasperEvent.domain.event.entity.event.RushOption;
import JGS.CasperEvent.global.enums.Position;

public record RushEventOptionResponseDto(String mainText, String subText, String resultMainText, String resultSubText, String imageUrl, Position position) {
import java.time.LocalDateTime;

public record RushEventOptionResponseDto(long optionId, String mainText,
String subText, String resultMainText,
String resultSubText, String imageUrl,
Position position, LocalDateTime createdAt, LocalDateTime updatedAt) {
public static RushEventOptionResponseDto of(RushOption rushOption) {
return new RushEventOptionResponseDto(
rushOption.getOptionId(),
rushOption.getMainText(),
rushOption.getSubText(),
rushOption.getResultMainText(),
rushOption.getResultSubText(),
rushOption.getImageUrl(),
rushOption.getPosition()
rushOption.getPosition(),
rushOption.getCreatedAt(),
rushOption.getUpdatedAt()
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsListResponseDto;
import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsResponseDto;
import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto;
import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventResponseDto;
import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventResponseDto;
import JGS.CasperEvent.domain.event.entity.admin.Admin;
import JGS.CasperEvent.domain.event.entity.event.LotteryEvent;
Expand Down Expand Up @@ -147,4 +148,9 @@ public RushEventResponseDto createRushEvent(RushEventRequestDto rushEventRequest

return RushEventResponseDto.of(rushEvent);
}

public List<AdminRushEventResponseDto> getRushEvents(){
List<RushEvent> rushEvents = rushEventRepository.findAll();
return AdminRushEventResponseDto.of(rushEvents);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package JGS.CasperEvent.global.config;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Profile("local")
public class LocalS3Config {
@Value("${spring.cloud.aws.credentials.accessKey}")
private String accessKey;

@Value("${spring.cloud.aws.credentials.secretKey}")
private String secretKey;

@Value("${spring.cloud.aws.s3.region}")
private String region;

@Bean
public AmazonS3 amazonS3(){
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

return AmazonS3ClientBuilder
.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(region)
.build();
}
}
25 changes: 4 additions & 21 deletions Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
package JGS.CasperEvent.global.config;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Profile("prod")
public class S3Config {
@Value("${spring.cloud.aws.credentials.accessKey}")
private String accessKey;

@Value("${spring.cloud.aws.credentials.secretKey}")
private String secretKey;

@Value("${spring.cloud.aws.s3.region}")
private String region;

@Bean
public AmazonS3 amazonS3(){
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

return AmazonS3ClientBuilder
.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(region)
.build();
return AmazonS3ClientBuilder.defaultClient();
}
}
}
16 changes: 16 additions & 0 deletions Server/src/main/java/JGS/CasperEvent/global/enums/EventStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package JGS.CasperEvent.global.enums;

import lombok.Getter;

@Getter
public enum EventStatus {
BEFORE(1),
DURING(2),
AFTER(3);

private final int eventStatus;

EventStatus(int eventStatus){
this.eventStatus = eventStatus;
}
}
3 changes: 0 additions & 3 deletions Server/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ spring:
s3:
bucket: ${S3_IMAGE_SERVER}
region: ap-northeast-2
credentials:
accessKey: ${AWS_ACCESS_KEY}
secretKey: ${AWS_SECRET_KEY}


client:
Expand Down

0 comments on commit a2e659e

Please sign in to comment.