From 2c32a16afd06f153f5ae7ca4177fa90ca861c528 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 11:03:11 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20CasperBotRequestDto=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=EC=97=90=20=EC=B6=94=EC=B2=9C=EC=9D=B8=20ID?= =?UTF-8?q?=20=EC=9E=85=EB=A0=A5=ED=95=98=EB=8A=94=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/dto/RequestDto/CasperBotRequestDto.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/CasperBotRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/CasperBotRequestDto.java index ef081d39..b30d7d3e 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/CasperBotRequestDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/CasperBotRequestDto.java @@ -35,6 +35,7 @@ public class CasperBotRequestDto { private String name; private String expectation; + private String referralId; public Integer getEyeShape() { From a402cc359fad10b31c168faf69388475c17378b8 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 11:04:34 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20Getter=EB=A5=BC=20=ED=86=B5?= =?UTF-8?q?=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EA=B0=84=EC=86=8C=ED=99=94,?= =?UTF-8?q?=20=EC=95=88=EC=93=B0=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/RequestDto/CasperBotRequestDto.java | 35 ++----------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/CasperBotRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/CasperBotRequestDto.java index b30d7d3e..f9a599b3 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/CasperBotRequestDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/CasperBotRequestDto.java @@ -3,7 +3,9 @@ import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; +import lombok.Getter; +@Getter public class CasperBotRequestDto { @NotNull(message = "눈 모양 값은 필수 필드입니다.") @@ -36,37 +38,4 @@ public class CasperBotRequestDto { private String expectation; private String referralId; - - - public Integer getEyeShape() { - return eyeShape; - } - - public Integer getEyePosition() { - return eyePosition; - } - - public Integer getMouthShape() { - return mouthShape; - } - - public Integer getColor() { - return color; - } - - public Integer getSticker() { - return sticker; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getExpectation() { - return expectation; - } } From 1521eeb1922b226826d46812d38019f7b7ac5fa8 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 11:21:06 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=EC=9C=A0=EC=A0=80=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=8B=9C=20=EC=B6=94=EC=B2=9C=EC=9D=B8=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=ED=95=98=EC=97=AC=20=EC=B6=94=EC=B2=9C=EC=9D=B8?= =?UTF-8?q?=EC=97=90=EA=B2=8C=20=EA=B0=80=EC=82=B0=EC=A0=90=20=EB=B6=80?= =?UTF-8?q?=EC=97=AC=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventController.java | 8 +++- .../eventService/LotteryEventService.java | 39 +++++++++++-------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventController.java index 244f236a..d391b37b 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventController.java @@ -9,13 +9,17 @@ import JGS.CasperEvent.global.entity.BaseUser; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; -import org.apache.coyote.BadRequestException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; import java.nio.file.attribute.UserPrincipalNotFoundException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; import java.util.List; @RestController @@ -41,7 +45,7 @@ public ResponseEntity getLotteryEvent(){ @PostMapping("/casperBot") public ResponseEntity postCasperBot( HttpServletRequest request, - @RequestBody @Valid CasperBotRequestDto postCasperBot) throws BadRequestException { + @RequestBody @Valid CasperBotRequestDto postCasperBot) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { BaseUser user = (BaseUser) request.getAttribute("user"); return ResponseEntity .status(HttpStatus.CREATED) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java index 2cf8c48b..28a69096 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java @@ -16,17 +16,26 @@ import JGS.CasperEvent.global.error.exception.CustomException; import JGS.CasperEvent.global.error.exception.LotteryEventNotExists; import JGS.CasperEvent.global.jwt.repository.UserRepository; -import org.springframework.beans.factory.annotation.Autowired; +import JGS.CasperEvent.global.util.AESUtils; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; import java.nio.file.attribute.UserPrincipalNotFoundException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; +import java.util.Optional; @Service @Transactional +@RequiredArgsConstructor public class LotteryEventService { private final UserRepository userRepository; @@ -34,21 +43,10 @@ public class LotteryEventService { private final LotteryParticipantsRepository lotteryParticipantsRepository; private final CasperBotRepository casperBotRepository; private final RedisService redisService; + private final SecretKey secretKey; - @Autowired - public LotteryEventService(LotteryEventRepository lotteryEventRepository, - LotteryParticipantsRepository lotteryParticipantsRepository, - CasperBotRepository casperBotRepository, - RedisService redisService, UserRepository userRepository) { - this.lotteryEventRepository = lotteryEventRepository; - this.lotteryParticipantsRepository = lotteryParticipantsRepository; - this.casperBotRepository = casperBotRepository; - this.redisService = redisService; - this.userRepository = userRepository; - } - - public CasperBotResponseDto postCasperBot(BaseUser user, CasperBotRequestDto casperBotRequestDto) throws CustomException { - LotteryParticipants participants = registerUserIfNeed(user); + public CasperBotResponseDto postCasperBot(BaseUser user, CasperBotRequestDto casperBotRequestDto) throws CustomException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { + LotteryParticipants participants = registerUserIfNeed(user, casperBotRequestDto); LotteryEvent lotteryEvent = lotteryEventRepository.findById(1L).orElseThrow(LotteryEventNotExists::new); CasperBot casperBot = casperBotRepository.save(new CasperBot(casperBotRequestDto, user.getId())); @@ -80,7 +78,7 @@ public CasperBotResponseDto getCasperBot(Long casperId) { } - public LotteryParticipants registerUserIfNeed(BaseUser user) { + public LotteryParticipants registerUserIfNeed(BaseUser user, CasperBotRequestDto casperBotRequestDto) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { LotteryParticipants participant = lotteryParticipantsRepository.findByBaseUser(user).orElse(null); if (participant == null) { @@ -88,6 +86,15 @@ public LotteryParticipants registerUserIfNeed(BaseUser user) { lotteryParticipantsRepository.save(participant); } + if (!casperBotRequestDto.getReferralId().isEmpty()) { + String referralId = AESUtils.decrypt(casperBotRequestDto.getReferralId(), secretKey); + Optional referralParticipant = + lotteryParticipantsRepository.findByBaseUser( + userRepository.findById(referralId).orElse(null) + ); + referralParticipant.ifPresent(LotteryParticipants::linkClickedCountAdded); + } + user.updateLotteryParticipants(participant); userRepository.save(user); From 71d29a306a7f3876e04a0a68dd2c8da3065a87f6 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 11:23:55 +0900 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=EB=B2=A0=EC=9D=B4=EC=8A=A4=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/eventService/LotteryEventService.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java index 28a69096..43313cd7 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java @@ -101,12 +101,9 @@ public LotteryParticipants registerUserIfNeed(BaseUser user, CasperBotRequestDto return participant; } - // TODO: 가짜 API, DB 접속되도록 수정 public LotteryEventResponseDto getLotteryEvent() { - return new LotteryEventResponseDto(LocalDateTime.now(), - LocalDate.of(2000, 9, 27).atStartOfDay(), - LocalDate.of(2100, 9, 27).atStartOfDay(), - ChronoUnit.DAYS.between(LocalDate.of(2000, 9, 27), LocalDate.of(2100, 9, 27))); + LotteryEvent lotteryEvent = lotteryEventRepository.findById(1L).orElseThrow(LotteryEventNotExists::new); + return LotteryEventResponseDto.of(lotteryEvent, LocalDateTime.now()); } } From 2dd3a5177b605d48390a2a59fd423bbaffce86ee Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 11:28:21 +0900 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EB=82=A0?= =?UTF-8?q?=EC=A7=9C=EC=99=80=20=EC=8B=9C=EA=B0=84=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventDetailResponseDto.java | 17 ++++++++++++----- .../eventService/LotteryEventService.java | 2 -- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventDetailResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventDetailResponseDto.java index ba6d9f7d..855317c6 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventDetailResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventDetailResponseDto.java @@ -2,20 +2,27 @@ import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -public record LotteryEventDetailResponseDto(LocalDateTime startDateTime, LocalDateTime endDateTime, - AtomicInteger appliedCount, int winnerCount, - LocalDateTime createdAt, LocalDateTime updatedAt) { +public record LotteryEventDetailResponseDto( + LocalDate startDate, LocalTime startTime, + LocalDate endDate, LocalTime endTime, + AtomicInteger appliedCount, int winnerCount, + LocalDateTime createdAt, LocalDateTime updatedAt) { + public static ArrayList of(List lotteryEvent) { ArrayList lotteryEventDtoList = new ArrayList<>(); for (LotteryEvent event : lotteryEvent) { lotteryEventDtoList.add(new LotteryEventDetailResponseDto( - event.getStartDateTime(), - event.getEndDateTime(), + event.getStartDateTime().toLocalDate(), + event.getStartDateTime().toLocalTime(), + event.getEndDateTime().toLocalDate(), + event.getEndDateTime().toLocalTime(), event.getAppliedCount(), event.getWinnerCount(), event.getCreatedAt(), diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java index 43313cd7..ddd1a32c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java @@ -28,9 +28,7 @@ import java.nio.file.attribute.UserPrincipalNotFoundException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; -import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; import java.util.Optional; @Service