Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/#74 cors #75

Merged
merged 5 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified Server/gradlew
100644 β†’ 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import JGS.CasperEvent.domain.event.entity.event.LotteryEvent;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

public record LotteryEventResponseDto(Long lotteryEventId, LocalDate startDate, LocalDate endDate,
int winnerCount) {
public static LotteryEventResponseDto of(LotteryEvent lotteryEvent) {
public record LotteryEventResponseDto(LocalDateTime serverDateTime, LocalDate eventStartDate, LocalDate eventEndDate,
long activePeriod) {
public static LotteryEventResponseDto of(LocalDateTime serverDateTime, LotteryEvent lotteryEvent) {
return new LotteryEventResponseDto(
lotteryEvent.getLotteryEventId(),
lotteryEvent.getStartDate(),
lotteryEvent.getEndDate(),
lotteryEvent.getWinnerCount()
serverDateTime,
lotteryEvent.getEventStartDate(),
lotteryEvent.getEventEndDate(),
ChronoUnit.DAYS.between(lotteryEvent.getEventStartDate(), lotteryEvent.getEventEndDate())
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public record RushEventResponseDto(Long rushEventId, LocalDate startDate, LocalD
public static RushEventResponseDto of (RushEvent rushEvent){
return new RushEventResponseDto(
rushEvent.getRushEventId(),
rushEvent.getStartDate(),
rushEvent.getEndDate(),
rushEvent.getEventStartDate(),
rushEvent.getEventEndDate(),
rushEvent.getWinnerCount(),
rushEvent.getPrizeImageUrl(),
rushEvent.getPrizeDescription(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import java.time.LocalDate;

public class BaseEvent extends BaseEntity {
protected LocalDate startDate;
protected LocalDate endDate;
protected LocalDate eventStartDate;
protected LocalDate eventEndDate;
protected int winnerCount;

public LocalDate getStartDate() {
return startDate;
public LocalDate getEventStartDate() {
return eventStartDate;
}

public LocalDate getEndDate() {
return endDate;
public LocalDate getEventEndDate() {
return eventEndDate;
}

public int getWinnerCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public LotteryParticipants() {
}

public void expectationAdded() {
expectations++;
appliedCount = Math.max(10, appliedCount + 1);
if(expectations == 0) expectations++;
appliedCount = Math.min(10, 1 + expectations + linkClickedCount);
}

public void linkClickedCountAdded() {
linkClickedCount++;
appliedCount = Math.max(10, appliedCount + 1);
appliedCount = Math.min(10, 1 + expectations + linkClickedCount);
}

public LotteryParticipants(BaseUser baseUser) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@
import JGS.CasperEvent.global.enums.CustomErrorCode;
import JGS.CasperEvent.global.error.exception.CustomException;
import JGS.CasperEvent.global.jwt.repository.UserRepository;
import org.apache.coyote.BadRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.nio.file.attribute.UserPrincipalNotFoundException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

@Service
@Transactional
public class LotteryEventService {

private final UserRepository userRepository;
private LotteryEventRepository lotteryEventRepository;
private LotteryParticipantsRepository lotteryParticipantsRepository;
private CasperBotRepository casperBotRepository;
private RedisService redisService;
private final LotteryEventRepository lotteryEventRepository;
private final LotteryParticipantsRepository lotteryParticipantsRepository;
private final CasperBotRepository casperBotRepository;
private final RedisService redisService;

@Autowired
public LotteryEventService(LotteryEventRepository lotteryEventRepository,
Expand All @@ -44,13 +45,13 @@ public LotteryEventService(LotteryEventRepository lotteryEventRepository,
this.userRepository = userRepository;
}

public CasperBotResponseDto postCasperBot(BaseUser user, CasperBotRequestDto postCasperBot) throws CustomException, BadRequestException {
public CasperBotResponseDto postCasperBot(BaseUser user, CasperBotRequestDto postCasperBot) throws CustomException {
LotteryParticipants participants = registerUserIfNeed(user);

CasperBot casperBot = new CasperBot(postCasperBot, participants.getBaseUser().getId());
participants.updateCasperId(casperBot.getCasperId());

if (casperBot.getExpectation() != null) participants.expectationAdded();
if (!casperBot.getExpectation().isEmpty()) participants.expectationAdded();
lotteryParticipantsRepository.save(participants);
casperBotRepository.save(casperBot);

Expand All @@ -72,7 +73,7 @@ public CasperBotResponseDto getCasperBot(Long casperId) {
}


public LotteryParticipants registerUserIfNeed(BaseUser user) {
public LotteryParticipants registerUserIfNeed(BaseUser user) {
LotteryParticipants participant = lotteryParticipantsRepository.findByBaseUser(user).orElse(null);

if (participant == null) {
Expand All @@ -87,8 +88,11 @@ public LotteryParticipants registerUserIfNeed(BaseUser user) {
}

// TODO: κ°€μ§œ API, DB μ ‘μ†λ˜λ„λ‘ μˆ˜μ •
public LotteryEventResponseDto getLotteryEvent(){
return new LotteryEventResponseDto(1L, LocalDate.of(2000, 9, 27), LocalDate.of(2100, 9, 27), 363);
public LotteryEventResponseDto getLotteryEvent() {
return new LotteryEventResponseDto(LocalDateTime.now(),
LocalDate.of(2000, 9, 27),
LocalDate.of(2100, 9, 27),
ChronoUnit.DAYS.between(LocalDate.of(2000, 9, 27), LocalDate.of(2100, 9, 27)));
}

}
21 changes: 11 additions & 10 deletions Server/src/main/java/JGS/CasperEvent/global/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
@Configuration
public class WebConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registration) {
registration.addMapping("/**")
.allowCredentials(true)
.allowedOrigins("http://localhost:5173", "https://d3phfzvzx3wm4l.cloudfront.net/")
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*");
}
// @Override
// public void addCorsMappings(CorsRegistry registration) {
// registration.addMapping("/**")
// .allowCredentials(true)
// .allowedOrigins("http://localhost:5173", "https://d3phfzvzx3wm4l.cloudfront.net/")
// .allowedMethods("GET", "POST", "PUT", "DELETE")
// .allowedHeaders("*");
// }

@Bean
public FilterRegistrationBean<CorsFilter> corsFilterRegistrationBean() {
Expand All @@ -44,8 +44,9 @@ public UrlBasedCorsConfigurationSource corsConfigurationSource() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("http://localhost:5173"); // ν—ˆμš©ν•  좜처λ₯Ό λͺ…μ‹œ
config.addAllowedOrigin("https://d3phfzvzx3wm4l.cloudfront.net/"); // ν—ˆμš©ν•  좜처λ₯Ό λͺ…μ‹œ
config.addAllowedOrigin("http://localhost:5173");
config.addAllowedOrigin("https://d3phfzvzx3wm4l.cloudfront.net/");
config.addAllowedOrigin("https://hybrid-jgs.shop");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/**", config);
Expand Down
Binary file added Server/src/main/resources/.DS_Store
Binary file not shown.
Loading