From 838ab36889f5fda5f8eedd890ca84ee2de8a7fd8 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 9 Aug 2024 11:13:07 +0900 Subject: [PATCH 001/289] =?UTF-8?q?fix:=20GeneratedValue=20strategy=20Iden?= =?UTF-8?q?tity=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java b/Server/src/main/java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java index 0545a31d..ce4e9fb8 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java @@ -1,13 +1,15 @@ package JGS.CasperEvent.domain.url.entity; import JGS.CasperEvent.global.entity.BaseEntity; +import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +@Entity public class OriginalUrl extends BaseEntity { @Id - @GeneratedValue(strategy = GenerationType.UUID) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String originalUrl; From 0396f2562c1a029e4ff1fa4ecefe03e5a7e65f0b Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 9 Aug 2024 11:13:21 +0900 Subject: [PATCH 002/289] =?UTF-8?q?chore:=20ShortenUrlResponseDto=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java new file mode 100644 index 00000000..df441221 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java @@ -0,0 +1,4 @@ +package JGS.CasperEvent.domain.url.dto; + +public record ShortenUrlResponseDto(String shortenUrl) { +} From 52cfd8c51bbabaeca0045a483151334a09475012 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 9 Aug 2024 11:13:34 +0900 Subject: [PATCH 003/289] =?UTF-8?q?chore:=20UrlRepository=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/domain/url/repository/UrlRepository.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java index 202cfb59..9052e753 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java @@ -1,4 +1,9 @@ package JGS.CasperEvent.domain.url.repository; -public interface UrlRepository { +import JGS.CasperEvent.domain.url.entity.OriginalUrl; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface UrlRepository extends JpaRepository { } From 9a8cd33c6987e63b0a2379c4675cdf866435e47c Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 9 Aug 2024 11:14:18 +0900 Subject: [PATCH 004/289] =?UTF-8?q?chore:=20UrlController=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/url/controller/UrlController.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java b/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java index cc8a266c..b2999c0f 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java @@ -1,4 +1,31 @@ package JGS.CasperEvent.domain.url.controller; +import JGS.CasperEvent.domain.url.dto.ShortenUrlResponseDto; +import JGS.CasperEvent.domain.url.service.UrlService; +import JGS.CasperEvent.global.entity.BaseUser; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("link") public class UrlController { + + private final UrlService urlService; + + @Autowired + public UrlController(UrlService urlService) { + this.urlService = urlService; + } + + @PostMapping + public ResponseEntity generateShortUrl(HttpServletRequest request) { + BaseUser user = (BaseUser) request.getAttribute("user"); + return ResponseEntity.status(HttpStatus.CREATED) + .body(urlService.generateShortUrl(user)); + } } From b63919ee31dcdcf8c9e72c51bc9d748726526187 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 9 Aug 2024 11:14:34 +0900 Subject: [PATCH 005/289] =?UTF-8?q?chore:=20UrlService=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/url/service/UrlService.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java index df6b852f..15c1d272 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java @@ -1,4 +1,26 @@ package JGS.CasperEvent.domain.url.service; +import JGS.CasperEvent.domain.url.dto.ShortenUrlResponseDto; +import JGS.CasperEvent.domain.url.repository.UrlRepository; +import JGS.CasperEvent.global.entity.BaseUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service public class UrlService { + + private final UrlRepository urlRepository; + + @Autowired + public UrlService(UrlRepository urlRepository) { + this.urlRepository = urlRepository; + } + + public ShortenUrlResponseDto generateShortUrl(BaseUser user){ + String id = user.getId(); + + System.out.println("id = " + id); + + return new ShortenUrlResponseDto("shortenLink"); + } } From f81d267dac3c6644776312c7cee3884ab308da08 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 9 Aug 2024 11:15:56 +0900 Subject: [PATCH 006/289] =?UTF-8?q?chore:=20=EC=95=94=EB=B3=B5=ED=98=B8?= =?UTF-8?q?=ED=99=94=EC=9A=A9=20AESUtils=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/JGS/CasperEvent/global/util/AESUtils.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java b/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java new file mode 100644 index 00000000..19dbe358 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java @@ -0,0 +1,4 @@ +package JGS.CasperEvent.global.util; + +public class AESUtils { +} From d795e1cdcdb2533e31914b7fe05ae88aa9ce9ba4 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:06:36 +0900 Subject: [PATCH 007/289] =?UTF-8?q?chore:=20URL=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/url/entity/{OriginalUrl.java => Url.java} | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) rename Server/src/main/java/JGS/CasperEvent/domain/url/entity/{OriginalUrl.java => Url.java} (67%) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java b/Server/src/main/java/JGS/CasperEvent/domain/url/entity/Url.java similarity index 67% rename from Server/src/main/java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java rename to Server/src/main/java/JGS/CasperEvent/domain/url/entity/Url.java index ce4e9fb8..59b5514c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/entity/Url.java @@ -5,12 +5,22 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import lombok.Getter; @Entity -public class OriginalUrl extends BaseEntity { +@Getter +public class Url extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String originalUrl; + + public Url(String originalUrl){ + this.originalUrl = originalUrl; + } + + public Url() { + + } } From b47093e46b38d23a0784e390eb1816ed0cd00c4a Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:07:30 +0900 Subject: [PATCH 008/289] =?UTF-8?q?chore:=20=EC=95=94=EB=B3=B5=ED=98=B8?= =?UTF-8?q?=ED=99=94=20=ED=82=A4=20=EC=99=B8=EB=B6=80=20=EC=A3=BC=EC=9E=85?= =?UTF-8?q?=20=EC=9C=84=ED=95=9C=20SecurityConfig=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/config/SecurityConfig.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/config/SecurityConfig.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/config/SecurityConfig.java b/Server/src/main/java/JGS/CasperEvent/global/config/SecurityConfig.java new file mode 100644 index 00000000..90dbf9ad --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/config/SecurityConfig.java @@ -0,0 +1,20 @@ +package JGS.CasperEvent.global.config; + +import JGS.CasperEvent.global.util.AESUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.crypto.SecretKey; + +@Configuration +public class SecurityConfig { + + @Value("${spring.encryption.key}") + private String encryptionKey; + + @Bean + public SecretKey secretKey() { + return AESUtils.stringToKey(encryptionKey); + } +} From 545fedca08d26bae07e936e01f5b688a15a4e89f Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:08:04 +0900 Subject: [PATCH 009/289] =?UTF-8?q?feat:=20AES128=20=EC=95=94=EB=B3=B5?= =?UTF-8?q?=ED=98=B8=ED=99=94=20=EC=9C=84=ED=95=9C=20AESUtils=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/global/util/AESUtils.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java b/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java index 19dbe358..1fc26b96 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java +++ b/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java @@ -1,4 +1,31 @@ package JGS.CasperEvent.global.util; +import javax.crypto.*; +import javax.crypto.spec.SecretKeySpec; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.Base64; + public class AESUtils { + + public static SecretKey stringToKey(String keyString) { + byte[] decodedKey = keyString.getBytes(); + return new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES"); + } + + public static String encrypt(String plainText, SecretKey key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { + Cipher cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.ENCRYPT_MODE, key); + byte[] encryptedBytes = cipher.doFinal(plainText.getBytes()); + return Base64.getEncoder().encodeToString(encryptedBytes); + } + + public static String decrypt(String encryptedText, SecretKey key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { + Cipher cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.DECRYPT_MODE, key); + byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(encryptedText)); + return new String(decryptedBytes); + } + + } From e319f3269a6cb704200e5ff32d891f3464964aff Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:08:27 +0900 Subject: [PATCH 010/289] =?UTF-8?q?chore:=20GlobalExceptionHandler=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=ED=95=B8=EB=93=A4=EB=A7=81=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/global/error/GlobalExceptionHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java index 692154a2..de569e89 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java +++ b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java @@ -19,8 +19,8 @@ public class GlobalExceptionHandler { @ExceptionHandler(CustomException.class) public ResponseEntity handler(CustomException e){ return ResponseEntity - .status(HttpStatus.BAD_REQUEST) - .body(ErrorResponse.of(CustomErrorCode.BAD_REQUEST, e.getMessage())); + .status(HttpStatus.valueOf(e.getErrorCode().getStatus())) + .body(ErrorResponse.of(e.getErrorCode(), e.getMessage())); } @ExceptionHandler(MissingRequestCookieException.class) From 3949cf5599735a8ee5c23289913840592fd660ed Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:08:57 +0900 Subject: [PATCH 011/289] =?UTF-8?q?test:=20=EB=8B=A8=EC=B6=95=20URL=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20API=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/entity/participants/LotteryParticipants.java | 2 +- .../CasperEvent/domain/url/controller/UrlController.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java index 387084a1..39037862 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java @@ -12,7 +12,7 @@ public class LotteryParticipants { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToOne + @OneToOne // mappedBy 이용하면 둘 다 저장 안해도 됨 @JoinColumn(name = "base_user_id") //todo: 왜이런지 알아보기 @JsonBackReference diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java b/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java index b2999c0f..751e3895 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java @@ -11,6 +11,12 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + @RestController @RequestMapping("link") public class UrlController { @@ -23,7 +29,7 @@ public UrlController(UrlService urlService) { } @PostMapping - public ResponseEntity generateShortUrl(HttpServletRequest request) { + public ResponseEntity generateShortUrl(HttpServletRequest request) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { BaseUser user = (BaseUser) request.getAttribute("user"); return ResponseEntity.status(HttpStatus.CREATED) .body(urlService.generateShortUrl(user)); From 4e224446bcb751e70f95d99308706806332a1416 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:09:21 +0900 Subject: [PATCH 012/289] =?UTF-8?q?test:=20BASE62=20=EC=9D=B8=EC=BD=94?= =?UTF-8?q?=EB=94=A9,=20=EB=94=94=EC=BD=94=EB=94=A9=20=EC=9C=84=ED=95=9C?= =?UTF-8?q?=20Base62Utils=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/global/util/Base62Utils.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java b/Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java new file mode 100644 index 00000000..bd63e1d3 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java @@ -0,0 +1,25 @@ +package JGS.CasperEvent.global.util; + +public class Base62Utils { + private static final String BASE62_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + + public static String encode(long number) { + if (number == 0) return Character.toString(BASE62_CHARS.charAt(0)); + + StringBuilder sb = new StringBuilder(); + while (number > 0) { + int reminder = (int) (number % 62); + sb.append(BASE62_CHARS.charAt(reminder)); + number /= 62; + } + return sb.reverse().toString(); + } + + public static long decode(String str){ + long result = 0; + for (int i = 0; i < str.length(); i++) { + result = result * 62 + BASE62_CHARS.indexOf(str.charAt(i)); + } + return result; + } +} From 0bcdfb5a9551186b73707856e9c497d0e9ffe133 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:09:51 +0900 Subject: [PATCH 013/289] =?UTF-8?q?test:=20=EB=8B=A8=EC=B6=95=20URL=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/url/repository/UrlRepository.java | 7 ++-- .../domain/url/service/UrlService.java | 36 ++++++++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java index 9052e753..f7d8649b 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java @@ -1,9 +1,12 @@ package JGS.CasperEvent.domain.url.repository; -import JGS.CasperEvent.domain.url.entity.OriginalUrl; +import JGS.CasperEvent.domain.url.entity.Url; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.Optional; + @Repository -public interface UrlRepository extends JpaRepository { +public interface UrlRepository extends JpaRepository { + Optional findByOriginalUrl(String originalUrl); } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java index 15c1d272..4cb5ba2a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java @@ -1,26 +1,52 @@ package JGS.CasperEvent.domain.url.service; import JGS.CasperEvent.domain.url.dto.ShortenUrlResponseDto; +import JGS.CasperEvent.domain.url.entity.Url; import JGS.CasperEvent.domain.url.repository.UrlRepository; import JGS.CasperEvent.global.entity.BaseUser; +import JGS.CasperEvent.global.util.AESUtils; +import JGS.CasperEvent.global.util.Base62Utils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + @Service public class UrlService { + @Value("${client.url}") + private String clientUrl; + + @Value("${shortenUrlService.url}") + private String shortenBaseUrl; + private final UrlRepository urlRepository; + private final SecretKey secretKey; @Autowired - public UrlService(UrlRepository urlRepository) { + public UrlService(UrlRepository urlRepository, SecretKey secretKey) { this.urlRepository = urlRepository; + this.secretKey = secretKey; } - public ShortenUrlResponseDto generateShortUrl(BaseUser user){ - String id = user.getId(); + public ShortenUrlResponseDto generateShortUrl(BaseUser user) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { + String encryptedUserId = AESUtils.encrypt(user.getId(), secretKey); + String originalUrl = clientUrl + "?" + "referralId=" + encryptedUserId; - System.out.println("id = " + id); + Url url = urlRepository.findByOriginalUrl(originalUrl).orElseGet( + () -> urlRepository.save(new Url(originalUrl)) + ); - return new ShortenUrlResponseDto("shortenLink"); + Long urlId = url.getId(); + String shortenUrl = shortenBaseUrl + "/link/" + Base62Utils.encode(urlId); + + return new ShortenUrlResponseDto(shortenUrl); } + } From 14ecc6c5dfe9d460920d3d3688230fef6d0de641 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:13:24 +0900 Subject: [PATCH 014/289] =?UTF-8?q?chore:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EB=B0=8F=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/global/util/GsonUtil.java | 80 ------------------- .../JGS/CasperEvent/global/util/UserUtil.java | 11 --- 2 files changed, 91 deletions(-) delete mode 100644 Server/src/main/java/JGS/CasperEvent/global/util/GsonUtil.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/GsonUtil.java b/Server/src/main/java/JGS/CasperEvent/global/util/GsonUtil.java deleted file mode 100644 index 7f6024f5..00000000 --- a/Server/src/main/java/JGS/CasperEvent/global/util/GsonUtil.java +++ /dev/null @@ -1,80 +0,0 @@ -package JGS.CasperEvent.global.util; - -import com.google.gson.*; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; - -public class GsonUtil { - private static final String PATTERN_DATE = "yyyy-MM-dd"; - private static final String PATTERN_TIME = "HH:mm:ss"; - private static final String PATTERN_DATETIME = String.format("%s %s", PATTERN_DATE, PATTERN_TIME); - - static class LocalDataTimeAdapter extends TypeAdapter { - DateTimeFormatter format = DateTimeFormatter.ofPattern(PATTERN_DATETIME); - - @Override - public void write(JsonWriter out, LocalDateTime value) throws IOException { - if (value != null) out.value(value.format(format)); - } - - @Override - public LocalDateTime read(JsonReader in) throws IOException { - return LocalDateTime.parse(in.nextString(), format); - } - } - - static class LocalDateAdapter extends TypeAdapter { - DateTimeFormatter format = DateTimeFormatter.ofPattern(PATTERN_DATE); - - @Override - public void write(JsonWriter out, LocalDate value) throws IOException { - out.value(value.format(format)); - } - - @Override - public LocalDate read(JsonReader in) throws IOException { - return LocalDate.parse(in.nextString(), format); - } - } - - static class LocalTimeAdapter extends TypeAdapter { - DateTimeFormatter format = DateTimeFormatter.ofPattern(PATTERN_TIME); - - @Override - public void write(JsonWriter out, LocalTime value) throws IOException { - out.value(value.format(format)); - } - - @Override - public LocalTime read(JsonReader in) throws IOException { - return LocalTime.parse(in.nextString(), format); - } - } - - static class EnumSerializer implements JsonSerializer>{ - @Override - public JsonElement serialize(Enum src, Type typeOfSrc, JsonSerializationContext context) { - return new JsonPrimitive(src.name()); - } - } - - private static final Gson gson = new GsonBuilder() - .disableHtmlEscaping() - .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) - .setDateFormat(PATTERN_DATETIME) - .registerTypeAdapter(LocalDateTime.class, new LocalDataTimeAdapter().nullSafe()) - .registerTypeAdapter(LocalDate.class, new LocalDateAdapter().nullSafe()) - .registerTypeAdapter(LocalTime.class, new LocalTimeAdapter().nullSafe()) - .create(); - - public static Gson getGson(){ - return gson; - } -} diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java b/Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java index 711708d1..a3ffb0cb 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java +++ b/Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java @@ -5,17 +5,6 @@ public class UserUtil { //TODO: 스프링 서버 뻗으면 캐스퍼 아이디 0부터 다시 시작함 private static final AtomicLong counter = new AtomicLong(0); - - //TODO: 현재는 그냥 userData 즉시 반환, 키 이용한 복호화로 수정하기 - public static String getDecodedPhoneNumber(String userData) { - return userData; - } - - //TODO: 현재는 true 리턴, jwt로 변경 필요 - public static Boolean isValidAdminToken(String token){ - if (token.equals("adminToken")) return true; - return false; - } public static long generateId(){ return counter.incrementAndGet(); } From 58102198b645019e4dafa6e012ed84d2714592b6 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:28:49 +0900 Subject: [PATCH 015/289] =?UTF-8?q?chore:=20=EB=8B=A8=EC=B6=95=20url=20?= =?UTF-8?q?=EC=A3=BC=EC=86=8C=20=ED=99=94=EC=9D=B4=ED=8A=B8=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=97=90=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java index cb83d2d8..60c276ba 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java @@ -32,7 +32,7 @@ public class JwtAuthorizationFilter implements Filter { "/event/rush", "/event/lottery/caspers", "/admin/join", "/admin/auth", "/h2", "/h2/*", "/swagger-ui/*", "/v3/api-docs", "/v3/api-docs/*", - "/event/lottery" + "/event/lottery", "/link/*" }; private final String[] blackListUris = new String[]{ "/event/rush/*", "/event/lottery/casperBot" From b3fc45b994cceed30a5e2c116b50be1ff7ff8af5 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:29:21 +0900 Subject: [PATCH 016/289] =?UTF-8?q?feat:=20=EB=8B=A8=EC=B6=95=20url=20?= =?UTF-8?q?=EC=A0=91=EC=86=8D=20api=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/url/controller/UrlController.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java b/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java index 751e3895..3503e936 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java @@ -7,9 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; @@ -31,7 +29,16 @@ public UrlController(UrlService urlService) { @PostMapping public ResponseEntity generateShortUrl(HttpServletRequest request) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { BaseUser user = (BaseUser) request.getAttribute("user"); - return ResponseEntity.status(HttpStatus.CREATED) + return ResponseEntity + .status(HttpStatus.CREATED) .body(urlService.generateShortUrl(user)); } + + @GetMapping("/{encodedId}") + public ResponseEntity redirectOriginalUrl(@PathVariable String encodedId){ + return ResponseEntity + .status(HttpStatus.FOUND) + .header("Location", urlService.getOriginalUrl(encodedId)) + .build(); + } } From c989ae3aed1d181912757fff718c75efa5e7ecc8 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:29:32 +0900 Subject: [PATCH 017/289] =?UTF-8?q?feat:=20=EB=8B=A8=EC=B6=95=20url=20?= =?UTF-8?q?=EC=A0=91=EC=86=8D=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/domain/url/service/UrlService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java index 4cb5ba2a..3503fdef 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java @@ -16,6 +16,7 @@ import javax.crypto.SecretKey; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; +import java.util.NoSuchElementException; @Service public class UrlService { @@ -49,4 +50,10 @@ public ShortenUrlResponseDto generateShortUrl(BaseUser user) throws NoSuchPaddin return new ShortenUrlResponseDto(shortenUrl); } + public String getOriginalUrl(String encodedId){ + Long urlId = Base62Utils.decode(encodedId); + Url url = urlRepository.findById(urlId).orElseThrow(NoSuchElementException::new); + return url.getOriginalUrl(); + } + } From 2d5d4f0d159bac1b0547c46c735289ce43114eca Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 15:30:27 +0900 Subject: [PATCH 018/289] =?UTF-8?q?chore:=20=EB=B0=B0=ED=8F=AC=EC=9A=A9=20?= =?UTF-8?q?=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=B6=94=EA=B0=80=20-?= =?UTF-8?q?=20client.url=20->=20=ED=81=B4=EB=9D=BC=EC=9D=B4=EC=96=B8?= =?UTF-8?q?=ED=8A=B8=20=EB=B0=B0=ED=8F=AC=20url=20-=20client.localUrl=20->?= =?UTF-8?q?=20=ED=81=B4=EB=9D=BC=EC=9D=B4=EC=96=B8=ED=8A=B8=20=EB=A1=9C?= =?UTF-8?q?=EC=BB=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9=20url=20-=20sh?= =?UTF-8?q?ortenUrlService.url=20->=20=EC=8A=A4=ED=94=84=EB=A7=81=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/src/main/resources/application-prod.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Server/src/main/resources/application-prod.yml b/Server/src/main/resources/application-prod.yml index 658d7e19..65bd582a 100644 --- a/Server/src/main/resources/application-prod.yml +++ b/Server/src/main/resources/application-prod.yml @@ -18,4 +18,12 @@ spring: data: redis: host: ${SPRING_REDIS_HOST} - port: ${SPRING_REDIS_PORT} \ No newline at end of file + port: ${SPRING_REDIS_PORT} + encryption: + key: ${AES_128_ENCRYPTION_KEY} + +client: + url: ${CLIENT_URL} + localUrl: ${LOCAL_CLIENT_URL} +shortenUrlService: + url: ${SPRING_SERVER_URL} \ No newline at end of file From 0457d85b726c399eae1dbeba50daeda141cf611d Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 15:30:52 +0900 Subject: [PATCH 019/289] =?UTF-8?q?chore:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=EC=97=94=EB=93=9C=20=EB=A1=9C=EC=BB=AC=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=9A=A9=20shortenLocalUrl=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 --- .../JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java index df441221..84f2ff92 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java @@ -1,4 +1,4 @@ package JGS.CasperEvent.domain.url.dto; -public record ShortenUrlResponseDto(String shortenUrl) { +public record ShortenUrlResponseDto(String shortenUrl, String shortenLocalUrl) { } From 189fa19d30056acf3cffb56bdb64f6eaafde481f Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 15:41:05 +0900 Subject: [PATCH 020/289] =?UTF-8?q?chore:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=EC=97=94=EB=93=9C=20=EB=A1=9C=EC=BB=AC=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=9A=A9=20shortenLocalUrl=EB=8F=84=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/domain/url/service/UrlService.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java index 3503fdef..dcb53cfa 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java @@ -23,10 +23,13 @@ public class UrlService { @Value("${client.url}") private String clientUrl; + @Value("${client.localUrl}") + private String localClientUrl; @Value("${shortenUrlService.url}") private String shortenBaseUrl; + private final UrlRepository urlRepository; private final SecretKey secretKey; @@ -36,18 +39,27 @@ public UrlService(UrlRepository urlRepository, SecretKey secretKey) { this.secretKey = secretKey; } + //todo: 테스트 끝나면 수정필요 public ShortenUrlResponseDto generateShortUrl(BaseUser user) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { String encryptedUserId = AESUtils.encrypt(user.getId(), secretKey); + String originalUrl = clientUrl + "?" + "referralId=" + encryptedUserId; + String originalLocalUrl = localClientUrl + "?" + "referralId=" + encryptedUserId; Url url = urlRepository.findByOriginalUrl(originalUrl).orElseGet( () -> urlRepository.save(new Url(originalUrl)) ); + Url localUrl = urlRepository.findByOriginalUrl(originalLocalUrl).orElseGet( + () -> urlRepository.save(new Url(originalLocalUrl)) + ); Long urlId = url.getId(); + Long localUrlId = localUrl.getId(); + String shortenUrl = shortenBaseUrl + "/link/" + Base62Utils.encode(urlId); + String shortenLocalUrl = shortenBaseUrl + "/link/" + Base62Utils.encode(localUrlId); - return new ShortenUrlResponseDto(shortenUrl); + return new ShortenUrlResponseDto(shortenUrl, shortenLocalUrl); } public String getOriginalUrl(String encodedId){ From 99c71fc233c8b8f52dbf8c3e451b2da53f012a28 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 9 Aug 2024 11:13:07 +0900 Subject: [PATCH 021/289] =?UTF-8?q?fix:=20GeneratedValue=20strategy=20Iden?= =?UTF-8?q?tity=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java b/Server/src/main/java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java index 0545a31d..ce4e9fb8 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java @@ -1,13 +1,15 @@ package JGS.CasperEvent.domain.url.entity; import JGS.CasperEvent.global.entity.BaseEntity; +import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +@Entity public class OriginalUrl extends BaseEntity { @Id - @GeneratedValue(strategy = GenerationType.UUID) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String originalUrl; From f5bc3c1497d67346ef4c66d2512d8befffcf9f7a Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 9 Aug 2024 11:13:21 +0900 Subject: [PATCH 022/289] =?UTF-8?q?chore:=20ShortenUrlResponseDto=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java new file mode 100644 index 00000000..df441221 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java @@ -0,0 +1,4 @@ +package JGS.CasperEvent.domain.url.dto; + +public record ShortenUrlResponseDto(String shortenUrl) { +} From e12ce96baf4b92824bf86b435464d9eaa9d71cdb Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 9 Aug 2024 11:13:34 +0900 Subject: [PATCH 023/289] =?UTF-8?q?chore:=20UrlRepository=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/domain/url/repository/UrlRepository.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java index 202cfb59..9052e753 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java @@ -1,4 +1,9 @@ package JGS.CasperEvent.domain.url.repository; -public interface UrlRepository { +import JGS.CasperEvent.domain.url.entity.OriginalUrl; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface UrlRepository extends JpaRepository { } From 747c8f0d73be77da8fea970d69b908196aef4468 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 9 Aug 2024 11:14:18 +0900 Subject: [PATCH 024/289] =?UTF-8?q?chore:=20UrlController=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/url/controller/UrlController.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java b/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java index cc8a266c..b2999c0f 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java @@ -1,4 +1,31 @@ package JGS.CasperEvent.domain.url.controller; +import JGS.CasperEvent.domain.url.dto.ShortenUrlResponseDto; +import JGS.CasperEvent.domain.url.service.UrlService; +import JGS.CasperEvent.global.entity.BaseUser; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("link") public class UrlController { + + private final UrlService urlService; + + @Autowired + public UrlController(UrlService urlService) { + this.urlService = urlService; + } + + @PostMapping + public ResponseEntity generateShortUrl(HttpServletRequest request) { + BaseUser user = (BaseUser) request.getAttribute("user"); + return ResponseEntity.status(HttpStatus.CREATED) + .body(urlService.generateShortUrl(user)); + } } From 65175afb3424adcee4d022822ccda9ba03d92888 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 9 Aug 2024 11:14:34 +0900 Subject: [PATCH 025/289] =?UTF-8?q?chore:=20UrlService=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/url/service/UrlService.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java index df6b852f..15c1d272 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java @@ -1,4 +1,26 @@ package JGS.CasperEvent.domain.url.service; +import JGS.CasperEvent.domain.url.dto.ShortenUrlResponseDto; +import JGS.CasperEvent.domain.url.repository.UrlRepository; +import JGS.CasperEvent.global.entity.BaseUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service public class UrlService { + + private final UrlRepository urlRepository; + + @Autowired + public UrlService(UrlRepository urlRepository) { + this.urlRepository = urlRepository; + } + + public ShortenUrlResponseDto generateShortUrl(BaseUser user){ + String id = user.getId(); + + System.out.println("id = " + id); + + return new ShortenUrlResponseDto("shortenLink"); + } } From 30406c6d6ac981a4210480aa21ad0a537e3bf2ac Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 9 Aug 2024 11:15:56 +0900 Subject: [PATCH 026/289] =?UTF-8?q?chore:=20=EC=95=94=EB=B3=B5=ED=98=B8?= =?UTF-8?q?=ED=99=94=EC=9A=A9=20AESUtils=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/JGS/CasperEvent/global/util/AESUtils.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java b/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java new file mode 100644 index 00000000..19dbe358 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java @@ -0,0 +1,4 @@ +package JGS.CasperEvent.global.util; + +public class AESUtils { +} From 8bcab68bb415c8bd210a0d4d8240041360b43d45 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:06:36 +0900 Subject: [PATCH 027/289] =?UTF-8?q?chore:=20URL=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/url/entity/{OriginalUrl.java => Url.java} | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) rename Server/src/main/java/JGS/CasperEvent/domain/url/entity/{OriginalUrl.java => Url.java} (67%) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java b/Server/src/main/java/JGS/CasperEvent/domain/url/entity/Url.java similarity index 67% rename from Server/src/main/java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java rename to Server/src/main/java/JGS/CasperEvent/domain/url/entity/Url.java index ce4e9fb8..59b5514c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/entity/OriginalUrl.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/entity/Url.java @@ -5,12 +5,22 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import lombok.Getter; @Entity -public class OriginalUrl extends BaseEntity { +@Getter +public class Url extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String originalUrl; + + public Url(String originalUrl){ + this.originalUrl = originalUrl; + } + + public Url() { + + } } From a42544ea3e52772ba46405cfbab3589d4ad663b9 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:07:30 +0900 Subject: [PATCH 028/289] =?UTF-8?q?chore:=20=EC=95=94=EB=B3=B5=ED=98=B8?= =?UTF-8?q?=ED=99=94=20=ED=82=A4=20=EC=99=B8=EB=B6=80=20=EC=A3=BC=EC=9E=85?= =?UTF-8?q?=20=EC=9C=84=ED=95=9C=20SecurityConfig=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/config/SecurityConfig.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/config/SecurityConfig.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/config/SecurityConfig.java b/Server/src/main/java/JGS/CasperEvent/global/config/SecurityConfig.java new file mode 100644 index 00000000..90dbf9ad --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/config/SecurityConfig.java @@ -0,0 +1,20 @@ +package JGS.CasperEvent.global.config; + +import JGS.CasperEvent.global.util.AESUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.crypto.SecretKey; + +@Configuration +public class SecurityConfig { + + @Value("${spring.encryption.key}") + private String encryptionKey; + + @Bean + public SecretKey secretKey() { + return AESUtils.stringToKey(encryptionKey); + } +} From f7941a730bd4217c8f36516a41f191e28a1c98d1 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:08:04 +0900 Subject: [PATCH 029/289] =?UTF-8?q?feat:=20AES128=20=EC=95=94=EB=B3=B5?= =?UTF-8?q?=ED=98=B8=ED=99=94=20=EC=9C=84=ED=95=9C=20AESUtils=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/global/util/AESUtils.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java b/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java index 19dbe358..1fc26b96 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java +++ b/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java @@ -1,4 +1,31 @@ package JGS.CasperEvent.global.util; +import javax.crypto.*; +import javax.crypto.spec.SecretKeySpec; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.Base64; + public class AESUtils { + + public static SecretKey stringToKey(String keyString) { + byte[] decodedKey = keyString.getBytes(); + return new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES"); + } + + public static String encrypt(String plainText, SecretKey key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { + Cipher cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.ENCRYPT_MODE, key); + byte[] encryptedBytes = cipher.doFinal(plainText.getBytes()); + return Base64.getEncoder().encodeToString(encryptedBytes); + } + + public static String decrypt(String encryptedText, SecretKey key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { + Cipher cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.DECRYPT_MODE, key); + byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(encryptedText)); + return new String(decryptedBytes); + } + + } From 399e5c3766f23d87b31ae8ab1e3b4d98e0a57a95 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:08:27 +0900 Subject: [PATCH 030/289] =?UTF-8?q?chore:=20GlobalExceptionHandler=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=ED=95=B8=EB=93=A4=EB=A7=81=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/global/error/GlobalExceptionHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java index 692154a2..de569e89 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java +++ b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java @@ -19,8 +19,8 @@ public class GlobalExceptionHandler { @ExceptionHandler(CustomException.class) public ResponseEntity handler(CustomException e){ return ResponseEntity - .status(HttpStatus.BAD_REQUEST) - .body(ErrorResponse.of(CustomErrorCode.BAD_REQUEST, e.getMessage())); + .status(HttpStatus.valueOf(e.getErrorCode().getStatus())) + .body(ErrorResponse.of(e.getErrorCode(), e.getMessage())); } @ExceptionHandler(MissingRequestCookieException.class) From c093404ada2f7ce4e5452f097f482a17da7d22d3 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:08:57 +0900 Subject: [PATCH 031/289] =?UTF-8?q?test:=20=EB=8B=A8=EC=B6=95=20URL=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20API=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/entity/participants/LotteryParticipants.java | 2 +- .../CasperEvent/domain/url/controller/UrlController.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java index 387084a1..39037862 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java @@ -12,7 +12,7 @@ public class LotteryParticipants { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToOne + @OneToOne // mappedBy 이용하면 둘 다 저장 안해도 됨 @JoinColumn(name = "base_user_id") //todo: 왜이런지 알아보기 @JsonBackReference diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java b/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java index b2999c0f..751e3895 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java @@ -11,6 +11,12 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + @RestController @RequestMapping("link") public class UrlController { @@ -23,7 +29,7 @@ public UrlController(UrlService urlService) { } @PostMapping - public ResponseEntity generateShortUrl(HttpServletRequest request) { + public ResponseEntity generateShortUrl(HttpServletRequest request) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { BaseUser user = (BaseUser) request.getAttribute("user"); return ResponseEntity.status(HttpStatus.CREATED) .body(urlService.generateShortUrl(user)); From ff934c590c6045c483e694acf26818db3fdd4045 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:09:21 +0900 Subject: [PATCH 032/289] =?UTF-8?q?test:=20BASE62=20=EC=9D=B8=EC=BD=94?= =?UTF-8?q?=EB=94=A9,=20=EB=94=94=EC=BD=94=EB=94=A9=20=EC=9C=84=ED=95=9C?= =?UTF-8?q?=20Base62Utils=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/global/util/Base62Utils.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java b/Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java new file mode 100644 index 00000000..bd63e1d3 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java @@ -0,0 +1,25 @@ +package JGS.CasperEvent.global.util; + +public class Base62Utils { + private static final String BASE62_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + + public static String encode(long number) { + if (number == 0) return Character.toString(BASE62_CHARS.charAt(0)); + + StringBuilder sb = new StringBuilder(); + while (number > 0) { + int reminder = (int) (number % 62); + sb.append(BASE62_CHARS.charAt(reminder)); + number /= 62; + } + return sb.reverse().toString(); + } + + public static long decode(String str){ + long result = 0; + for (int i = 0; i < str.length(); i++) { + result = result * 62 + BASE62_CHARS.indexOf(str.charAt(i)); + } + return result; + } +} From 228f024cda56c2c33400a6653b23dc7800cea46a Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:09:51 +0900 Subject: [PATCH 033/289] =?UTF-8?q?test:=20=EB=8B=A8=EC=B6=95=20URL=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/url/repository/UrlRepository.java | 7 ++-- .../domain/url/service/UrlService.java | 36 ++++++++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java index 9052e753..f7d8649b 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/repository/UrlRepository.java @@ -1,9 +1,12 @@ package JGS.CasperEvent.domain.url.repository; -import JGS.CasperEvent.domain.url.entity.OriginalUrl; +import JGS.CasperEvent.domain.url.entity.Url; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.Optional; + @Repository -public interface UrlRepository extends JpaRepository { +public interface UrlRepository extends JpaRepository { + Optional findByOriginalUrl(String originalUrl); } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java index 15c1d272..4cb5ba2a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java @@ -1,26 +1,52 @@ package JGS.CasperEvent.domain.url.service; import JGS.CasperEvent.domain.url.dto.ShortenUrlResponseDto; +import JGS.CasperEvent.domain.url.entity.Url; import JGS.CasperEvent.domain.url.repository.UrlRepository; import JGS.CasperEvent.global.entity.BaseUser; +import JGS.CasperEvent.global.util.AESUtils; +import JGS.CasperEvent.global.util.Base62Utils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + @Service public class UrlService { + @Value("${client.url}") + private String clientUrl; + + @Value("${shortenUrlService.url}") + private String shortenBaseUrl; + private final UrlRepository urlRepository; + private final SecretKey secretKey; @Autowired - public UrlService(UrlRepository urlRepository) { + public UrlService(UrlRepository urlRepository, SecretKey secretKey) { this.urlRepository = urlRepository; + this.secretKey = secretKey; } - public ShortenUrlResponseDto generateShortUrl(BaseUser user){ - String id = user.getId(); + public ShortenUrlResponseDto generateShortUrl(BaseUser user) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { + String encryptedUserId = AESUtils.encrypt(user.getId(), secretKey); + String originalUrl = clientUrl + "?" + "referralId=" + encryptedUserId; - System.out.println("id = " + id); + Url url = urlRepository.findByOriginalUrl(originalUrl).orElseGet( + () -> urlRepository.save(new Url(originalUrl)) + ); - return new ShortenUrlResponseDto("shortenLink"); + Long urlId = url.getId(); + String shortenUrl = shortenBaseUrl + "/link/" + Base62Utils.encode(urlId); + + return new ShortenUrlResponseDto(shortenUrl); } + } From c9666a2c1b094a891244d259f9a5427d44eddaf0 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:13:24 +0900 Subject: [PATCH 034/289] =?UTF-8?q?chore:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EB=B0=8F=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/global/util/GsonUtil.java | 80 ------------------- .../JGS/CasperEvent/global/util/UserUtil.java | 11 --- 2 files changed, 91 deletions(-) delete mode 100644 Server/src/main/java/JGS/CasperEvent/global/util/GsonUtil.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/GsonUtil.java b/Server/src/main/java/JGS/CasperEvent/global/util/GsonUtil.java deleted file mode 100644 index 7f6024f5..00000000 --- a/Server/src/main/java/JGS/CasperEvent/global/util/GsonUtil.java +++ /dev/null @@ -1,80 +0,0 @@ -package JGS.CasperEvent.global.util; - -import com.google.gson.*; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; - -public class GsonUtil { - private static final String PATTERN_DATE = "yyyy-MM-dd"; - private static final String PATTERN_TIME = "HH:mm:ss"; - private static final String PATTERN_DATETIME = String.format("%s %s", PATTERN_DATE, PATTERN_TIME); - - static class LocalDataTimeAdapter extends TypeAdapter { - DateTimeFormatter format = DateTimeFormatter.ofPattern(PATTERN_DATETIME); - - @Override - public void write(JsonWriter out, LocalDateTime value) throws IOException { - if (value != null) out.value(value.format(format)); - } - - @Override - public LocalDateTime read(JsonReader in) throws IOException { - return LocalDateTime.parse(in.nextString(), format); - } - } - - static class LocalDateAdapter extends TypeAdapter { - DateTimeFormatter format = DateTimeFormatter.ofPattern(PATTERN_DATE); - - @Override - public void write(JsonWriter out, LocalDate value) throws IOException { - out.value(value.format(format)); - } - - @Override - public LocalDate read(JsonReader in) throws IOException { - return LocalDate.parse(in.nextString(), format); - } - } - - static class LocalTimeAdapter extends TypeAdapter { - DateTimeFormatter format = DateTimeFormatter.ofPattern(PATTERN_TIME); - - @Override - public void write(JsonWriter out, LocalTime value) throws IOException { - out.value(value.format(format)); - } - - @Override - public LocalTime read(JsonReader in) throws IOException { - return LocalTime.parse(in.nextString(), format); - } - } - - static class EnumSerializer implements JsonSerializer>{ - @Override - public JsonElement serialize(Enum src, Type typeOfSrc, JsonSerializationContext context) { - return new JsonPrimitive(src.name()); - } - } - - private static final Gson gson = new GsonBuilder() - .disableHtmlEscaping() - .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) - .setDateFormat(PATTERN_DATETIME) - .registerTypeAdapter(LocalDateTime.class, new LocalDataTimeAdapter().nullSafe()) - .registerTypeAdapter(LocalDate.class, new LocalDateAdapter().nullSafe()) - .registerTypeAdapter(LocalTime.class, new LocalTimeAdapter().nullSafe()) - .create(); - - public static Gson getGson(){ - return gson; - } -} diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java b/Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java index 711708d1..a3ffb0cb 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java +++ b/Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java @@ -5,17 +5,6 @@ public class UserUtil { //TODO: 스프링 서버 뻗으면 캐스퍼 아이디 0부터 다시 시작함 private static final AtomicLong counter = new AtomicLong(0); - - //TODO: 현재는 그냥 userData 즉시 반환, 키 이용한 복호화로 수정하기 - public static String getDecodedPhoneNumber(String userData) { - return userData; - } - - //TODO: 현재는 true 리턴, jwt로 변경 필요 - public static Boolean isValidAdminToken(String token){ - if (token.equals("adminToken")) return true; - return false; - } public static long generateId(){ return counter.incrementAndGet(); } From fcf9e3104b03a71645c2dd50c42fbb8f9e05a088 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:28:49 +0900 Subject: [PATCH 035/289] =?UTF-8?q?chore:=20=EB=8B=A8=EC=B6=95=20url=20?= =?UTF-8?q?=EC=A3=BC=EC=86=8C=20=ED=99=94=EC=9D=B4=ED=8A=B8=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=97=90=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java index cb83d2d8..60c276ba 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java @@ -32,7 +32,7 @@ public class JwtAuthorizationFilter implements Filter { "/event/rush", "/event/lottery/caspers", "/admin/join", "/admin/auth", "/h2", "/h2/*", "/swagger-ui/*", "/v3/api-docs", "/v3/api-docs/*", - "/event/lottery" + "/event/lottery", "/link/*" }; private final String[] blackListUris = new String[]{ "/event/rush/*", "/event/lottery/casperBot" From 7c1dcefdbcd78ab5e6f3aea80fa9666ae64de655 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:29:21 +0900 Subject: [PATCH 036/289] =?UTF-8?q?feat:=20=EB=8B=A8=EC=B6=95=20url=20?= =?UTF-8?q?=EC=A0=91=EC=86=8D=20api=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/url/controller/UrlController.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java b/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java index 751e3895..3503e936 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/controller/UrlController.java @@ -7,9 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; @@ -31,7 +29,16 @@ public UrlController(UrlService urlService) { @PostMapping public ResponseEntity generateShortUrl(HttpServletRequest request) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { BaseUser user = (BaseUser) request.getAttribute("user"); - return ResponseEntity.status(HttpStatus.CREATED) + return ResponseEntity + .status(HttpStatus.CREATED) .body(urlService.generateShortUrl(user)); } + + @GetMapping("/{encodedId}") + public ResponseEntity redirectOriginalUrl(@PathVariable String encodedId){ + return ResponseEntity + .status(HttpStatus.FOUND) + .header("Location", urlService.getOriginalUrl(encodedId)) + .build(); + } } From 752035fc042c6b8ce56bfef82376caab3bd1342f Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 02:29:32 +0900 Subject: [PATCH 037/289] =?UTF-8?q?feat:=20=EB=8B=A8=EC=B6=95=20url=20?= =?UTF-8?q?=EC=A0=91=EC=86=8D=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/domain/url/service/UrlService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java index 4cb5ba2a..3503fdef 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java @@ -16,6 +16,7 @@ import javax.crypto.SecretKey; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; +import java.util.NoSuchElementException; @Service public class UrlService { @@ -49,4 +50,10 @@ public ShortenUrlResponseDto generateShortUrl(BaseUser user) throws NoSuchPaddin return new ShortenUrlResponseDto(shortenUrl); } + public String getOriginalUrl(String encodedId){ + Long urlId = Base62Utils.decode(encodedId); + Url url = urlRepository.findById(urlId).orElseThrow(NoSuchElementException::new); + return url.getOriginalUrl(); + } + } From e2ce3793d0f879119c008e0a7f05d9a016350872 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 15:30:27 +0900 Subject: [PATCH 038/289] =?UTF-8?q?chore:=20=EB=B0=B0=ED=8F=AC=EC=9A=A9=20?= =?UTF-8?q?=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=B6=94=EA=B0=80=20-?= =?UTF-8?q?=20client.url=20->=20=ED=81=B4=EB=9D=BC=EC=9D=B4=EC=96=B8?= =?UTF-8?q?=ED=8A=B8=20=EB=B0=B0=ED=8F=AC=20url=20-=20client.localUrl=20->?= =?UTF-8?q?=20=ED=81=B4=EB=9D=BC=EC=9D=B4=EC=96=B8=ED=8A=B8=20=EB=A1=9C?= =?UTF-8?q?=EC=BB=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9=20url=20-=20sh?= =?UTF-8?q?ortenUrlService.url=20->=20=EC=8A=A4=ED=94=84=EB=A7=81=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/src/main/resources/application-prod.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Server/src/main/resources/application-prod.yml b/Server/src/main/resources/application-prod.yml index 658d7e19..65bd582a 100644 --- a/Server/src/main/resources/application-prod.yml +++ b/Server/src/main/resources/application-prod.yml @@ -18,4 +18,12 @@ spring: data: redis: host: ${SPRING_REDIS_HOST} - port: ${SPRING_REDIS_PORT} \ No newline at end of file + port: ${SPRING_REDIS_PORT} + encryption: + key: ${AES_128_ENCRYPTION_KEY} + +client: + url: ${CLIENT_URL} + localUrl: ${LOCAL_CLIENT_URL} +shortenUrlService: + url: ${SPRING_SERVER_URL} \ No newline at end of file From 69959f604663cdc79ac08589b3b29688a1cb5e5c Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 15:30:52 +0900 Subject: [PATCH 039/289] =?UTF-8?q?chore:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=EC=97=94=EB=93=9C=20=EB=A1=9C=EC=BB=AC=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=9A=A9=20shortenLocalUrl=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 --- .../JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java index df441221..84f2ff92 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/dto/ShortenUrlResponseDto.java @@ -1,4 +1,4 @@ package JGS.CasperEvent.domain.url.dto; -public record ShortenUrlResponseDto(String shortenUrl) { +public record ShortenUrlResponseDto(String shortenUrl, String shortenLocalUrl) { } From e0716b90af366100c2d8ae724263d69e539b1d5c Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 10 Aug 2024 15:41:05 +0900 Subject: [PATCH 040/289] =?UTF-8?q?chore:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=EC=97=94=EB=93=9C=20=EB=A1=9C=EC=BB=AC=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=9A=A9=20shortenLocalUrl=EB=8F=84=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/domain/url/service/UrlService.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java index 3503fdef..dcb53cfa 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/url/service/UrlService.java @@ -23,10 +23,13 @@ public class UrlService { @Value("${client.url}") private String clientUrl; + @Value("${client.localUrl}") + private String localClientUrl; @Value("${shortenUrlService.url}") private String shortenBaseUrl; + private final UrlRepository urlRepository; private final SecretKey secretKey; @@ -36,18 +39,27 @@ public UrlService(UrlRepository urlRepository, SecretKey secretKey) { this.secretKey = secretKey; } + //todo: 테스트 끝나면 수정필요 public ShortenUrlResponseDto generateShortUrl(BaseUser user) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { String encryptedUserId = AESUtils.encrypt(user.getId(), secretKey); + String originalUrl = clientUrl + "?" + "referralId=" + encryptedUserId; + String originalLocalUrl = localClientUrl + "?" + "referralId=" + encryptedUserId; Url url = urlRepository.findByOriginalUrl(originalUrl).orElseGet( () -> urlRepository.save(new Url(originalUrl)) ); + Url localUrl = urlRepository.findByOriginalUrl(originalLocalUrl).orElseGet( + () -> urlRepository.save(new Url(originalLocalUrl)) + ); Long urlId = url.getId(); + Long localUrlId = localUrl.getId(); + String shortenUrl = shortenBaseUrl + "/link/" + Base62Utils.encode(urlId); + String shortenLocalUrl = shortenBaseUrl + "/link/" + Base62Utils.encode(localUrlId); - return new ShortenUrlResponseDto(shortenUrl); + return new ShortenUrlResponseDto(shortenUrl, shortenLocalUrl); } public String getOriginalUrl(String encodedId){ From 79f18724eb1e4df5a22ebfce7ac71a954855e635 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 13:46:32 +0900 Subject: [PATCH 041/289] =?UTF-8?q?chore:=20=EC=96=B4=EB=93=9C=EB=AF=BC=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EC=8B=9D=EB=B3=84=EC=9E=90=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/global/jwt/filter/VerifyAdminFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/VerifyAdminFilter.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/VerifyAdminFilter.java index f189a8d0..19d97a11 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/VerifyAdminFilter.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/VerifyAdminFilter.java @@ -16,7 +16,7 @@ @Slf4j @RequiredArgsConstructor public class VerifyAdminFilter implements Filter { - public static final String AUTHENTICATE_ADMIN = "authenticateAdmin"; + public static final String AUTHENTICATE_ADMIN = "authenticateUser"; private final ObjectMapper objectMapper; private final AdminService adminService; From c32fff184a41c73c95f9889da6e6089dc6370a32 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 13:47:08 +0900 Subject: [PATCH 042/289] =?UTF-8?q?chore:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?LocalDate=20->=20LocalDateTime=EC=9C=BC=EB=A1=9C=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ResponseDto/LotteryEventResponseDto.java | 6 ++--- .../dto/ResponseDto/RushEventResponseDto.java | 4 ++-- .../domain/event/entity/event/BaseEvent.java | 22 ++++++------------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java index 6ca3df36..23e2e591 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java @@ -2,13 +2,13 @@ import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; -import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; -public record LotteryEventResponseDto(LocalDateTime serverDateTime, LocalDate eventStartDate, LocalDate eventEndDate, +public record LotteryEventResponseDto(LocalDateTime serverDateTime, LocalDateTime eventStartDate, + LocalDateTime eventEndDate, long activePeriod) { - public static LotteryEventResponseDto of(LocalDateTime serverDateTime, LotteryEvent lotteryEvent) { + public static LotteryEventResponseDto of(LotteryEvent lotteryEvent, LocalDateTime serverDateTime) { return new LotteryEventResponseDto( serverDateTime, lotteryEvent.getEventStartDate(), diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java index f6c9558d..359896c0 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java @@ -3,9 +3,9 @@ import JGS.CasperEvent.domain.event.entity.event.RushEvent; import JGS.CasperEvent.domain.event.entity.event.RushOption; -import java.time.LocalDate; +import java.time.LocalDateTime; -public record RushEventResponseDto(Long rushEventId, LocalDate startDate, LocalDate endDate, +public record RushEventResponseDto(Long rushEventId, LocalDateTime startDate, LocalDateTime endDate, int winnerCount, String prizeImageUrl, String prizeDescription, RushOption leftOption, RushOption rightOption){ diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java index c16fe270..305c1efe 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java @@ -1,23 +1,15 @@ package JGS.CasperEvent.domain.event.entity.event; import JGS.CasperEvent.global.entity.BaseEntity; +import jakarta.persistence.MappedSuperclass; +import lombok.Getter; -import java.time.LocalDate; +import java.time.LocalDateTime; +@MappedSuperclass +@Getter public class BaseEvent extends BaseEntity { - protected LocalDate eventStartDate; - protected LocalDate eventEndDate; + protected LocalDateTime eventStartDate; + protected LocalDateTime eventEndDate; protected int winnerCount; - - public LocalDate getEventStartDate() { - return eventStartDate; - } - - public LocalDate getEventEndDate() { - return eventEndDate; - } - - public int getWinnerCount() { - return winnerCount; - } } From ffe0d4e6b5275963dcba52fc00194c5764fbccd8 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 13:47:49 +0900 Subject: [PATCH 043/289] =?UTF-8?q?feat:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20api=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/adminController/AdminController.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index e97d7268..a970b7a0 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -1,6 +1,8 @@ package JGS.CasperEvent.domain.event.controller.adminController; import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.global.response.ResponseDto; import jakarta.validation.Valid; @@ -20,9 +22,17 @@ public AdminController(AdminService adminService) { } @PostMapping("/join") - public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto adminRequestDto){ + public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto adminRequestDto) { return ResponseEntity .status(HttpStatus.CREATED) .body(adminService.postAdmin(adminRequestDto)); } + + @PostMapping("/event/lottery") + public ResponseEntity createLotteryEvent( + @RequestBody LotteryEventRequestDto lotteryEventRequestDto) { + return ResponseEntity + .status(HttpStatus.CREATED) + .body(adminService.createLotteryEvent(lotteryEventRequestDto)); + } } From ac2cd5f96e8185f227f7443f6acaf19b564243f1 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 14:08:16 +0900 Subject: [PATCH 044/289] =?UTF-8?q?chore:=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=20=EC=BB=A4=EC=8A=A4=ED=85=80=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/global/enums/CustomErrorCode.java | 2 +- .../eventController/LotteryEventControllerTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index 035630f9..ae109d03 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -5,7 +5,7 @@ @Getter public enum CustomErrorCode { NO_RUSH_EVENT("선착순 이벤트를 찾을 수 없습니다.", 404), - INVALID_CASPERBOT_PARAMETER("잘못된 파라미터 입력입니다.", 400), + INVALID_PARAMETER("잘못된 파라미터 입력입니다.", 400), CASPERBOT_NOT_FOUND("배지를 찾을 수 없습니다.", 404), BAD_REQUEST("잘못된 요청입니다.", 400), UNAUTHORIZED("권한이 없습니다.", 401), diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java index 7cdecf86..320b9987 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java @@ -112,7 +112,7 @@ void createCasperBotFailureTest_RequiredFieldNotExist() throws Exception { //then perform.andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.errorCode").value("INVALID_CASPERBOT_PARAMETER")) + .andExpect(jsonPath("$.errorCode").value("INVALID_PARAMETER")) .andDo(print()); } @@ -141,7 +141,7 @@ void createCasperBotSuccessTest_WrongValue() throws Exception { //then perform.andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.errorCode").value("INVALID_CASPERBOT_PARAMETER")) + .andExpect(jsonPath("$.errorCode").value("INVALID_PARAMETER")) .andDo(print()); } From 77170e223ce2731153c9a4ed209c495710cc2d09 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 14:09:03 +0900 Subject: [PATCH 045/289] =?UTF-8?q?feat:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=8B=9C=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20?= =?UTF-8?q?=EA=B2=80=EC=82=AC=20=EC=A7=84=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminController/AdminController.java | 2 +- .../RequestDto/LotteryEventRequestDto.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index a970b7a0..81b318a6 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -30,7 +30,7 @@ public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto @PostMapping("/event/lottery") public ResponseEntity createLotteryEvent( - @RequestBody LotteryEventRequestDto lotteryEventRequestDto) { + @Valid @RequestBody LotteryEventRequestDto lotteryEventRequestDto) { return ResponseEntity .status(HttpStatus.CREATED) .body(adminService.createLotteryEvent(lotteryEventRequestDto)); diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java new file mode 100644 index 00000000..59afda19 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java @@ -0,0 +1,19 @@ +package JGS.CasperEvent.domain.event.dto.RequestDto; + +import jakarta.validation.constraints.NotNull; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +public class LotteryEventRequestDto { + + @NotNull(message = "이벤트 시작 일자를 지정하세요.") + private LocalDateTime eventStartDate; + + @NotNull(message = "이벤트 종료 일자를 지정하세요.") + private LocalDateTime eventEndDate; + + @NotNull(message = "당첨인원 수를 지정하세요.") + private int winnerCount; +} From fd0fd2e18bbdb1e1ef6a2ba3b7db6e9f1970c872 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 14:09:18 +0900 Subject: [PATCH 046/289] =?UTF-8?q?feat:=20LotteryEvent=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/event/LotteryEvent.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java index 79c76c18..954adeb7 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java @@ -3,10 +3,22 @@ import jakarta.persistence.*; import lombok.Getter; +import java.time.LocalDateTime; + @Entity @Getter public class LotteryEvent extends BaseEvent { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long lotteryEventId; + + public LotteryEvent(LocalDateTime eventStartDate, LocalDateTime eventEndDate, int winnerCount){ + this.eventStartDate = eventStartDate; + this.eventEndDate = eventEndDate; + this.winnerCount = winnerCount; + } + + public LotteryEvent() { + + } } From 5bb3d815c65e6ed0d66c4a5f47b3a29bcefd81a1 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 14:09:49 +0900 Subject: [PATCH 047/289] =?UTF-8?q?feat:=20LotteryEvent=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20API=20=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 19 +++++++++++++++++++ .../eventService/LotteryEventService.java | 4 ++-- .../global/error/GlobalExceptionHandler.java | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index e66fa193..466f7b5c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -1,8 +1,13 @@ package JGS.CasperEvent.domain.event.service.adminService; import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.entity.admin.Admin; +import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; import JGS.CasperEvent.domain.event.repository.AdminRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.Role; import JGS.CasperEvent.global.error.exception.CustomException; @@ -10,12 +15,16 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; import java.util.NoSuchElementException; @RequiredArgsConstructor @Service public class AdminService { + private final AdminRepository adminRepository; + private final LotteryEventRepository lotteryEventRepository; + private final RushEventRepository rushEventRepository; public Admin verifyAdmin(AdminRequestDto adminRequestDto) { return adminRepository.findById(adminRequestDto.getAdminId()).orElseThrow(NoSuchElementException::new); @@ -33,4 +42,14 @@ public ResponseDto postAdmin(AdminRequestDto adminRequestDto) { return ResponseDto.of("관리자 생성 성공"); } + + public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lotteryEventRequestDto) { + LotteryEvent lotteryEvent = lotteryEventRepository.save(new LotteryEvent( + lotteryEventRequestDto.getEventStartDate(), + lotteryEventRequestDto.getEventEndDate(), + lotteryEventRequestDto.getWinnerCount() + )); + + return LotteryEventResponseDto.of(lotteryEvent, LocalDateTime.now()); + } } 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 5a94885e..a5be1e61 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 @@ -90,8 +90,8 @@ public LotteryParticipants registerUserIfNeed(BaseUser user) { // TODO: 가짜 API, DB 접속되도록 수정 public LotteryEventResponseDto getLotteryEvent() { return new LotteryEventResponseDto(LocalDateTime.now(), - LocalDate.of(2000, 9, 27), - LocalDate.of(2100, 9, 27), + LocalDateTime.of(2000, 9, 27, 0, 0), + LocalDateTime.of(2100, 9, 27, 0, 0), ChronoUnit.DAYS.between(LocalDate.of(2000, 9, 27), LocalDate.of(2100, 9, 27))); } diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java index de569e89..f0e00657 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java +++ b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java @@ -51,7 +51,7 @@ public ResponseEntity methodArgumentNotValidExceptionHandler(Meth return ResponseEntity .status(HttpStatus.BAD_REQUEST) - .body(ErrorResponse.of(CustomErrorCode.INVALID_CASPERBOT_PARAMETER, builder.toString())); + .body(ErrorResponse.of(CustomErrorCode.INVALID_PARAMETER, builder.toString())); } @ExceptionHandler(RuntimeException.class) From 9d94945c5bffd9737d1bc439f0f3af5753a1f26b Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:05:07 +0900 Subject: [PATCH 048/289] =?UTF-8?q?feat:=20LocalDateTime=20=EC=A7=81?= =?UTF-8?q?=EB=A0=AC=ED=99=94=20=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/global/entity/BaseEntity.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/entity/BaseEntity.java b/Server/src/main/java/JGS/CasperEvent/global/entity/BaseEntity.java index 1f65da20..6a41fb05 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/entity/BaseEntity.java +++ b/Server/src/main/java/JGS/CasperEvent/global/entity/BaseEntity.java @@ -1,8 +1,13 @@ package JGS.CasperEvent.global.entity; +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.Column; import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; +import lombok.Getter; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -12,20 +17,16 @@ @EntityListeners(AuditingEntityListener.class) @MappedSuperclass +@Getter public class BaseEntity { - @CreatedDate + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonDeserialize(using = LocalDateTimeDeserializer.class) @Column(updatable = false) private LocalDateTime createdAt; @LastModifiedDate + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonDeserialize(using = LocalDateTimeDeserializer.class) private LocalDateTime updatedAt; - - public LocalDateTime getCreatedAt() { - return createdAt; - } - - public LocalDateTime getUpdatedAt() { - return updatedAt; - } } From f89d14f52e3968c2f2a959f29c21940c9f6ad675 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:05:15 +0900 Subject: [PATCH 049/289] =?UTF-8?q?feat:=20LocalDateTime=20=EC=A7=81?= =?UTF-8?q?=EB=A0=AC=ED=99=94=20=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/event/BaseEvent.java | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java index c16fe270..491c8b9e 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java @@ -1,23 +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.LocalDate; +import java.time.LocalDateTime; +@Getter +@MappedSuperclass public class BaseEvent extends BaseEntity { - protected LocalDate eventStartDate; - protected LocalDate eventEndDate; - protected int winnerCount; + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonDeserialize(using = LocalDateTimeDeserializer.class) + private LocalDateTime startDateTime; - public LocalDate getEventStartDate() { - return eventStartDate; - } + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonDeserialize(using = LocalDateTimeDeserializer.class) + private LocalDateTime endDateTime; + private int winnerCount; - public LocalDate getEventEndDate() { - return eventEndDate; + // 기본 생성자에서 디폴트 값 설정 + public BaseEvent() { + this.startDateTime = LocalDateTime.now(); + this.endDateTime = LocalDateTime.now().plusMinutes(10); + this.winnerCount = 0; // 기본 우승자 수를 0으로 설정 } - public int getWinnerCount() { - return winnerCount; + // 특정 값을 설정할 수 있는 생성자 + public BaseEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, int winnerCount) { + this.startDateTime = startDateTime; + this.endDateTime = endDateTime; + this.winnerCount = winnerCount; } } From 6b5f0f824b17622fb180e5019201cc273823ce88 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:05:48 +0900 Subject: [PATCH 050/289] =?UTF-8?q?feat:=20BaseUser=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EC=97=90=20RushParticipants=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/JGS/CasperEvent/global/entity/BaseUser.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java b/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java index ee143b23..09f06708 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java +++ b/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java @@ -1,6 +1,7 @@ package JGS.CasperEvent.global.entity; import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; +import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; import JGS.CasperEvent.global.enums.Role; import com.fasterxml.jackson.annotation.JsonManagedReference; import jakarta.persistence.*; @@ -18,6 +19,10 @@ public class BaseUser extends BaseEntity { @OneToOne(mappedBy = "baseUser", cascade = CascadeType.ALL) private LotteryParticipants lotteryParticipants; + @JsonManagedReference + @OneToOne(mappedBy = "baseUser", cascade = CascadeType.ALL) + private RushParticipants rushParticipants; + public void updateLotteryParticipants(LotteryParticipants lotteryParticipant) { this.lotteryParticipants = lotteryParticipant; } From 5b8f11067fb9338e9f60f4043494ec8de3187f25 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:06:05 +0900 Subject: [PATCH 051/289] =?UTF-8?q?feat:=20LocalDateTime=20=EC=A7=81?= =?UTF-8?q?=EB=A0=AC=ED=99=94=20=EC=84=A4=EC=A0=95=EC=9D=84=20=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20=EC=9C=84=ED=95=B4=20=EC=9D=98=EC=A1=B4=EC=84=B1=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 --- Server/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/Server/build.gradle b/Server/build.gradle index 33e8c515..68f53cb8 100644 --- a/Server/build.gradle +++ b/Server/build.gradle @@ -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' } From 8eb923eb980f34b60854aa085f8a4873ff873f3a Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:06:19 +0900 Subject: [PATCH 052/289] =?UTF-8?q?feat:=20CursomErrorCode=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 --- .../java/JGS/CasperEvent/global/enums/CustomErrorCode.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index 035630f9..75378d38 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -14,9 +14,9 @@ public enum CustomErrorCode { JWT_PARSE_EXCEPTION("Json 파싱 오류입니다.", 400), JWT_EXCEPTION("JWT 오류입니다.", 400), JWT_EXPIRED("만료된 토큰입니다.", 400), - JWT_MISSING("인증 토큰이 존재하지 않습니다.", 401); - - + JWT_MISSING("인증 토큰이 존재하지 않습니다.", 401), + MULTIPLE_RUSH_EVENTS_FOUND("해당 날짜에 여러 개의 이벤트가 존재합니다.", 409), + TODAY_RUSH_EVENT_NOT_FOUND("오늘의 이벤트를 찾을 수 없습니다.", 404); // 새로운 예외 추가 private final String message; private int status; From 463241c0ca1c5ce8761cc782f78a0fa0da75af73 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:07:07 +0900 Subject: [PATCH 053/289] =?UTF-8?q?fix:=20github=20action=20=ED=8A=B8?= =?UTF-8?q?=EB=A6=AC=EA=B1=B0=EB=A5=BC=20pull=5Frequest=20->=20push=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0aabad65..13b48476 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,7 +14,6 @@ env: jobs: build-and-deploy: runs-on: ubuntu-latest - steps: - name: Checkout code uses: actions/checkout@v2 From 7c3ba60d3116c9cae1095fb783774c21f46f115d Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:08:16 +0900 Subject: [PATCH 054/289] =?UTF-8?q?fix:=20LocalDate=20->=20LocalDateTime?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/dto/ResponseDto/LotteryEventResponseDto.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java index 6ca3df36..c15eed07 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java @@ -6,14 +6,14 @@ import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; -public record LotteryEventResponseDto(LocalDateTime serverDateTime, LocalDate eventStartDate, LocalDate eventEndDate, +public record LotteryEventResponseDto(LocalDateTime serverDateTime, LocalDateTime eventStartDate, LocalDateTime eventEndDate, long activePeriod) { public static LotteryEventResponseDto of(LocalDateTime serverDateTime, LotteryEvent lotteryEvent) { 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()) ); } From 2b3f4ef428ef374c8086b7427953ee7c498992f2 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:08:21 +0900 Subject: [PATCH 055/289] =?UTF-8?q?fix:=20LocalDate=20->=20LocalDateTime?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/eventService/LotteryEventService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 5a94885e..3051249d 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 @@ -90,8 +90,8 @@ public LotteryParticipants registerUserIfNeed(BaseUser user) { // TODO: 가짜 API, DB 접속되도록 수정 public LotteryEventResponseDto getLotteryEvent() { return new LotteryEventResponseDto(LocalDateTime.now(), - LocalDate.of(2000, 9, 27), - LocalDate.of(2100, 9, 27), + 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))); } From 5c3c894a887093b90c350b0546415d3f12f8b22a Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:09:16 +0900 Subject: [PATCH 056/289] =?UTF-8?q?feat:=20=EB=A9=94=EC=9D=B8=ED=99=94?= =?UTF-8?q?=EB=A9=B4=EC=97=90=EC=84=9C=20=EB=B3=B4=EC=97=AC=EC=A7=88=20Rus?= =?UTF-8?q?hEvent=EC=9D=98=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EB=8B=B4?= =?UTF-8?q?=EB=8A=94=20DTO=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ResponseDto/MainRushEventResponseDto.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventResponseDto.java new file mode 100644 index 00000000..cfd61949 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventResponseDto.java @@ -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() + ); + } +} From 1dfaf0fe80d24162e55da9e8f29f9456116837fd Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:09:47 +0900 Subject: [PATCH 057/289] =?UTF-8?q?feat:=20Redis=EC=97=90=20RushEvent?= =?UTF-8?q?=EB=A5=BC=20=EB=8B=B4=EA=B8=B0=20=EC=9C=84=ED=95=9C=20RushEvent?= =?UTF-8?q?RedisTemplate=EC=9D=84=20Bean=EC=9C=BC=EB=A1=9C=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/global/config/RedisConfig.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/config/RedisConfig.java b/Server/src/main/java/JGS/CasperEvent/global/config/RedisConfig.java index 355ac87a..f397261c 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/config/RedisConfig.java +++ b/Server/src/main/java/JGS/CasperEvent/global/config/RedisConfig.java @@ -1,6 +1,7 @@ package JGS.CasperEvent.global.config; import JGS.CasperEvent.domain.event.dto.ResponseDto.CasperBotResponseDto; +import JGS.CasperEvent.domain.event.entity.event.RushEvent; import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; @@ -29,7 +30,7 @@ public RedisConnectionFactory redisConnectionFactory(){ } @Bean - public RedisTemplate redisTemplate(){ + public RedisTemplate CasperBotRedisTemplate(){ RedisTemplate redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(redisConnectionFactory()); redisTemplate.setKeySerializer(new StringRedisSerializer()); @@ -37,4 +38,12 @@ public RedisTemplate redisTemplate(){ return redisTemplate; } + @Bean + public RedisTemplate RushEventRedisTemplate(){ + RedisTemplate redisTemplate = new RedisTemplate<>(); + redisTemplate.setConnectionFactory(redisConnectionFactory()); + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); + return redisTemplate; + } } From 262ea60299210f2d1db179bf533a2fedf503677a Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:10:35 +0900 Subject: [PATCH 058/289] =?UTF-8?q?fix:=20=EC=9C=A0=EB=8B=88=ED=81=AC=20?= =?UTF-8?q?=EC=A0=9C=EC=95=BD=EC=A1=B0=EA=B1=B4=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=EB=A5=BC=20=ED=95=B4=EA=B2=B0=ED=95=98=EA=B8=B0=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=EC=84=9C=20RushEvent=EA=B0=80=20=EA=B0=81=EA=B0=81=20?= =?UTF-8?q?=EB=91=90=EA=B0=9C=EC=9D=98=20=EC=98=B5=EC=85=98=EC=9D=84=20?= =?UTF-8?q?=EA=B0=96=EB=8A=94=20=EA=B2=83=EC=9D=B4=20=EC=95=84=EB=8B=8C,?= =?UTF-8?q?=20Set=20=ED=98=95=ED=83=9C=EB=A1=9C=20option?= =?UTF-8?q?=EC=9D=84=20=EA=B0=96=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/event/RushEvent.java | 34 ++++++------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java index 38767fbb..07ba336b 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java @@ -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; @@ -14,13 +17,9 @@ 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 options; @OneToMany(mappedBy = "rushEvent", cascade = CascadeType.ALL, orphanRemoval = true) private Set rushParticipants; @@ -28,29 +27,16 @@ public class RushEvent extends BaseEvent { 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; } } From e949dfbd12c5073ca4c4cf4ea6ee86ed65965643 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:10:55 +0900 Subject: [PATCH 059/289] =?UTF-8?q?feat:=20=EB=B0=B8=EB=9F=B0=EC=8A=A4=20?= =?UTF-8?q?=EA=B2=8C=EC=9E=84=20=EA=B2=B0=EA=B3=BC=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventController/RushEventController.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java index 6b3fa926..a0b7790b 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java @@ -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; @@ -20,7 +21,7 @@ public RushEventController(RushEventService rushEventService) { // 전체 선착순 이벤트 조회 @GetMapping - public ResponseEntity getRushEventListAndServerTime() { + public ResponseEntity getRushEventListAndServerTime() { return ResponseEntity.ok(rushEventService.getAllRushEvents()); } @@ -47,4 +48,19 @@ public ResponseEntity rushEventRate (@PathVariable("ev RushEventRateResponseDto rushEventRateResponseDto = rushEventService.getRushEventRate(eventId); return ResponseEntity.ok(rushEventRateResponseDto); } + + // 밸런스 게임 결과 조회 + @GetMapping("/{eventId}/result") + public ResponseEntity 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 setTodayEvent() { + rushEventService.setTodayEventToRedis(); + return ResponseEntity.noContent().build(); + } } From 75a90bc40d3a1ef59ce1a167d9ff538cfc6225d8 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:12:04 +0900 Subject: [PATCH 060/289] =?UTF-8?q?fix:=20RushEvent=20=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=ED=99=94=EB=A9=B4=20=EC=A1=B0=ED=9A=8C=20API=EC=9D=98=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EA=B0=80=20=EC=B6=94=EA=B0=80=EB=90=98?= =?UTF-8?q?=EC=96=B4=EC=84=9C=20=ED=95=B4=EB=8B=B9=20=EC=82=AC=ED=95=AD=20?= =?UTF-8?q?=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...RushEventListAndServerTimeResponseDto.java | 31 ------------------- .../ResponseDto/RushEventListResponseDto.java | 26 ++++++++++++++++ 2 files changed, 26 insertions(+), 31 deletions(-) delete mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventListAndServerTimeResponseDto.java create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventListResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventListAndServerTimeResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventListAndServerTimeResponseDto.java deleted file mode 100644 index cc17a58b..00000000 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventListAndServerTimeResponseDto.java +++ /dev/null @@ -1,31 +0,0 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto; - -import java.time.LocalDateTime; -import java.util.List; - -public class RushEventListAndServerTimeResponseDto { - private List events; - private LocalDateTime serverTime; - - public RushEventListAndServerTimeResponseDto(List events, LocalDateTime serverTime) { - this.events = events; - this.serverTime = serverTime; - } - - // Getters and setters - public List getEvents() { - return events; - } - public void setEvents(List events) { - this.events = events; - } - - public LocalDateTime getServerTime() { - return serverTime; - } - - public void setServerTime(LocalDateTime serverTime) { - this.serverTime = serverTime; - } - -} diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventListResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventListResponseDto.java new file mode 100644 index 00000000..abcac614 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventListResponseDto.java @@ -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 events; + private LocalDateTime serverTime; + private Long todayEventId; + private LocalDate eventStartDate; + private LocalDate eventEndDate; + private Long activePeriod; + + public RushEventListResponseDto(List 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; + } +} From 97efb30922cc50c8eaa9538ae8d19881070df387 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:12:49 +0900 Subject: [PATCH 061/289] =?UTF-8?q?fix:=20=EA=B8=B0=EC=A1=B4=20Dto=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A5=BC=20->=20record=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/dto/ResponseDto/RushEventRateResponseDto.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java index 87700f1e..a4b81c45 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java @@ -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) { } From aa2b29b73fa1038e63f7993e4c0d80505d94a0f8 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:13:48 +0900 Subject: [PATCH 062/289] =?UTF-8?q?feat:=20=EC=98=A4=EB=8A=98=20=EB=82=A0?= =?UTF-8?q?=EC=A7=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=EB=A5=BC=20=EA=BA=BC?= =?UTF-8?q?=EB=82=B4=EC=98=A4=EB=8A=94=20=EC=BF=BC=EB=A6=AC=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/eventRepository/RushEventRepository.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushEventRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushEventRepository.java index 3ff0c837..1913977f 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushEventRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushEventRepository.java @@ -2,8 +2,17 @@ import JGS.CasperEvent.domain.event.entity.event.RushEvent; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.time.LocalDate; +import java.util.List; + @Repository public interface RushEventRepository extends JpaRepository { + @Query("SELECT e FROM RushEvent e WHERE DATE(e.startDateTime) = :eventDate") + List findByEventDate(@Param("eventDate") LocalDate eventDate); + + RushEvent findByRushEventId(Long rushEventId); } From 5dc3e445af60ef43dc7aaa1f2be1c30b1961107d Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:14:10 +0900 Subject: [PATCH 063/289] =?UTF-8?q?fix:=20LocalDate=20->=20LocalDateTime?= =?UTF-8?q?=20=ED=83=80=EC=9E=85=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/dto/ResponseDto/RushEventResponseDto.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java index f6c9558d..923f30d6 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java @@ -4,21 +4,22 @@ 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, LocalDate startDate, LocalDate endDate, +public record RushEventResponseDto(Long rushEventId, LocalDateTime startDateTime, LocalDateTime endDateTime, int winnerCount, String prizeImageUrl, String prizeDescription, - RushOption leftOption, RushOption rightOption){ + Set 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() ); } From d72f1c13b83594281c71acf0dfc7b3b12bcff0e4 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:15:45 +0900 Subject: [PATCH 064/289] =?UTF-8?q?feat:=20RushEvent=20=EA=B2=B0=EA=B3=BC?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20API=20=EC=9D=91=EB=8B=B5=20DTO=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/ResponseDto/RushEventResultResponseDto.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResultResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResultResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResultResponseDto.java new file mode 100644 index 00000000..f8171066 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResultResponseDto.java @@ -0,0 +1,10 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public record RushEventResultResponseDto(long leftOption, long rightOption, long rank, long totalParticipants, + long winnerCount) { +} From 6ce2fff33a2c53c7f6b6ea0651e48f5059642716 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:16:13 +0900 Subject: [PATCH 065/289] =?UTF-8?q?feat:=20=EC=98=A4=EB=8A=98=EC=9D=98=20R?= =?UTF-8?q?ushEvent=EB=A5=BC=20=EB=A7=A4=EC=9D=BC=2012=EC=8B=9C=EC=97=90?= =?UTF-8?q?=20Redis=EC=97=90=20=EB=84=A3=EB=8A=94=20=EC=8A=A4=EC=BC=80?= =?UTF-8?q?=EC=A4=84=EB=9F=AC=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventService/RushEventScheduler.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventScheduler.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventScheduler.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventScheduler.java new file mode 100644 index 00000000..9d91e79c --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventScheduler.java @@ -0,0 +1,33 @@ +package JGS.CasperEvent.domain.event.service.eventService; + +import JGS.CasperEvent.domain.event.entity.event.RushEvent; +import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; + +@Service +@EnableScheduling +@RequiredArgsConstructor +public class RushEventScheduler { + + private final RushEventService rushEventService; + private final RedisTemplate rushEventRedisTemplate; + + // 매일 12시에 스케줄된 작업을 실행합니다. + @Scheduled(cron = "0 0 12 * * ?") + public void fetchDailyEvents() { + // 오늘의 날짜를 구합니다. + LocalDate today = LocalDate.now(); + + // EventService를 통해 오늘의 이벤트를 가져옵니다. + RushEvent todayEvent = rushEventService.getTodayRushEvent(today); + + // 가져온 이벤트에 대한 추가 작업을 수행합니다. + // 예: 캐싱, 로그 기록, 알림 발송 등 + rushEventRedisTemplate.opsForValue().set("todayEvent", todayEvent); + } +} From d68c9a5a116d56ad208eddafc6175235b8ed23a7 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:18:12 +0900 Subject: [PATCH 066/289] =?UTF-8?q?fix:=20=EC=83=9D=EC=84=B1=EC=9E=90?= =?UTF-8?q?=EC=97=90=EC=84=9C=20RushEventRateResponseDto=EB=A5=BC=20?= =?UTF-8?q?=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ResponseDto/RushEventResultResponseDto.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResultResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResultResponseDto.java index f8171066..4fee8df8 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResultResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResultResponseDto.java @@ -5,6 +5,18 @@ @Getter @AllArgsConstructor -public record RushEventResultResponseDto(long leftOption, long rightOption, long rank, long totalParticipants, - long winnerCount) { +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; + } } From baca0a16152c88bc63cd0eca24108e303e0f1fa2 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:18:56 +0900 Subject: [PATCH 067/289] =?UTF-8?q?feat:=20rushEvent=EB=A5=BC=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=ED=99=94=ED=95=98=EA=B3=A0,=20=EC=98=A4=EB=8A=98?= =?UTF-8?q?=EC=9D=98=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=EB=A5=BC=20redis?= =?UTF-8?q?=EC=97=90=20=EB=84=A3=EB=8A=94=20API=20=EA=B5=AC=ED=98=84,=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=EC=A0=81=EC=9D=B8=20API=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventService/RushEventService.java | 161 ++++++++++++++++-- 1 file changed, 146 insertions(+), 15 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java index 35afbd36..26fb59b8 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java @@ -1,48 +1,82 @@ package JGS.CasperEvent.domain.event.service.eventService; -import JGS.CasperEvent.domain.event.dto.ResponseDto.RushEventResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.RushEventListAndServerTimeResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.RushEventRateResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.*; import JGS.CasperEvent.domain.event.entity.event.RushEvent; +import JGS.CasperEvent.domain.event.entity.event.RushOption; import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.RushOptionRepository; import JGS.CasperEvent.domain.event.repository.participantsRepository.RushParticipantsRepository; import JGS.CasperEvent.global.entity.BaseUser; import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.error.exception.CustomException; import JGS.CasperEvent.global.util.RepositoryErrorHandler; +import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; +import java.util.Optional; @Service +@RequiredArgsConstructor public class RushEventService { private final RushEventRepository rushEventRepository; private final RushParticipantsRepository rushParticipantsRepository; + private final RedisTemplate rushEventRedisTemplate; + private final RushOptionRepository rushOptionRepository; - public RushEventService(RushEventRepository rushEventRepository, RushParticipantsRepository rushParticipantsRepository) { - this.rushEventRepository = rushEventRepository; - this.rushParticipantsRepository = rushParticipantsRepository; - } + @Transactional + public RushEventListResponseDto getAllRushEvents() { + // 오늘의 선착순 이벤트 꺼내오기 + RushEvent todayEvent = rushEventRedisTemplate.opsForValue().get("todayEvent"); + + // 오늘의 선착순 이벤트가 redis에 등록되지 않은 경우 + if (todayEvent == null) { + throw new CustomException("오늘의 선착순 이벤트가 redis에 등록되지 않았습니다.", CustomErrorCode.TODAY_RUSH_EVENT_NOT_FOUND); + } - public RushEventListAndServerTimeResponseDto getAllRushEvents() { // DB에서 모든 RushEvent 가져오기 List rushEventList = rushEventRepository.findAll(); + + // 선착순 이벤트 전체 시작 날짜와 종료 날짜 구하기 + List dates = rushEventList.stream().map(rushEvent -> rushEvent.getStartDateTime().toLocalDate()).sorted().toList(); + + LocalDate totalStartDate = dates.get(0); + LocalDate totalEndDate = dates.get(dates.size() - 1); + + // 전체 이벤트 기간 구하기 + long activePeriod = totalStartDate.until(totalEndDate).getDays() + 1; + // RushEvent를 DTO로 전환 - List rushEventDtoList = rushEventList.stream() - .map(RushEventResponseDto::of) + List mainRushEventDtoList = rushEventList.stream() + .map(MainRushEventResponseDto::of) .toList(); + // DTO 리스트와 서버 시간을 담은 RushEventListAndServerTimeResponse 객체 생성 후 반환 - return new RushEventListAndServerTimeResponseDto(rushEventDtoList, LocalDateTime.now()); + return new RushEventListResponseDto( + mainRushEventDtoList, + LocalDateTime.now(), + todayEvent.getRushEventId(), + totalStartDate, + totalEndDate, + activePeriod + ); } + // 응모 여부 조회 public boolean isExists(Long eventId, String userId) { - return rushParticipantsRepository.existsByRushEventIdAndUserId(eventId, userId); + return rushParticipantsRepository.existsByRushEvent_RushEventIdAndBaseUser_Id(eventId, userId); } + @Transactional public void apply(BaseUser user, Long eventId, int optionId) { - if (isExists(eventId, user.getId())) { + // 이미 응모한 회원인지 검증 + if (rushParticipantsRepository.existsByRushEvent_RushEventIdAndBaseUser_Id(eventId, user.getId())) { throw new CustomException("이미 응모한 회원입니다.", CustomErrorCode.CONFLICT); } @@ -55,9 +89,106 @@ public void apply(BaseUser user, Long eventId, int optionId) { } public RushEventRateResponseDto getRushEventRate(Long eventId) { - long leftOptionCount = rushParticipantsRepository.countByRushEventIdAndOptionId(eventId, 1); - long rightOptionCount = rushParticipantsRepository.countByRushEventIdAndOptionId(eventId, 2); + long leftOptionCount = rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(eventId, 1); + long rightOptionCount = rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(eventId, 2); return new RushEventRateResponseDto(leftOptionCount, rightOptionCount); } + + // 이벤트 결과를 반환 + // 해당 요청은 무조건 응모한 유저일 때만 요청 가능하다고 가정 + @Transactional + public RushEventResultResponseDto getRushEventResult(BaseUser user, Long eventId) { + // 최종 선택 비율을 조회 + // TODO: 레디스에 캐시 + RushEventRateResponseDto rushEventRateResponseDto = getRushEventRate(eventId); + + // 해당 이벤트의 당첨자 수를 가져옴 + int winnerCount = rushEventRepository.findByRushEventId(eventId).getWinnerCount(); + + // 해당 유저가 응모한 optionId 가져옴 + Optional optionId = rushParticipantsRepository.getOptionIdByUserId(user.getId()); + + if (optionId.isEmpty()) { + throw new CustomException("해당 유저가 이벤트 응모를 하지 않았습니다.", CustomErrorCode.USER_NOT_FOUND); + } + + // eventId, userId, optionId 를 이용하여 해당 유저가 응모한 선택지에서 등수를 가져옴 + long rank = rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(eventId, user.getId(), optionId.get()); + + // 해당 선택지를 선택한 모든 유저 수를 가져옴 + long totalParticipants = rushParticipantsRepository.countAllByOptionId(optionId.get()); + + return new RushEventResultResponseDto(rushEventRateResponseDto.getLeftOption(), rushEventRateResponseDto.rightOption(), rank, totalParticipants, winnerCount); + } + + @Transactional + // 오늘의 이벤트를 DB에 꺼내서 반환 + public RushEvent getTodayRushEvent(LocalDate today) { + // 오늘 날짜에 해당하는 모든 이벤트 꺼내옴 + List rushEventList = rushEventRepository.findByEventDate(today); + + if (rushEventList.isEmpty()) { + throw new CustomException("선착순 이벤트가 존재하지않습니다.", CustomErrorCode.NO_RUSH_EVENT); + } + + if (rushEventList.size() > 1) { + throw new CustomException("선착순 이벤트가 존재하지않습니다.", CustomErrorCode.MULTIPLE_RUSH_EVENTS_FOUND); + } + + return rushEventList.get(0); + } + + @Transactional + public void setTodayEventToRedis() { + // 테이블 초기화 + rushParticipantsRepository.deleteAllInBatch(); + rushOptionRepository.deleteAllInBatch(); + rushEventRepository.deleteAllInBatch(); + + LocalDateTime startDateTime = LocalDateTime.of(2024, 8, 11, 22, 0); + LocalDateTime endDateTime = startDateTime.plusMinutes(10); + + List rushEvents = new ArrayList<>(); + + for (int i = 0; i < 6; i++) { + // RushEvent 생성 및 초기화 + RushEvent rushEvent = new RushEvent( + startDateTime.plusDays(i), // 이벤트 시작 날짜 + endDateTime.plusDays(i), // 이벤트 종료 날짜 + 0, // 우승자 수 (winnerCount) + "http://example.com/prize" + (i + 1) + ".jpg", // 상 이미지 URL + "Prize Description " + (i + 1) // 상 설명 + ); + + // RushEvent 저장 + rushEvent = rushEventRepository.save(rushEvent); + rushEvents.add(rushEvent); + + // 첫 번째 RushOption 생성 및 저장 + RushOption option1 = new RushOption( + rushEvent, + "Option 1 Main Text for Event " + (i + 1), + "Option 1 Sub Text for Event " + (i + 1), + "Option 1 Result Main Text for Event " + (i + 1), + "Option 1 Result Sub Text for Event " + (i + 1), + "http://example.com/option1-image" + (i + 1) + ".jpg" + ); + rushOptionRepository.save(option1); + + // 두 번째 RushOption 생성 및 저장 + RushOption option2 = new RushOption( + rushEvent, + "Option 2 Main Text for Event " + (i + 1), + "Option 2 Sub Text for Event " + (i + 1), + "Option 2 Result Main Text for Event " + (i + 1), + "Option 2 Result Sub Text for Event " + (i + 1), + "http://example.com/option2-image" + (i + 1) + ".jpg" + ); + rushOptionRepository.save(option2); + } + + // 처음으로 생성된 RushEvent를 Redis에 저장 + rushEventRedisTemplate.opsForValue().set("todayEvent", rushEvents.get(0)); + } } From ac26b67420fb1e2603957f5618469c7894b9fb57 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:20:12 +0900 Subject: [PATCH 068/289] =?UTF-8?q?fix:=20=EB=A1=AC=EB=B3=B5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84?= =?UTF-8?q?=EB=A5=BC=20OneToOne=20->=20ManyToOne=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/event/RushOption.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java index 4e771731..a66fd6d1 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java @@ -2,16 +2,20 @@ import JGS.CasperEvent.global.entity.BaseEntity; import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; @Entity -public class RushOption extends BaseEntity{ +@AllArgsConstructor +@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; From eeca21c736290826bab8efb8d0183d334bc1d614 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:20:34 +0900 Subject: [PATCH 069/289] =?UTF-8?q?fix:=20RushOptionRepository=20JPA?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/eventRepository/RushOptionRepository.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushOptionRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushOptionRepository.java index e4e65d12..96130c15 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushOptionRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushOptionRepository.java @@ -1,7 +1,9 @@ package JGS.CasperEvent.domain.event.repository.eventRepository; +import JGS.CasperEvent.domain.event.entity.event.RushOption; +import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository -public interface RushOptionRepository { +public interface RushOptionRepository extends JpaRepository { } From c93d8fbcdc60e7a99e2cebdd1e51423705385bf8 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:21:41 +0900 Subject: [PATCH 070/289] =?UTF-8?q?fix:=20=EC=B0=B8=EC=A1=B0=20=EC=88=9C?= =?UTF-8?q?=ED=99=98=20=EC=97=90=EB=9F=AC=EB=A5=BC=20=ED=95=B4=EA=B2=B0?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=B4=20@JsonBackReference=20?= =?UTF-8?q?=EC=95=A0=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=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 --- .../domain/event/entity/participants/RushParticipants.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/RushParticipants.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/RushParticipants.java index f160d1ff..d3d5b213 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/RushParticipants.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/RushParticipants.java @@ -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 @@ -12,6 +13,7 @@ public class RushParticipants { private int optionId; @OneToOne @JoinColumn(name = "base_user_id") + @JsonBackReference private BaseUser baseUser; @ManyToOne From a511154a065c0716ecfd3a0773e6288057d4a987 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:22:13 +0900 Subject: [PATCH 071/289] =?UTF-8?q?fix:=20=EC=B5=9C=EB=8C=80=ED=95=9C=20JP?= =?UTF-8?q?A=20=EA=B8=B0=EB=B3=B8=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A1=9C?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8A=94?= =?UTF-8?q?=EA=B1=B4=20=EC=B2=98=EB=A6=AC=ED=95=A0=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD,=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EC=A0=81=EC=9D=B8=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RushParticipantsRepository.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java index d8b0daea..f53b74f7 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java @@ -6,14 +6,23 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.util.Optional; + @Repository public interface RushParticipantsRepository extends JpaRepository { - @Query("SELECT CASE WHEN COUNT(rp) > 0 THEN TRUE ELSE FALSE END " + - "FROM RushParticipants rp " + - "WHERE rp.rushEvent.rushEventId = :eventId AND rp.baseUser.id = :userId") - boolean existsByRushEventIdAndUserId(@Param("eventId") Long eventId, @Param("userId") String userId); + boolean existsByRushEvent_RushEventIdAndBaseUser_Id(Long eventId, String userId); + long countByRushEvent_RushEventIdAndOptionId(Long eventId, int optionId); + @Query("SELECT COUNT(rp) + 1 FROM RushParticipants rp " + + "WHERE rp.rushEvent.rushEventId = :eventId " + + "AND rp.optionId = :optionId " + + "AND rp.id < (SELECT rp2.id FROM RushParticipants rp2 " + + "WHERE rp2.rushEvent.rushEventId = :eventId " + + "AND rp2.baseUser.id = :userId)") + long findUserRankByEventIdAndUserIdAndOptionId(@Param("eventId") Long eventId, + @Param("userId") String userId, + @Param("optionId") int optionId); + long countAllByOptionId(int optionId); + @Query("SELECT rp.optionId FROM RushParticipants rp WHERE rp.baseUser.id = :userId") + Optional getOptionIdByUserId(@Param("userId") String userId); - @Query("SELECT COUNT(rp) FROM RushParticipants rp " + - "WHERE rp.rushEvent.rushEventId = :eventId AND rp.optionId = :optionId") - long countByRushEventIdAndOptionId(@Param("eventId") Long eventId, @Param("optionId") int optionId); } From fdafb1384b6e857ecc208bba3ad86faa21c476de Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Sun, 11 Aug 2024 14:43:41 +0900 Subject: [PATCH 072/289] =?UTF-8?q?feat:=20AllArgsConstructor=20=EB=8C=80?= =?UTF-8?q?=EC=8B=A0=20=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/event/RushOption.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java index a66fd6d1..7d0726ba 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java @@ -2,11 +2,9 @@ import JGS.CasperEvent.global.entity.BaseEntity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; @Entity -@AllArgsConstructor @NoArgsConstructor public class RushOption extends BaseEntity { @Id @@ -21,4 +19,13 @@ public class RushOption extends BaseEntity { 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; + } } From b185678d81eeb98b44967148434ab1e251293afc Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 13:46:32 +0900 Subject: [PATCH 073/289] =?UTF-8?q?chore:=20=EC=96=B4=EB=93=9C=EB=AF=BC=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EC=8B=9D=EB=B3=84=EC=9E=90=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/global/jwt/filter/VerifyAdminFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/VerifyAdminFilter.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/VerifyAdminFilter.java index f189a8d0..19d97a11 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/VerifyAdminFilter.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/VerifyAdminFilter.java @@ -16,7 +16,7 @@ @Slf4j @RequiredArgsConstructor public class VerifyAdminFilter implements Filter { - public static final String AUTHENTICATE_ADMIN = "authenticateAdmin"; + public static final String AUTHENTICATE_ADMIN = "authenticateUser"; private final ObjectMapper objectMapper; private final AdminService adminService; From 6165aac2cfb432de9e18f4b3c62676a91af7e1ee Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 13:47:49 +0900 Subject: [PATCH 074/289] =?UTF-8?q?feat:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20api=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/adminController/AdminController.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index e97d7268..a970b7a0 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -1,6 +1,8 @@ package JGS.CasperEvent.domain.event.controller.adminController; import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.global.response.ResponseDto; import jakarta.validation.Valid; @@ -20,9 +22,17 @@ public AdminController(AdminService adminService) { } @PostMapping("/join") - public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto adminRequestDto){ + public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto adminRequestDto) { return ResponseEntity .status(HttpStatus.CREATED) .body(adminService.postAdmin(adminRequestDto)); } + + @PostMapping("/event/lottery") + public ResponseEntity createLotteryEvent( + @RequestBody LotteryEventRequestDto lotteryEventRequestDto) { + return ResponseEntity + .status(HttpStatus.CREATED) + .body(adminService.createLotteryEvent(lotteryEventRequestDto)); + } } From a1bb4a09acab07c7e2efb930616e139747cb7826 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 14:08:16 +0900 Subject: [PATCH 075/289] =?UTF-8?q?chore:=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=20=EC=BB=A4=EC=8A=A4=ED=85=80=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/global/enums/CustomErrorCode.java | 2 +- .../eventController/LotteryEventControllerTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index 75378d38..408ef36a 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -5,7 +5,7 @@ @Getter public enum CustomErrorCode { NO_RUSH_EVENT("선착순 이벤트를 찾을 수 없습니다.", 404), - INVALID_CASPERBOT_PARAMETER("잘못된 파라미터 입력입니다.", 400), + INVALID_PARAMETER("잘못된 파라미터 입력입니다.", 400), CASPERBOT_NOT_FOUND("배지를 찾을 수 없습니다.", 404), BAD_REQUEST("잘못된 요청입니다.", 400), UNAUTHORIZED("권한이 없습니다.", 401), diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java index 7cdecf86..320b9987 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java @@ -112,7 +112,7 @@ void createCasperBotFailureTest_RequiredFieldNotExist() throws Exception { //then perform.andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.errorCode").value("INVALID_CASPERBOT_PARAMETER")) + .andExpect(jsonPath("$.errorCode").value("INVALID_PARAMETER")) .andDo(print()); } @@ -141,7 +141,7 @@ void createCasperBotSuccessTest_WrongValue() throws Exception { //then perform.andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.errorCode").value("INVALID_CASPERBOT_PARAMETER")) + .andExpect(jsonPath("$.errorCode").value("INVALID_PARAMETER")) .andDo(print()); } From 9665e821d57921bc8687e079b957e1d00a017a92 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 14:09:03 +0900 Subject: [PATCH 076/289] =?UTF-8?q?feat:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=8B=9C=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20?= =?UTF-8?q?=EA=B2=80=EC=82=AC=20=EC=A7=84=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminController/AdminController.java | 2 +- .../RequestDto/LotteryEventRequestDto.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index a970b7a0..81b318a6 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -30,7 +30,7 @@ public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto @PostMapping("/event/lottery") public ResponseEntity createLotteryEvent( - @RequestBody LotteryEventRequestDto lotteryEventRequestDto) { + @Valid @RequestBody LotteryEventRequestDto lotteryEventRequestDto) { return ResponseEntity .status(HttpStatus.CREATED) .body(adminService.createLotteryEvent(lotteryEventRequestDto)); diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java new file mode 100644 index 00000000..59afda19 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java @@ -0,0 +1,19 @@ +package JGS.CasperEvent.domain.event.dto.RequestDto; + +import jakarta.validation.constraints.NotNull; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +public class LotteryEventRequestDto { + + @NotNull(message = "이벤트 시작 일자를 지정하세요.") + private LocalDateTime eventStartDate; + + @NotNull(message = "이벤트 종료 일자를 지정하세요.") + private LocalDateTime eventEndDate; + + @NotNull(message = "당첨인원 수를 지정하세요.") + private int winnerCount; +} From 46437b9abc6617b2dc67d5cea0a03c2c148c541c Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 14:09:18 +0900 Subject: [PATCH 077/289] =?UTF-8?q?feat:=20LotteryEvent=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/event/LotteryEvent.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java index 79c76c18..954adeb7 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java @@ -3,10 +3,22 @@ import jakarta.persistence.*; import lombok.Getter; +import java.time.LocalDateTime; + @Entity @Getter public class LotteryEvent extends BaseEvent { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long lotteryEventId; + + public LotteryEvent(LocalDateTime eventStartDate, LocalDateTime eventEndDate, int winnerCount){ + this.eventStartDate = eventStartDate; + this.eventEndDate = eventEndDate; + this.winnerCount = winnerCount; + } + + public LotteryEvent() { + + } } From a898fb686f4c819a500a47a623cec4a2d918f713 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 14:09:49 +0900 Subject: [PATCH 078/289] =?UTF-8?q?feat:=20LotteryEvent=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20API=20=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 19 +++++++++++++++++++ .../global/error/GlobalExceptionHandler.java | 2 +- .../LotteryEventControllerTest.java | 1 - 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index e66fa193..466f7b5c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -1,8 +1,13 @@ package JGS.CasperEvent.domain.event.service.adminService; import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.entity.admin.Admin; +import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; import JGS.CasperEvent.domain.event.repository.AdminRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.Role; import JGS.CasperEvent.global.error.exception.CustomException; @@ -10,12 +15,16 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; import java.util.NoSuchElementException; @RequiredArgsConstructor @Service public class AdminService { + private final AdminRepository adminRepository; + private final LotteryEventRepository lotteryEventRepository; + private final RushEventRepository rushEventRepository; public Admin verifyAdmin(AdminRequestDto adminRequestDto) { return adminRepository.findById(adminRequestDto.getAdminId()).orElseThrow(NoSuchElementException::new); @@ -33,4 +42,14 @@ public ResponseDto postAdmin(AdminRequestDto adminRequestDto) { return ResponseDto.of("관리자 생성 성공"); } + + public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lotteryEventRequestDto) { + LotteryEvent lotteryEvent = lotteryEventRepository.save(new LotteryEvent( + lotteryEventRequestDto.getEventStartDate(), + lotteryEventRequestDto.getEventEndDate(), + lotteryEventRequestDto.getWinnerCount() + )); + + return LotteryEventResponseDto.of(lotteryEvent, LocalDateTime.now()); + } } diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java index de569e89..f0e00657 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java +++ b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java @@ -51,7 +51,7 @@ public ResponseEntity methodArgumentNotValidExceptionHandler(Meth return ResponseEntity .status(HttpStatus.BAD_REQUEST) - .body(ErrorResponse.of(CustomErrorCode.INVALID_CASPERBOT_PARAMETER, builder.toString())); + .body(ErrorResponse.of(CustomErrorCode.INVALID_PARAMETER, builder.toString())); } @ExceptionHandler(RuntimeException.class) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java index 320b9987..5f4459fb 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java @@ -1,6 +1,5 @@ package JGS.CasperEvent.domain.event.controller.eventController; -import jakarta.servlet.http.Cookie; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; From 5b7978e895b11eb225cc79fb57a5f22b4eb2f03e Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 23:09:05 +0900 Subject: [PATCH 079/289] =?UTF-8?q?refactor:=20=EC=BA=90=EC=8A=A4=ED=8D=BC?= =?UTF-8?q?=20=EB=B4=87=20=EC=83=9D=EC=84=B1=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/domain/event/entity/casperBot/CasperBot.java | 3 +-- .../event/service/eventService/LotteryEventService.java | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java index f9ff849b..575b9132 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java @@ -2,14 +2,12 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.CasperBotRequestDto; import JGS.CasperEvent.global.entity.BaseEntity; -import JGS.CasperEvent.global.util.UserUtil; import jakarta.persistence.*; @Entity public class CasperBot extends BaseEntity { public CasperBot(CasperBotRequestDto postCasperBot, String phoneNumber) { - this.casperId = UserUtil.generateId(); this.phoneNumber = phoneNumber; this.eyeShape = postCasperBot.getEyeShape(); this.eyePosition = postCasperBot.getEyePosition(); @@ -21,6 +19,7 @@ public CasperBot(CasperBotRequestDto postCasperBot, String phoneNumber) { } @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long casperId; private String phoneNumber; 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 3051249d..afc66aa8 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 @@ -48,15 +48,14 @@ public LotteryEventService(LotteryEventRepository lotteryEventRepository, public CasperBotResponseDto postCasperBot(BaseUser user, CasperBotRequestDto postCasperBot) throws CustomException { LotteryParticipants participants = registerUserIfNeed(user); - CasperBot casperBot = new CasperBot(postCasperBot, participants.getBaseUser().getId()); + CasperBot casperBot = casperBotRepository.save(new CasperBot(postCasperBot, participants.getBaseUser().getId())); participants.updateCasperId(casperBot.getCasperId()); if (!casperBot.getExpectation().isEmpty()) participants.expectationAdded(); - lotteryParticipantsRepository.save(participants); - casperBotRepository.save(casperBot); CasperBotResponseDto casperBotDto = CasperBotResponseDto.of(casperBot); redisService.addData(casperBotDto); + return casperBotDto; } From f11d7c56ffc65b1e229021f56144d7808f847139 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 23:12:10 +0900 Subject: [PATCH 080/289] =?UTF-8?q?fix:=20Getter=20=EC=96=B4=EB=85=B8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EC=85=98=EC=97=90=EC=84=9C=20Getter=EB=A1=9C?= =?UTF-8?q?=20=EA=B5=90=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/ResponseDto/RushEventRateResponseDto.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java index a4b81c45..64e5b21a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java @@ -1,7 +1,11 @@ package JGS.CasperEvent.domain.event.dto.ResponseDto; -import lombok.Getter; - -@Getter public record RushEventRateResponseDto(long leftOption, long rightOption) { + public long getLeftOption() { + return leftOption; + } + + public long getRightOption() { + return rightOption; + } } From 6f629ab2e26b3ffc7e46ad914b442cc1b64b9a81 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 23:13:15 +0900 Subject: [PATCH 081/289] =?UTF-8?q?fix:=20=EC=A0=91=EA=B7=BC=EC=A0=9C?= =?UTF-8?q?=EC=96=B4=EC=9E=90=20protected=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/domain/event/entity/event/BaseEvent.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java index 491c8b9e..fa2e1a55 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java @@ -15,12 +15,12 @@ public class BaseEvent extends BaseEntity { @JsonSerialize(using = LocalDateTimeSerializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class) - private LocalDateTime startDateTime; + protected LocalDateTime startDateTime; @JsonSerialize(using = LocalDateTimeSerializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class) - private LocalDateTime endDateTime; - private int winnerCount; + protected LocalDateTime endDateTime; + protected int winnerCount; // 기본 생성자에서 디폴트 값 설정 public BaseEvent() { From 546dea84bfb777b49945adc2a425467de2ffb0a4 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 23:13:37 +0900 Subject: [PATCH 082/289] =?UTF-8?q?fix:=20=ED=95=84=EB=93=9C=EB=AA=85=20Ba?= =?UTF-8?q?seEvent=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/domain/event/entity/event/LotteryEvent.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java index 954adeb7..6e001bd3 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java @@ -12,9 +12,9 @@ public class LotteryEvent extends BaseEvent { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long lotteryEventId; - public LotteryEvent(LocalDateTime eventStartDate, LocalDateTime eventEndDate, int winnerCount){ - this.eventStartDate = eventStartDate; - this.eventEndDate = eventEndDate; + public LotteryEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, int winnerCount) { + this.startDateTime = startDateTime; + this.endDateTime = endDateTime; this.winnerCount = winnerCount; } From ffdb9eff6ea88e8d8783ef61b65ff9a1c4a6fa51 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 23:14:13 +0900 Subject: [PATCH 083/289] =?UTF-8?q?fix:=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=20=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/service/adminService/AdminService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 466f7b5c..c1accc09 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -50,6 +50,6 @@ public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lottery lotteryEventRequestDto.getWinnerCount() )); - return LotteryEventResponseDto.of(lotteryEvent, LocalDateTime.now()); + return LotteryEventResponseDto.of(LocalDateTime.now(), lotteryEvent); } } From 0ba2d038fa2842216d7cd75e433653ed59a28ae0 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 11 Aug 2024 23:36:40 +0900 Subject: [PATCH 084/289] =?UTF-8?q?refactor:=20Getter,=20ToString=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=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 --- .../event/entity/casperBot/CasperBot.java | 75 ++++--------------- .../eventService/LotteryEventService.java | 5 +- 2 files changed, 17 insertions(+), 63 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java index 575b9132..f79ff877 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java @@ -3,24 +3,19 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.CasperBotRequestDto; import JGS.CasperEvent.global.entity.BaseEntity; import jakarta.persistence.*; +import lombok.Getter; +import lombok.ToString; @Entity +@Getter +@ToString public class CasperBot extends BaseEntity { - public CasperBot(CasperBotRequestDto postCasperBot, String phoneNumber) { - this.phoneNumber = phoneNumber; - this.eyeShape = postCasperBot.getEyeShape(); - this.eyePosition = postCasperBot.getEyePosition(); - this.mouthShape = postCasperBot.getMouthShape(); - this.color = postCasperBot.getColor(); - this.sticker = postCasperBot.getSticker(); - this.name = postCasperBot.getName(); - this.expectation = postCasperBot.getExpectation(); - } @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long casperId; + private String phoneNumber; private int eyeShape; @@ -35,56 +30,14 @@ public CasperBot() { } - public Long getCasperId() { - return casperId; - } - - public String getPhoneNumber() { - return phoneNumber; - } - - public int getEyeShape() { - return eyeShape; - } - - public int getEyePosition() { - return eyePosition; - } - - public int getMouthShape() { - return mouthShape; - } - - public int getColor() { - return color; - } - - public int getSticker() { - return sticker; - } - - public String getName() { - return name; - } - - public String getExpectation() { - return expectation; - } - - @Override - public String toString() { - return "CasperBot{" + - "casperId=" + casperId + - ", phoneNumber='" + phoneNumber + '\'' + - ", eyeShape=" + eyeShape + - ", eyePosition=" + eyePosition + - ", mouthShape=" + mouthShape + - ", color=" + color + - ", sticker=" + sticker + - ", name='" + name + '\'' + - ", expectation='" + expectation + '\'' + - ", createdAt='" + getCreatedAt() + '\'' + - ", updatedAt='" + getUpdatedAt() + '\'' + - '}'; + public CasperBot(CasperBotRequestDto requestDto, String phoneNumber) { + this.phoneNumber = phoneNumber; + this.eyeShape = requestDto.getEyeShape(); + this.eyePosition = requestDto.getEyePosition(); + this.mouthShape = requestDto.getMouthShape(); + this.color = requestDto.getColor(); + this.sticker = requestDto.getSticker(); + this.name = requestDto.getName(); + this.expectation = requestDto.getExpectation(); } } 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 afc66aa8..927ba61b 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 @@ -45,10 +45,11 @@ public LotteryEventService(LotteryEventRepository lotteryEventRepository, this.userRepository = userRepository; } - public CasperBotResponseDto postCasperBot(BaseUser user, CasperBotRequestDto postCasperBot) throws CustomException { + public CasperBotResponseDto postCasperBot(BaseUser user, CasperBotRequestDto casperBotRequestDto) throws CustomException { LotteryParticipants participants = registerUserIfNeed(user); - CasperBot casperBot = casperBotRepository.save(new CasperBot(postCasperBot, participants.getBaseUser().getId())); + CasperBot casperBot = casperBotRepository.save(new CasperBot(casperBotRequestDto, user.getId())); + participants.updateCasperId(casperBot.getCasperId()); if (!casperBot.getExpectation().isEmpty()) participants.expectationAdded(); From 8345fd5c4d18255acf47f7dd1a37f8f270f45a70 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:03:50 +0900 Subject: [PATCH 085/289] =?UTF-8?q?feat:=20=EC=B6=94=EA=B0=80=EC=A0=81?= =?UTF-8?q?=EC=9D=B8=20=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=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 --- .../java/JGS/CasperEvent/global/enums/CustomErrorCode.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index 75378d38..b080ab8a 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -5,6 +5,7 @@ @Getter public enum CustomErrorCode { NO_RUSH_EVENT("선착순 이벤트를 찾을 수 없습니다.", 404), + NO_RUSH_EVENT_OPTION("해당 밸런스 게임 선택지를 찾을 수 없습니다.", 404), INVALID_CASPERBOT_PARAMETER("잘못된 파라미터 입력입니다.", 400), CASPERBOT_NOT_FOUND("배지를 찾을 수 없습니다.", 404), BAD_REQUEST("잘못된 요청입니다.", 400), @@ -16,7 +17,9 @@ public enum CustomErrorCode { JWT_EXPIRED("만료된 토큰입니다.", 400), JWT_MISSING("인증 토큰이 존재하지 않습니다.", 401), MULTIPLE_RUSH_EVENTS_FOUND("해당 날짜에 여러 개의 이벤트가 존재합니다.", 409), - TODAY_RUSH_EVENT_NOT_FOUND("오늘의 이벤트를 찾을 수 없습니다.", 404); // 새로운 예외 추가 + TODAY_RUSH_EVENT_NOT_FOUND("오늘의 이벤트를 찾을 수 없습니다.", 404), + INVALID_RUSH_EVENT_OPTIONS_COUNT("이벤트의 옵션 수가 올바르지 않습니다.", 500), + INVALID_RUSH_EVENT_OPTION_ID("옵션 ID는 1 또는 2여야 합니다.", 400); private final String message; private int status; From c023b802c9b737b10a224f39c85ddeaedf143de3 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:04:28 +0900 Subject: [PATCH 086/289] =?UTF-8?q?feat:=20=EB=A9=94=EC=9D=B8=20=EC=84=A0?= =?UTF-8?q?=ED=83=9D=EC=A7=80=EC=9D=98=20=ED=85=8D=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=A5=BC=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20Dto=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ResponseDto/MainRushEventOptionResponseDto.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventOptionResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventOptionResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventOptionResponseDto.java new file mode 100644 index 00000000..7a730c27 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventOptionResponseDto.java @@ -0,0 +1,12 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto; + +public record MainRushEventOptionResponseDto(String mainText, + String subText) { + + public static MainRushEventOptionResponseDto of(RushEventOptionResponseDto rushEventOptionResponseDto) { + return new MainRushEventOptionResponseDto( + rushEventOptionResponseDto.mainText(), + rushEventOptionResponseDto.subText() + ); + } +} From cf9db0067c6d89159af18f761bb3f0169493f4f6 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:05:11 +0900 Subject: [PATCH 087/289] =?UTF-8?q?feat:=20left,=20right=20=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=B4=20=EC=84=A0=ED=83=9D=EC=A7=80=20=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=ED=85=8D=EC=8A=A4=ED=8A=B8=EB=A5=BC=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=ED=95=98=EB=8A=94=20Dto=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ResponseDto/MainRushEventOptionsResponseDto.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventOptionsResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventOptionsResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventOptionsResponseDto.java new file mode 100644 index 00000000..c0230be9 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventOptionsResponseDto.java @@ -0,0 +1,11 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto; + + +public record MainRushEventOptionsResponseDto(MainRushEventOptionResponseDto leftOption, + MainRushEventOptionResponseDto rightOption) { + + public MainRushEventOptionsResponseDto(MainRushEventOptionResponseDto leftOption, MainRushEventOptionResponseDto rightOption) { + this.leftOption = leftOption; + this.rightOption = rightOption; + } +} From e467f96bb32bcc034137169a4f138b75f98e0f78 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:05:37 +0900 Subject: [PATCH 088/289] =?UTF-8?q?feat:=20=EC=99=BC=EC=AA=BD,=20=EC=98=A4?= =?UTF-8?q?=EB=A5=B8=EC=AA=BD=20=EC=84=A0=ED=83=9D=EC=A7=80=EB=A5=BC=20?= =?UTF-8?q?=EB=8B=B4=EB=8A=94=20Enum=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/global/enums/Position.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/enums/Position.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/Position.java b/Server/src/main/java/JGS/CasperEvent/global/enums/Position.java new file mode 100644 index 00000000..25c7a205 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/Position.java @@ -0,0 +1,26 @@ +package JGS.CasperEvent.global.enums; + +import JGS.CasperEvent.global.error.exception.CustomException; +import lombok.Getter; + +@Getter +public enum Position { + LEFT(1), + RIGHT(2); + + private final int position; + + Position(int position) { + this.position = position; + } + + public static Position of(int position) { + for (Position pos : Position.values()) { + if (pos.getPosition() == position) { + return pos; + } + } + + throw new CustomException("optionId는 1 또는 2여야 합니다.", CustomErrorCode.INVALID_RUSH_EVENT_OPTION_ID); + } +} From 75267515add192c88f7bd16aba9eb8351bed007d Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:06:36 +0900 Subject: [PATCH 089/289] =?UTF-8?q?feat:=20Redis=EC=97=90=20RushEvent?= =?UTF-8?q?=EB=A5=BC=20=EB=84=A3=EC=9D=84=20=EB=95=8C=20=ED=94=84=EB=A1=9D?= =?UTF-8?q?=EC=8B=9C=20=EA=B0=9D=EC=B2=B4=EC=9D=B8=20Entity=EB=A5=BC=20?= =?UTF-8?q?=EC=A7=81=EC=A0=91=20=EB=84=A3=EB=8A=94=20=EA=B2=8C=20=EC=95=84?= =?UTF-8?q?=EB=8B=8C=20Entity=EB=A5=BC=20=EB=84=A3=EB=8F=84=EB=A1=9D=20Red?= =?UTF-8?q?isTemplate=20=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/global/config/RedisConfig.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/config/RedisConfig.java b/Server/src/main/java/JGS/CasperEvent/global/config/RedisConfig.java index f397261c..3862295c 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/config/RedisConfig.java +++ b/Server/src/main/java/JGS/CasperEvent/global/config/RedisConfig.java @@ -1,7 +1,7 @@ package JGS.CasperEvent.global.config; import JGS.CasperEvent.domain.event.dto.ResponseDto.CasperBotResponseDto; -import JGS.CasperEvent.domain.event.entity.event.RushEvent; +import JGS.CasperEvent.domain.event.dto.ResponseDto.RushEventResponseDto; import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; @@ -39,8 +39,8 @@ public RedisTemplate CasperBotRedisTemplate(){ } @Bean - public RedisTemplate RushEventRedisTemplate(){ - RedisTemplate redisTemplate = new RedisTemplate<>(); + public RedisTemplate RushEventRedisTemplate(){ + RedisTemplate redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(redisConnectionFactory()); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); From 2b9a056209fb64429e6897d1079f63547bc6d94c Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:06:53 +0900 Subject: [PATCH 090/289] =?UTF-8?q?feat:=20=EC=84=A0=ED=83=9D=EC=A7=80=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EC=A1=B0=ED=9A=8C=20Dto=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ResponseDto/ResultRushEventOptionResponseDto.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/ResultRushEventOptionResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/ResultRushEventOptionResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/ResultRushEventOptionResponseDto.java new file mode 100644 index 00000000..3cc2b6a2 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/ResultRushEventOptionResponseDto.java @@ -0,0 +1,11 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto; + +public record ResultRushEventOptionResponseDto(String mainText, String resultMainText, String resultSubText) { + public static ResultRushEventOptionResponseDto of(RushEventOptionResponseDto rushEventOptionResponseDto) { + return new ResultRushEventOptionResponseDto( + rushEventOptionResponseDto.mainText(), + rushEventOptionResponseDto.resultMainText(), + rushEventOptionResponseDto.resultSubText() + ); + } +} From 1fbb482eabfe4949075d8e5fdfdf6b1c56cef8a7 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:07:46 +0900 Subject: [PATCH 091/289] =?UTF-8?q?feat:=20=EC=88=9C=ED=99=98=20=EC=B0=B8?= =?UTF-8?q?=EC=A1=B0=EB=A5=BC=20=EB=B0=A9=EC=A7=80=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4=20=EC=95=A0=EB=85=B8=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/event/RushEvent.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java index 07ba336b..47481951 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java @@ -1,10 +1,12 @@ package JGS.CasperEvent.domain.event.entity.event; import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; +import com.fasterxml.jackson.annotation.JsonManagedReference; import jakarta.persistence.*; import lombok.Getter; import java.time.LocalDateTime; +import java.util.HashSet; import java.util.Set; @Entity @@ -17,11 +19,11 @@ public class RushEvent extends BaseEvent { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long rushEventId; - @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "rush_event_id") - private Set options; + @OneToMany(fetch = FetchType.EAGER, mappedBy = "rushEvent", cascade = CascadeType.ALL, orphanRemoval = true) + @JsonManagedReference + private final Set options = new HashSet<>(); - @OneToMany(mappedBy = "rushEvent", cascade = CascadeType.ALL, orphanRemoval = true) + @OneToMany(fetch = FetchType.EAGER, mappedBy = "rushEvent", cascade = CascadeType.ALL, orphanRemoval = true) private Set rushParticipants; public RushEvent() { From 483683e41e28b1e51e8852603bf0f49497bf2d63 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:08:31 +0900 Subject: [PATCH 092/289] =?UTF-8?q?fix:=20=EB=AA=A8=EB=93=A0=20=EC=84=A0?= =?UTF-8?q?=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=B4=20eventId=EB=A5=BC=20PathVariable=20?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventController/RushEventController.java | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java index a0b7790b..cc15be6f 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java @@ -1,9 +1,7 @@ package JGS.CasperEvent.domain.event.controller.eventController; -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.dto.ResponseDto.*; import JGS.CasperEvent.domain.event.service.eventService.RushEventService; import JGS.CasperEvent.global.entity.BaseUser; import jakarta.servlet.http.HttpServletRequest; @@ -26,34 +24,34 @@ public ResponseEntity getRushEventListAndServerTime() } // 밸런스 게임 참여 여부 조회 - @GetMapping("/{eventId}/applied") - public ResponseEntity checkUserParticipationInRushEvent(HttpServletRequest httpServletRequest, @PathVariable("eventId") Long eventId) { - + @GetMapping("/applied") + public ResponseEntity checkUserParticipationInRushEvent(HttpServletRequest httpServletRequest) { BaseUser user = (BaseUser) httpServletRequest.getAttribute("user"); - return ResponseEntity.ok(rushEventService.isExists(eventId, user.getId())); + return ResponseEntity.ok(rushEventService.isExists(user.getId())); } // 밸런스 게임 응모 - @PostMapping("/{eventId}/options/{optionId}/apply") - public ResponseEntity applyRushEvent(HttpServletRequest httpServletRequest, @PathVariable("eventId") Long eventId, @PathVariable("optionId") int optionId) { + @PostMapping("/options/{optionId}/apply") + public ResponseEntity applyRushEvent(HttpServletRequest httpServletRequest, @PathVariable("optionId") int optionId) { BaseUser user = (BaseUser) httpServletRequest.getAttribute("user"); - rushEventService.apply(user, eventId, optionId); + rushEventService.apply(user, optionId); return ResponseEntity.noContent().build(); } // 밸런스 게임 비율 조회 - @GetMapping("/{eventId}/balance") - public ResponseEntity rushEventRate (@PathVariable("eventId") Long eventId) { - RushEventRateResponseDto rushEventRateResponseDto = rushEventService.getRushEventRate(eventId); + @GetMapping("/balance") + public ResponseEntity rushEventRate(HttpServletRequest httpServletRequest) { + BaseUser user = (BaseUser) httpServletRequest.getAttribute("user"); + RushEventRateResponseDto rushEventRateResponseDto = rushEventService.getRushEventRate(user); return ResponseEntity.ok(rushEventRateResponseDto); } // 밸런스 게임 결과 조회 - @GetMapping("/{eventId}/result") - public ResponseEntity rushEventResult(HttpServletRequest httpServletRequest, @PathVariable("eventId") Long eventId) { + @GetMapping("/result") + public ResponseEntity rushEventResult(HttpServletRequest httpServletRequest) { BaseUser user = (BaseUser) httpServletRequest.getAttribute("user"); - RushEventResultResponseDto result = rushEventService.getRushEventResult(user, eventId); + RushEventResultResponseDto result = rushEventService.getRushEventResult(user); return ResponseEntity.ok(result); } @@ -63,4 +61,18 @@ public ResponseEntity setTodayEvent() { rushEventService.setTodayEventToRedis(); return ResponseEntity.noContent().build(); } + + // 오늘의 이벤트 선택지 조회 + @GetMapping("/today") + public ResponseEntity getTodayEvent() { + MainRushEventOptionsResponseDto mainRushEventOptionsResponseDto = rushEventService.getTodayRushEventOptions(); + return ResponseEntity.ok(mainRushEventOptionsResponseDto); + } + + // 옵션 선택 결과 조회 + @GetMapping("/options/{optionId}/result") + public ResponseEntity getResultOption(@PathVariable("optionId") int optionId) { + ResultRushEventOptionResponseDto resultRushEventOptionResponseDto = rushEventService.getRushEventOptionResult(optionId); + return ResponseEntity.ok(resultRushEventOptionResponseDto); + } } From fe00a2d714d306b68d5cd2731f0880f51711b37d Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:09:13 +0900 Subject: [PATCH 093/289] =?UTF-8?q?feat:=20Redis=EC=97=90=20=EB=84=A3?= =?UTF-8?q?=EC=9D=84=20=EB=95=8C=20RushOption=20Entity=20=EB=8C=80?= =?UTF-8?q?=EC=8B=A0=20=EB=84=A3=EC=9D=84=20Dto=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ResponseDto/RushEventOptionResponseDto.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventOptionResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventOptionResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventOptionResponseDto.java new file mode 100644 index 00000000..3d786ff7 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventOptionResponseDto.java @@ -0,0 +1,17 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto; + +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) { + public static RushEventOptionResponseDto of(RushOption rushOption) { + return new RushEventOptionResponseDto( + rushOption.getMainText(), + rushOption.getSubText(), + rushOption.getResultMainText(), + rushOption.getResultSubText(), + rushOption.getImageUrl(), + rushOption.getPosition() + ); + } +} From 76ab3b759aa2ea3017550dc4f26d2ee6a4d1c360 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:09:39 +0900 Subject: [PATCH 094/289] =?UTF-8?q?fix:=20=EB=B9=84=EC=9C=A8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EC=97=90=20=EB=B0=98=ED=99=98=20=EA=B0=92?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20optionId=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/dto/ResponseDto/RushEventRateResponseDto.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java index a4b81c45..d54e4bdc 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java @@ -1,7 +1,4 @@ package JGS.CasperEvent.domain.event.dto.ResponseDto; -import lombok.Getter; - -@Getter -public record RushEventRateResponseDto(long leftOption, long rightOption) { +public record RushEventRateResponseDto(int optionId, long leftOption, long rightOption) { } From 9db4e668da798f2caadeb88aec3246ddb07a8d1a Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:10:32 +0900 Subject: [PATCH 095/289] =?UTF-8?q?fix:=20RushOption=20=EB=8C=80=EC=8B=A0?= =?UTF-8?q?=20RushEventOptionResponseDto=EB=A5=BC=20=EA=B0=80=EC=A7=80?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20LocalDate?= =?UTF-8?q?Time=20=EC=A7=81=EB=A0=AC=ED=99=94=20=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=A7=80=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/ResponseDto/RushEventResponseDto.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java index 923f30d6..a0d45131 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java @@ -2,16 +2,34 @@ import JGS.CasperEvent.domain.event.entity.event.RushEvent; import JGS.CasperEvent.domain.event.entity.event.RushOption; +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 java.time.LocalDate; import java.time.LocalDateTime; import java.util.Set; +import java.util.stream.Collectors; -public record RushEventResponseDto(Long rushEventId, LocalDateTime startDateTime, LocalDateTime endDateTime, - int winnerCount, String prizeImageUrl, String prizeDescription, - Set options){ +public record RushEventResponseDto(Long rushEventId, + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonDeserialize(using = LocalDateTimeDeserializer.class) + + LocalDateTime startDateTime, + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonDeserialize(using = LocalDateTimeDeserializer.class) + + LocalDateTime endDateTime, + int winnerCount, String prizeImageUrl, + String prizeDescription, + Set options){ public static RushEventResponseDto of (RushEvent rushEvent){ + Set options = rushEvent.getOptions().stream() + .map(RushEventOptionResponseDto::of) + .collect(Collectors.toSet()); + return new RushEventResponseDto( rushEvent.getRushEventId(), rushEvent.getStartDateTime(), @@ -19,8 +37,7 @@ public static RushEventResponseDto of (RushEvent rushEvent){ rushEvent.getWinnerCount(), rushEvent.getPrizeImageUrl(), rushEvent.getPrizeDescription(), - rushEvent.getOptions() + options ); } - } From b033c29ea512215e0602060582ceaae5a6e4e0f9 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:11:11 +0900 Subject: [PATCH 096/289] =?UTF-8?q?fix:=20RedisTemplate=EC=9D=98=20RushEve?= =?UTF-8?q?nt=20=ED=83=80=EC=9E=85=20->=20RushEventResponseDto=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/eventService/RushEventScheduler.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventScheduler.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventScheduler.java index 9d91e79c..b4eca6ab 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventScheduler.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventScheduler.java @@ -1,5 +1,6 @@ package JGS.CasperEvent.domain.event.service.eventService; +import JGS.CasperEvent.domain.event.dto.ResponseDto.RushEventResponseDto; import JGS.CasperEvent.domain.event.entity.event.RushEvent; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; @@ -15,7 +16,7 @@ public class RushEventScheduler { private final RushEventService rushEventService; - private final RedisTemplate rushEventRedisTemplate; + private final RedisTemplate rushEventRedisTemplate; // 매일 12시에 스케줄된 작업을 실행합니다. @Scheduled(cron = "0 0 12 * * ?") @@ -24,7 +25,7 @@ public void fetchDailyEvents() { LocalDate today = LocalDate.now(); // EventService를 통해 오늘의 이벤트를 가져옵니다. - RushEvent todayEvent = rushEventService.getTodayRushEvent(today); + RushEventResponseDto todayEvent = rushEventService.getTodayRushEvent(today); // 가져온 이벤트에 대한 추가 작업을 수행합니다. // 예: 캐싱, 로그 기록, 알림 발송 등 From f2832938335ee35b83e6e2dfdbb1647b322f57eb Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:12:13 +0900 Subject: [PATCH 097/289] =?UTF-8?q?fix:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=84=A0=ED=83=9D=EC=A7=80=20=EC=A0=95=EB=B3=B4=20=EB=B0=98?= =?UTF-8?q?=ED=99=98,=20=EC=84=A0=ED=83=9D=EC=A7=80=20=EA=B2=B0=EA=B3=BC?= =?UTF-8?q?=20=ED=85=8D=EC=8A=A4=ED=8A=B8=20=EB=B0=98=ED=99=98=20=EB=B9=84?= =?UTF-8?q?=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EB=B0=8F=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventService/RushEventService.java | 141 +++++++++++++----- 1 file changed, 105 insertions(+), 36 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java index 26fb59b8..9dbe627c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java @@ -9,6 +9,7 @@ import JGS.CasperEvent.domain.event.repository.participantsRepository.RushParticipantsRepository; import JGS.CasperEvent.global.entity.BaseUser; import JGS.CasperEvent.global.enums.CustomErrorCode; +import JGS.CasperEvent.global.enums.Position; import JGS.CasperEvent.global.error.exception.CustomException; import JGS.CasperEvent.global.util.RepositoryErrorHandler; import lombok.RequiredArgsConstructor; @@ -21,19 +22,20 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.Set; @Service @RequiredArgsConstructor public class RushEventService { private final RushEventRepository rushEventRepository; private final RushParticipantsRepository rushParticipantsRepository; - private final RedisTemplate rushEventRedisTemplate; + private final RedisTemplate rushEventRedisTemplate; private final RushOptionRepository rushOptionRepository; @Transactional public RushEventListResponseDto getAllRushEvents() { // 오늘의 선착순 이벤트 꺼내오기 - RushEvent todayEvent = rushEventRedisTemplate.opsForValue().get("todayEvent"); + RushEventResponseDto todayEvent = rushEventRedisTemplate.opsForValue().get("todayEvent"); // 오늘의 선착순 이벤트가 redis에 등록되지 않은 경우 if (todayEvent == null) { @@ -61,7 +63,7 @@ public RushEventListResponseDto getAllRushEvents() { return new RushEventListResponseDto( mainRushEventDtoList, LocalDateTime.now(), - todayEvent.getRushEventId(), + todayEvent.rushEventId(), totalStartDate, totalEndDate, activePeriod @@ -69,62 +71,67 @@ public RushEventListResponseDto getAllRushEvents() { } // 응모 여부 조회 - public boolean isExists(Long eventId, String userId) { - return rushParticipantsRepository.existsByRushEvent_RushEventIdAndBaseUser_Id(eventId, userId); + public boolean isExists(String userId) { + Long todayEventId = getTodayRushEvent().rushEventId(); + return rushParticipantsRepository.existsByRushEvent_RushEventIdAndBaseUser_Id(todayEventId, userId); } @Transactional - public void apply(BaseUser user, Long eventId, int optionId) { + public void apply(BaseUser user, int optionId) { + Long todayEventId = getTodayRushEvent().rushEventId(); + // 이미 응모한 회원인지 검증 - if (rushParticipantsRepository.existsByRushEvent_RushEventIdAndBaseUser_Id(eventId, user.getId())) { + if (rushParticipantsRepository.existsByRushEvent_RushEventIdAndBaseUser_Id(todayEventId, user.getId())) { throw new CustomException("이미 응모한 회원입니다.", CustomErrorCode.CONFLICT); } // eventId 를 이용하여 rushEvent 를 꺼냄 - RushEvent rushEvent = RepositoryErrorHandler.findByIdOrElseThrow(rushEventRepository, eventId, CustomErrorCode.NO_RUSH_EVENT); + RushEvent rushEvent = RepositoryErrorHandler.findByIdOrElseThrow(rushEventRepository, todayEventId, CustomErrorCode.NO_RUSH_EVENT); // 새로운 RushParticipants 를 생성하여 DB 에 저장 RushParticipants rushParticipants = new RushParticipants(user, rushEvent, optionId); rushParticipantsRepository.save(rushParticipants); } - public RushEventRateResponseDto getRushEventRate(Long eventId) { - long leftOptionCount = rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(eventId, 1); - long rightOptionCount = rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(eventId, 2); + // 진행중인 게임의 응모 비율 반환 + public RushEventRateResponseDto getRushEventRate(BaseUser user) { + Long todayEventId = getTodayRushEvent().rushEventId(); + Optional optionId = rushParticipantsRepository.getOptionIdByUserId(user.getId()); + long leftOptionCount = rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(todayEventId, 1); + long rightOptionCount = rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(todayEventId, 2); - return new RushEventRateResponseDto(leftOptionCount, rightOptionCount); + return new RushEventRateResponseDto( + optionId.orElseThrow(() -> new CustomException("유저가 응모한 선택지가 존재하지 않습니다.", CustomErrorCode.USER_NOT_FOUND)), + leftOptionCount, rightOptionCount); } // 이벤트 결과를 반환 // 해당 요청은 무조건 응모한 유저일 때만 요청 가능하다고 가정 @Transactional - public RushEventResultResponseDto getRushEventResult(BaseUser user, Long eventId) { + public RushEventResultResponseDto getRushEventResult(BaseUser user) { + Long todayEventId = getTodayRushEvent().rushEventId(); + // 최종 선택 비율을 조회 // TODO: 레디스에 캐시 - RushEventRateResponseDto rushEventRateResponseDto = getRushEventRate(eventId); + RushEventRateResponseDto rushEventRateResponseDto = getRushEventRate(user); // 해당 이벤트의 당첨자 수를 가져옴 - int winnerCount = rushEventRepository.findByRushEventId(eventId).getWinnerCount(); + int winnerCount = rushEventRepository.findByRushEventId(todayEventId).getWinnerCount(); - // 해당 유저가 응모한 optionId 가져옴 - Optional optionId = rushParticipantsRepository.getOptionIdByUserId(user.getId()); - - if (optionId.isEmpty()) { - throw new CustomException("해당 유저가 이벤트 응모를 하지 않았습니다.", CustomErrorCode.USER_NOT_FOUND); - } + int optionId = rushEventRateResponseDto.optionId(); // eventId, userId, optionId 를 이용하여 해당 유저가 응모한 선택지에서 등수를 가져옴 - long rank = rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(eventId, user.getId(), optionId.get()); + long rank = rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(todayEventId, user.getId(), optionId); // 해당 선택지를 선택한 모든 유저 수를 가져옴 - long totalParticipants = rushParticipantsRepository.countAllByOptionId(optionId.get()); + long totalParticipants = rushParticipantsRepository.countAllByOptionId(optionId); - return new RushEventResultResponseDto(rushEventRateResponseDto.getLeftOption(), rushEventRateResponseDto.rightOption(), rank, totalParticipants, winnerCount); + return new RushEventResultResponseDto(rushEventRateResponseDto, rank, totalParticipants, winnerCount); } @Transactional // 오늘의 이벤트를 DB에 꺼내서 반환 - public RushEvent getTodayRushEvent(LocalDate today) { + public RushEventResponseDto getTodayRushEvent(LocalDate today) { // 오늘 날짜에 해당하는 모든 이벤트 꺼내옴 List rushEventList = rushEventRepository.findByEventDate(today); @@ -136,7 +143,17 @@ public RushEvent getTodayRushEvent(LocalDate today) { throw new CustomException("선착순 이벤트가 존재하지않습니다.", CustomErrorCode.MULTIPLE_RUSH_EVENTS_FOUND); } - return rushEventList.get(0); + return RushEventResponseDto.of(rushEventList.get(0)); + } + + // 오늘의 이벤트 꺼내오기 + private RushEventResponseDto getTodayRushEvent() { + RushEventResponseDto todayEvent = rushEventRedisTemplate.opsForValue().get("todayEvent"); + if (todayEvent == null) { + throw new CustomException("오늘의 이벤트가 Redis에 없습니다.", CustomErrorCode.TODAY_RUSH_EVENT_NOT_FOUND); + } + + return todayEvent; } @Transactional @@ -161,34 +178,86 @@ public void setTodayEventToRedis() { "Prize Description " + (i + 1) // 상 설명 ); - // RushEvent 저장 - rushEvent = rushEventRepository.save(rushEvent); - rushEvents.add(rushEvent); - - // 첫 번째 RushOption 생성 및 저장 + // RushOption 생성 RushOption option1 = new RushOption( rushEvent, "Option 1 Main Text for Event " + (i + 1), "Option 1 Sub Text for Event " + (i + 1), "Option 1 Result Main Text for Event " + (i + 1), "Option 1 Result Sub Text for Event " + (i + 1), - "http://example.com/option1-image" + (i + 1) + ".jpg" + "http://example.com/option1-image" + (i + 1) + ".jpg", + Position.LEFT ); - rushOptionRepository.save(option1); - // 두 번째 RushOption 생성 및 저장 RushOption option2 = new RushOption( rushEvent, "Option 2 Main Text for Event " + (i + 1), "Option 2 Sub Text for Event " + (i + 1), "Option 2 Result Main Text for Event " + (i + 1), "Option 2 Result Sub Text for Event " + (i + 1), - "http://example.com/option2-image" + (i + 1) + ".jpg" + "http://example.com/option2-image" + (i + 1) + ".jpg", + Position.RIGHT ); + + // RushEvent의 options 컬렉션에 추가 + rushEvent.getOptions().add(option1); + rushEvent.getOptions().add(option2); + + // RushEvent 및 RushOption 저장 + rushEvent = rushEventRepository.save(rushEvent); + rushOptionRepository.save(option1); rushOptionRepository.save(option2); + + rushEvents.add(rushEvent); } // 처음으로 생성된 RushEvent를 Redis에 저장 - rushEventRedisTemplate.opsForValue().set("todayEvent", rushEvents.get(0)); + rushEventRedisTemplate.opsForValue().set("todayEvent", RushEventResponseDto.of(rushEvents.get(0))); + } + + // 오늘의 이벤트 옵션 정보를 반환 + public MainRushEventOptionsResponseDto getTodayRushEventOptions() { + RushEventResponseDto todayEvent = getTodayRushEvent(); + Set options = todayEvent.options(); + + if (options.size() != 2) { + throw new CustomException("해당 이벤트의 선택지가 2개가 아닙니다.", CustomErrorCode.INVALID_RUSH_EVENT_OPTIONS_COUNT); + } + + RushEventOptionResponseDto leftOption = options.stream() + .filter(option -> option.position() == Position.LEFT) + .findFirst() + .orElseThrow(() -> new CustomException("왼쪽 선택지가 존재하지 않습니다.", CustomErrorCode.INVALID_RUSH_EVENT_OPTIONS_COUNT)); + + RushEventOptionResponseDto rightOption = options.stream() + .filter(option -> option.position() == Position.RIGHT) + .findFirst() + .orElseThrow(() -> new CustomException("오른쪽 선택지가 존재하지 않습니다.", CustomErrorCode.INVALID_RUSH_EVENT_OPTIONS_COUNT)); + + return new MainRushEventOptionsResponseDto( + MainRushEventOptionResponseDto.of(leftOption), + MainRushEventOptionResponseDto.of(rightOption) + ); + } + + public ResultRushEventOptionResponseDto getRushEventOptionResult(int optionId) { + Position position = Position.of(optionId); + RushEventResponseDto todayEvent = getTodayRushEvent(); + Set options = todayEvent.options(); + + if (options.size() != 2) { + throw new CustomException("해당 이벤트의 선택지가 2개가 아닙니다.", CustomErrorCode.INVALID_RUSH_EVENT_OPTIONS_COUNT); + } + + RushEventOptionResponseDto selectedOption = options.stream() + .filter(option -> option.position() == position) + .findFirst() + .orElseThrow(() -> new CustomException("사용자가 선택한 선택지가 존재하지 않습니다.", CustomErrorCode.NO_RUSH_EVENT_OPTION)); + + return new ResultRushEventOptionResponseDto( + selectedOption.mainText(), + selectedOption.resultMainText(), + selectedOption.resultSubText() + ); } } From e9a4eeadd21415f4ae48090953b403be3f3d48ff Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:12:54 +0900 Subject: [PATCH 098/289] =?UTF-8?q?fix:=20Json=20=EC=A7=81=EB=A0=AC?= =?UTF-8?q?=ED=99=94=20=EC=8B=9C=20=EC=88=9C=ED=99=98=20=EC=B0=B8=EC=A1=B0?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=EB=A5=BC=20=EB=A7=89=EA=B8=B0=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20=EC=95=A0=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80,=20=EC=99=BC=EC=AA=BD=20=EC=84=A0=ED=83=9D?= =?UTF-8?q?=EC=A7=80,=20=EC=98=A4=EB=A5=B8=EC=AA=BD=20=EC=84=A0=ED=83=9D?= =?UTF-8?q?=EC=A7=80=EB=A5=BC=20=EA=B5=AC=EB=B6=84=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20Position=20Enum=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=EC=9D=84=20=EA=B0=96=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/event/RushOption.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java index 7d0726ba..08470d02 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java @@ -1,10 +1,14 @@ package JGS.CasperEvent.domain.event.entity.event; import JGS.CasperEvent.global.entity.BaseEntity; +import JGS.CasperEvent.global.enums.Position; +import com.fasterxml.jackson.annotation.JsonBackReference; import jakarta.persistence.*; +import lombok.Getter; import lombok.NoArgsConstructor; @Entity +@Getter @NoArgsConstructor public class RushOption extends BaseEntity { @Id @@ -13,6 +17,7 @@ public class RushOption extends BaseEntity { @ManyToOne @JoinColumn(name = "rush_event_id") + @JsonBackReference private RushEvent rushEvent; private String mainText; private String subText; @@ -20,12 +25,16 @@ public class RushOption extends BaseEntity { private String resultSubText; private String imageUrl; - public RushOption(RushEvent rushEvent, String mainText, String subText, String resultMainText, String resultSubText, String imageUrl) { + @Enumerated(EnumType.STRING) + private Position position; + + public RushOption(RushEvent rushEvent, String mainText, String subText, String resultMainText, String resultSubText, String imageUrl, Position position) { this.rushEvent = rushEvent; this.mainText = mainText; this.subText = subText; this.resultMainText = resultMainText; this.resultSubText = resultSubText; this.imageUrl = imageUrl; + this.position = position; } } From fac33c85a9b8cb2140b30765656b3286c2b0d181 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 00:17:23 +0900 Subject: [PATCH 099/289] =?UTF-8?q?feat:=20TooManyLotteryEventException=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/error/exception/TooManyLotteryEventException.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/error/exception/TooManyLotteryEventException.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/exception/TooManyLotteryEventException.java b/Server/src/main/java/JGS/CasperEvent/global/error/exception/TooManyLotteryEventException.java new file mode 100644 index 00000000..94c742cc --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/error/exception/TooManyLotteryEventException.java @@ -0,0 +1,5 @@ +package JGS.CasperEvent.global.error.exception; + +public class TooManyLotteryEventException extends RuntimeException { + +} From fd9790dc66dd77ad8ca9bf62f088421984d52ca5 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 00:17:41 +0900 Subject: [PATCH 100/289] =?UTF-8?q?feat:=20TooManyLotteryEventException=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=ED=95=B8=EB=93=A4=EB=9F=AC=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/global/enums/CustomErrorCode.java | 3 ++- .../global/error/GlobalExceptionHandler.java | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index ae109d03..b31a4a65 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -14,7 +14,8 @@ public enum CustomErrorCode { JWT_PARSE_EXCEPTION("Json 파싱 오류입니다.", 400), JWT_EXCEPTION("JWT 오류입니다.", 400), JWT_EXPIRED("만료된 토큰입니다.", 400), - JWT_MISSING("인증 토큰이 존재하지 않습니다.", 401); + JWT_MISSING("인증 토큰이 존재하지 않습니다.", 401), + LOTTERYEVENT_ALREADY_EXISTS("이미 추첨 이벤트가 존재합니다.", 409); diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java index f0e00657..58200340 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java +++ b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java @@ -2,6 +2,7 @@ import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.error.exception.CustomException; +import JGS.CasperEvent.global.error.exception.TooManyLotteryEventException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.BindingResult; @@ -33,10 +34,17 @@ public ResponseEntity missingCookieHandler(){ @ExceptionHandler(UserPrincipalNotFoundException.class) public ResponseEntity userPrincipalNotFoundHandler(){ return ResponseEntity - .status(HttpStatus.NOT_FOUND) + .status(HttpStatus.CONFLICT) .body(ErrorResponse.of(CustomErrorCode.USER_NOT_FOUND)); } + @ExceptionHandler(TooManyLotteryEventException.class) + public ResponseEntity tooManyLotteryEventExceptionHandler(){ + return ResponseEntity + .status(HttpStatus.NOT_FOUND) + .body(ErrorResponse.of(CustomErrorCode.LOTTERYEVENT_ALREADY_EXISTS)); + } + @ExceptionHandler(MethodArgumentNotValidException.class) public ResponseEntity methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e){ BindingResult bindingResult = e.getBindingResult(); From c711fe9e1b3c3a265aee2a2c13ced253c4fe1649 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 00:18:40 +0900 Subject: [PATCH 101/289] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EB=90=9C=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=EA=B0=80=20=EC=A1=B4=EC=9E=AC=ED=95=A0=20=EC=8B=9C=20?= =?UTF-8?q?TooManyLotteryEventException=20=EC=98=88=EC=99=B8=20=EB=B0=98?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/service/adminService/AdminService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 466f7b5c..583fe639 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -11,6 +11,7 @@ import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.Role; import JGS.CasperEvent.global.error.exception.CustomException; +import JGS.CasperEvent.global.error.exception.TooManyLotteryEventException; import JGS.CasperEvent.global.response.ResponseDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -44,6 +45,7 @@ public ResponseDto postAdmin(AdminRequestDto adminRequestDto) { } public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lotteryEventRequestDto) { + if(lotteryEventRepository.count() >= 1) throw new TooManyLotteryEventException(); LotteryEvent lotteryEvent = lotteryEventRepository.save(new LotteryEvent( lotteryEventRequestDto.getEventStartDate(), lotteryEventRequestDto.getEventEndDate(), From b71d4081bffa2cc633b7a1fbf0574dac04302365 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:30:02 +0900 Subject: [PATCH 102/289] =?UTF-8?q?fix:=20BaseEvent=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=EB=A5=BC=20private=20->=20protected=20=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/domain/event/entity/event/BaseEvent.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java index 491c8b9e..fa2e1a55 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java @@ -15,12 +15,12 @@ public class BaseEvent extends BaseEntity { @JsonSerialize(using = LocalDateTimeSerializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class) - private LocalDateTime startDateTime; + protected LocalDateTime startDateTime; @JsonSerialize(using = LocalDateTimeSerializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class) - private LocalDateTime endDateTime; - private int winnerCount; + protected LocalDateTime endDateTime; + protected int winnerCount; // 기본 생성자에서 디폴트 값 설정 public BaseEvent() { From ebf2d118438a6121ce980108aa3e880cd732196f Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 00:42:56 +0900 Subject: [PATCH 103/289] =?UTF-8?q?fix:=20LotteryEvent=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/dto/RequestDto/LotteryEventRequestDto.java | 4 ++-- .../domain/event/entity/event/LotteryEvent.java | 7 +++---- .../domain/event/service/adminService/AdminService.java | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java index 59afda19..80e2ec11 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java @@ -9,10 +9,10 @@ public class LotteryEventRequestDto { @NotNull(message = "이벤트 시작 일자를 지정하세요.") - private LocalDateTime eventStartDate; + private LocalDateTime eventStartDateTime; @NotNull(message = "이벤트 종료 일자를 지정하세요.") - private LocalDateTime eventEndDate; + private LocalDateTime eventEndDateTime; @NotNull(message = "당첨인원 수를 지정하세요.") private int winnerCount; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java index 954adeb7..b950f2e0 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java @@ -12,13 +12,12 @@ public class LotteryEvent extends BaseEvent { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long lotteryEventId; - public LotteryEvent(LocalDateTime eventStartDate, LocalDateTime eventEndDate, int winnerCount){ - this.eventStartDate = eventStartDate; - this.eventEndDate = eventEndDate; + public LotteryEvent(LocalDateTime eventStartDateTime, LocalDateTime eventEndDateTime, int winnerCount){ + this.startDateTime = eventStartDateTime; + this.endDateTime = eventEndDateTime; this.winnerCount = winnerCount; } public LotteryEvent() { - } } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 466f7b5c..4f84b392 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -45,8 +45,8 @@ public ResponseDto postAdmin(AdminRequestDto adminRequestDto) { public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lotteryEventRequestDto) { LotteryEvent lotteryEvent = lotteryEventRepository.save(new LotteryEvent( - lotteryEventRequestDto.getEventStartDate(), - lotteryEventRequestDto.getEventEndDate(), + lotteryEventRequestDto.getEventStartDateTime(), + lotteryEventRequestDto.getEventEndDateTime(), lotteryEventRequestDto.getWinnerCount() )); From e7c218967d2ade4431f5ff238f30bccf4bdbbc53 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 10:53:26 +0900 Subject: [PATCH 104/289] =?UTF-8?q?feat:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/adminController/AdminController.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 81b318a6..531eac03 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -2,6 +2,7 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventDetailResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.global.response.ResponseDto; @@ -11,6 +12,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RestController @RequestMapping("/admin") public class AdminController { @@ -28,6 +31,13 @@ public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto .body(adminService.postAdmin(adminRequestDto)); } + @GetMapping("/event/lottery") + public ResponseEntity> getLotteryEvent() { + return ResponseEntity + .status(HttpStatus.OK) + .body(adminService.getLotteryEvent()); + } + @PostMapping("/event/lottery") public ResponseEntity createLotteryEvent( @Valid @RequestBody LotteryEventRequestDto lotteryEventRequestDto) { @@ -35,4 +45,5 @@ public ResponseEntity createLotteryEvent( .status(HttpStatus.CREATED) .body(adminService.createLotteryEvent(lotteryEventRequestDto)); } + } From 6278238b4913bf1db25ae41414ab116c512f5f9c Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 10:53:45 +0900 Subject: [PATCH 105/289] =?UTF-8?q?feat:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index e66fa193..2a57d239 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -1,21 +1,33 @@ package JGS.CasperEvent.domain.event.service.adminService; import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventDetailResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.entity.admin.Admin; +import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; import JGS.CasperEvent.domain.event.repository.AdminRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.Role; import JGS.CasperEvent.global.error.exception.CustomException; +import JGS.CasperEvent.global.error.exception.TooManyLotteryEventException; import JGS.CasperEvent.global.response.ResponseDto; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; +import java.util.List; import java.util.NoSuchElementException; @RequiredArgsConstructor @Service public class AdminService { + private final AdminRepository adminRepository; + private final LotteryEventRepository lotteryEventRepository; + private final RushEventRepository rushEventRepository; public Admin verifyAdmin(AdminRequestDto adminRequestDto) { return adminRepository.findById(adminRequestDto.getAdminId()).orElseThrow(NoSuchElementException::new); @@ -33,4 +45,22 @@ public ResponseDto postAdmin(AdminRequestDto adminRequestDto) { return ResponseDto.of("관리자 생성 성공"); } + + public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lotteryEventRequestDto) { + if(lotteryEventRepository.count() >= 1) throw new TooManyLotteryEventException(); + + LotteryEvent lotteryEvent = lotteryEventRepository.save(new LotteryEvent( + lotteryEventRequestDto.getEventStartDate(), + lotteryEventRequestDto.getEventEndDate(), + lotteryEventRequestDto.getWinnerCount() + )); + + return LotteryEventResponseDto.of(lotteryEvent, LocalDateTime.now()); + } + + public List getLotteryEvent() { + return LotteryEventDetailResponseDto.of( + lotteryEventRepository.findAll() + ); + } } From f1211db9f256773acaa8398b55092b287c379298 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 10:54:13 +0900 Subject: [PATCH 106/289] =?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=84=B8=EB=B6=80=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20DTO=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventDetailResponseDto.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventDetailResponseDto.java 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 new file mode 100644 index 00000000..ba6d9f7d --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventDetailResponseDto.java @@ -0,0 +1,26 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto; + +import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; + +import java.time.LocalDateTime; +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 static ArrayList of(List lotteryEvent) { + ArrayList lotteryEventDtoList = new ArrayList<>(); + for (LotteryEvent event : lotteryEvent) { + lotteryEventDtoList.add(new LotteryEventDetailResponseDto( + event.getStartDateTime(), + event.getEndDateTime(), + event.getAppliedCount(), + event.getWinnerCount(), + event.getCreatedAt(), + event.getUpdatedAt())); + } + return lotteryEventDtoList; + } +} From 0d361f6b3fa4be76163be293ed09ebd2829abbcb Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 10:54:32 +0900 Subject: [PATCH 107/289] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=EA=B0=80=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=EC=97=90=20=EC=A1=B4=EC=9E=AC?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9D=84=EB=95=8C=20LotteryEvent?= =?UTF-8?q?NotExists=20=EC=98=88=EC=99=B8=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/error/exception/LotteryEventNotExists.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/error/exception/LotteryEventNotExists.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/exception/LotteryEventNotExists.java b/Server/src/main/java/JGS/CasperEvent/global/error/exception/LotteryEventNotExists.java new file mode 100644 index 00000000..314b513d --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/error/exception/LotteryEventNotExists.java @@ -0,0 +1,4 @@ +package JGS.CasperEvent.global.error.exception; + +public class LotteryEventNotExists extends RuntimeException{ +} From 00a15bb056dd4b2938019a89ec2d270173befacd Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 10:55:02 +0900 Subject: [PATCH 108/289] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=EC=9D=98=20=EC=B4=9D=20=EC=B0=B8=EC=97=AC?= =?UTF-8?q?=EC=9E=90=20=EC=88=98=20=EA=B3=84=EC=82=B0=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/domain/event/entity/event/BaseEvent.java | 7 +++++++ .../event/service/eventService/LotteryEventService.java | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java index fa2e1a55..bd1828fd 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java @@ -9,6 +9,7 @@ import lombok.Getter; import java.time.LocalDateTime; +import java.util.concurrent.atomic.AtomicInteger; @Getter @MappedSuperclass @@ -21,12 +22,14 @@ public class BaseEvent extends BaseEntity { @JsonDeserialize(using = LocalDateTimeDeserializer.class) protected LocalDateTime endDateTime; protected int winnerCount; + protected AtomicInteger appliedCount; // 기본 생성자에서 디폴트 값 설정 public BaseEvent() { this.startDateTime = LocalDateTime.now(); this.endDateTime = LocalDateTime.now().plusMinutes(10); this.winnerCount = 0; // 기본 우승자 수를 0으로 설정 + this.appliedCount = new AtomicInteger(0); } // 특정 값을 설정할 수 있는 생성자 @@ -35,4 +38,8 @@ public BaseEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, int win this.endDateTime = endDateTime; this.winnerCount = winnerCount; } + + public void addAppliedCount(){ + this.appliedCount.addAndGet(1); + } } 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 927ba61b..2cf8c48b 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 @@ -5,6 +5,7 @@ import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryParticipantResponseDto; import JGS.CasperEvent.domain.event.entity.casperBot.CasperBot; +import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import JGS.CasperEvent.domain.event.repository.CasperBotRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; @@ -13,6 +14,7 @@ import JGS.CasperEvent.global.entity.BaseUser; import JGS.CasperEvent.global.enums.CustomErrorCode; 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 org.springframework.stereotype.Service; @@ -47,12 +49,17 @@ public LotteryEventService(LotteryEventRepository lotteryEventRepository, public CasperBotResponseDto postCasperBot(BaseUser user, CasperBotRequestDto casperBotRequestDto) throws CustomException { LotteryParticipants participants = registerUserIfNeed(user); + LotteryEvent lotteryEvent = lotteryEventRepository.findById(1L).orElseThrow(LotteryEventNotExists::new); CasperBot casperBot = casperBotRepository.save(new CasperBot(casperBotRequestDto, user.getId())); + lotteryEvent.addAppliedCount(); participants.updateCasperId(casperBot.getCasperId()); - if (!casperBot.getExpectation().isEmpty()) participants.expectationAdded(); + if (!casperBot.getExpectation().isEmpty()) { + participants.expectationAdded(); + lotteryEvent.addAppliedCount(); + } CasperBotResponseDto casperBotDto = CasperBotResponseDto.of(casperBot); redisService.addData(casperBotDto); From 03c9ec1368aacc4c107c8d90e58dcaf30184ce84 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 10:55:30 +0900 Subject: [PATCH 109/289] =?UTF-8?q?feat:=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=EC=97=90=20=EC=9D=B4=EB=AF=B8=20?= =?UTF-8?q?=EC=B6=94=EC=B2=A8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=EA=B0=80=20?= =?UTF-8?q?=EC=A1=B4=EC=9E=AC=ED=95=A0=20=EB=95=8C=20=EC=97=90=EC=99=B8=20?= =?UTF-8?q?=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/dto/ResponseDto/LotteryEventResponseDto.java | 4 ++-- .../java/JGS/CasperEvent/global/enums/CustomErrorCode.java | 3 ++- .../JGS/CasperEvent/global/error/GlobalExceptionHandler.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java index 7690db6a..f02417a3 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java @@ -5,7 +5,8 @@ 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( @@ -15,5 +16,4 @@ public static LotteryEventResponseDto of(LotteryEvent lotteryEvent, LocalDateTim ChronoUnit.DAYS.between(lotteryEvent.getStartDateTime(), lotteryEvent.getEndDateTime()) ); } - } diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index 408ef36a..6458b599 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -16,7 +16,8 @@ public enum CustomErrorCode { JWT_EXPIRED("만료된 토큰입니다.", 400), JWT_MISSING("인증 토큰이 존재하지 않습니다.", 401), MULTIPLE_RUSH_EVENTS_FOUND("해당 날짜에 여러 개의 이벤트가 존재합니다.", 409), - TODAY_RUSH_EVENT_NOT_FOUND("오늘의 이벤트를 찾을 수 없습니다.", 404); // 새로운 예외 추가 + TODAY_RUSH_EVENT_NOT_FOUND("오늘의 이벤트를 찾을 수 없습니다.", 404), // 새로운 예외 추가 + LOTTERY_EVENT_ALREADY_EXISTS("추첨 이벤트가 이미 존재합니다.", 409); private final String message; private int status; diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java index 58200340..d6ba3665 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java +++ b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java @@ -42,7 +42,7 @@ public ResponseEntity userPrincipalNotFoundHandler(){ public ResponseEntity tooManyLotteryEventExceptionHandler(){ return ResponseEntity .status(HttpStatus.NOT_FOUND) - .body(ErrorResponse.of(CustomErrorCode.LOTTERYEVENT_ALREADY_EXISTS)); + .body(ErrorResponse.of(CustomErrorCode.LOTTERY_EVENT_ALREADY_EXISTS)); } @ExceptionHandler(MethodArgumentNotValidException.class) From 2c32a16afd06f153f5ae7ca4177fa90ca861c528 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 11:03:11 +0900 Subject: [PATCH 110/289] =?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 111/289] =?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 112/289] =?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 113/289] =?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 114/289] =?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 From 72bbc82abd1f665c34446d88e3ae92626960f400 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 12:01:28 +0900 Subject: [PATCH 115/289] =?UTF-8?q?fix:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20Test=20API=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=98=A4=EB=8A=98=20=EB=82=A0=EC=A7=9C=20=EA=B8=B0=EC=A4=80?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=82=BD?= =?UTF-8?q?=EC=9E=85=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/service/eventService/RushEventService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java index 9dbe627c..f2a3de23 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java @@ -163,7 +163,8 @@ public void setTodayEventToRedis() { rushOptionRepository.deleteAllInBatch(); rushEventRepository.deleteAllInBatch(); - LocalDateTime startDateTime = LocalDateTime.of(2024, 8, 11, 22, 0); + // 현재 날짜와 시간을 기준으로 이벤트 시간 설정 + LocalDateTime startDateTime = LocalDateTime.now().withHour(22).withMinute(0).withSecond(0).withNano(0); LocalDateTime endDateTime = startDateTime.plusMinutes(10); List rushEvents = new ArrayList<>(); From d4459b4a1edbf25dfa9749849fa0a2e5f66a29f6 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 12:14:46 +0900 Subject: [PATCH 116/289] =?UTF-8?q?fix:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20Test=20API=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=98=A4=EB=8A=98=20=EB=82=A0=EC=A7=9C=EA=B0=80=20=EC=84=B8=20?= =?UTF-8?q?=EB=B2=88=EC=A7=B8=EB=A1=9C=20=EB=93=B1=EB=A1=9D=EB=90=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/eventService/RushEventService.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java index f2a3de23..bd7e066f 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java @@ -163,14 +163,14 @@ public void setTodayEventToRedis() { rushOptionRepository.deleteAllInBatch(); rushEventRepository.deleteAllInBatch(); - // 현재 날짜와 시간을 기준으로 이벤트 시간 설정 - LocalDateTime startDateTime = LocalDateTime.now().withHour(22).withMinute(0).withSecond(0).withNano(0); + // 오늘의 날짜를 기준으로 시간 설정 + LocalDateTime startDateTime = LocalDateTime.now().minusDays(2).withHour(22).withMinute(0).withSecond(0).withNano(0); LocalDateTime endDateTime = startDateTime.plusMinutes(10); List rushEvents = new ArrayList<>(); for (int i = 0; i < 6; i++) { - // RushEvent 생성 및 초기화 + // 각 이벤트의 날짜를 오늘 기준으로 설정 RushEvent rushEvent = new RushEvent( startDateTime.plusDays(i), // 이벤트 시작 날짜 endDateTime.plusDays(i), // 이벤트 종료 날짜 @@ -212,10 +212,11 @@ public void setTodayEventToRedis() { rushEvents.add(rushEvent); } - // 처음으로 생성된 RushEvent를 Redis에 저장 - rushEventRedisTemplate.opsForValue().set("todayEvent", RushEventResponseDto.of(rushEvents.get(0))); + // 세 번째로 생성된 RushEvent를 Redis에 저장 + rushEventRedisTemplate.opsForValue().set("todayEvent", RushEventResponseDto.of(rushEvents.get(2))); } + // 오늘의 이벤트 옵션 정보를 반환 public MainRushEventOptionsResponseDto getTodayRushEventOptions() { RushEventResponseDto todayEvent = getTodayRushEvent(); From 2dd7a19dccba08ba0df6a7a4d5b3522b90abcbf1 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 11:03:11 +0900 Subject: [PATCH 117/289] =?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 9bff3878b97c416ac4d4826094c7fa0ac4bf6bfc Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 11:04:34 +0900 Subject: [PATCH 118/289] =?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 11c810cd1cf8c27d6eed705c81a8a169a9bd3fe0 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 11:21:06 +0900 Subject: [PATCH 119/289] =?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 7ee3f68bce24b62237db9dcb0de777ad27cf1cec Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 11:23:55 +0900 Subject: [PATCH 120/289] =?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 0718b5b501095d4d807cb76e84ee556ad447c28b Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 11:28:21 +0900 Subject: [PATCH 121/289] =?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 From 57403a3abb540c60dedcf8e88dc6078497946e42 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 13:36:57 +0900 Subject: [PATCH 122/289] =?UTF-8?q?refactor:=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD=20->=20ResponseDto=20?= =?UTF-8?q?=ED=95=98=EC=9C=84=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/controller/adminController/AdminController.java | 4 ++-- .../controller/eventController/LotteryEventController.java | 6 +++--- .../controller/eventController/RushEventController.java | 2 +- .../{ => lotteryEventResponseDto}/CasperBotResponseDto.java | 2 +- .../LotteryEventDetailResponseDto.java | 2 +- .../LotteryEventResponseDto.java | 2 +- .../LotteryParticipantResponseDto.java | 2 +- .../MainRushEventOptionResponseDto.java | 2 +- .../MainRushEventOptionsResponseDto.java | 2 +- .../MainRushEventResponseDto.java | 2 +- .../ResultRushEventOptionResponseDto.java | 2 +- .../RushEventListResponseDto.java | 2 +- .../RushEventOptionResponseDto.java | 2 +- .../RushEventRateResponseDto.java | 2 +- .../{ => rushEventResponseDto}/RushEventResponseDto.java | 4 +--- .../RushEventResultResponseDto.java | 2 +- .../domain/event/service/adminService/AdminService.java | 4 ++-- .../event/service/eventService/LotteryEventService.java | 6 +++--- .../event/service/eventService/RushEventScheduler.java | 3 +-- .../domain/event/service/eventService/RushEventService.java | 2 +- .../domain/event/service/redisService/RedisService.java | 2 +- .../java/JGS/CasperEvent/global/config/RedisConfig.java | 4 ++-- 22 files changed, 29 insertions(+), 32 deletions(-) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/{ => lotteryEventResponseDto}/CasperBotResponseDto.java (91%) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/{ => lotteryEventResponseDto}/LotteryEventDetailResponseDto.java (94%) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/{ => lotteryEventResponseDto}/LotteryEventResponseDto.java (90%) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/{ => lotteryEventResponseDto}/LotteryParticipantResponseDto.java (91%) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/{ => rushEventResponseDto}/MainRushEventOptionResponseDto.java (84%) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/{ => rushEventResponseDto}/MainRushEventOptionsResponseDto.java (84%) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/{ => rushEventResponseDto}/MainRushEventResponseDto.java (91%) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/{ => rushEventResponseDto}/ResultRushEventOptionResponseDto.java (86%) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/{ => rushEventResponseDto}/RushEventListResponseDto.java (91%) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/{ => rushEventResponseDto}/RushEventOptionResponseDto.java (89%) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/{ => rushEventResponseDto}/RushEventRateResponseDto.java (55%) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/{ => rushEventResponseDto}/RushEventResponseDto.java (92%) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/{ => rushEventResponseDto}/RushEventResultResponseDto.java (90%) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 531eac03..7a972985 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -2,8 +2,8 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventDetailResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.global.response.ResponseDto; import jakarta.validation.Valid; 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 d391b37b..7bfe669b 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 @@ -1,9 +1,9 @@ package JGS.CasperEvent.domain.event.controller.eventController; import JGS.CasperEvent.domain.event.dto.RequestDto.CasperBotRequestDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.CasperBotResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryParticipantResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.CasperBotResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryParticipantResponseDto; import JGS.CasperEvent.domain.event.service.redisService.RedisService; import JGS.CasperEvent.domain.event.service.eventService.LotteryEventService; import JGS.CasperEvent.global.entity.BaseUser; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java index cc15be6f..ce9eb3d6 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventController.java @@ -1,7 +1,7 @@ package JGS.CasperEvent.domain.event.controller.eventController; -import JGS.CasperEvent.domain.event.dto.ResponseDto.*; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.*; import JGS.CasperEvent.domain.event.service.eventService.RushEventService; import JGS.CasperEvent.global.entity.BaseUser; import jakarta.servlet.http.HttpServletRequest; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/CasperBotResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/CasperBotResponseDto.java similarity index 91% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/CasperBotResponseDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/CasperBotResponseDto.java index be4caf59..7ec812ea 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/CasperBotResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/CasperBotResponseDto.java @@ -1,4 +1,4 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto; +package JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto; import JGS.CasperEvent.domain.event.entity.casperBot.CasperBot; import org.springframework.data.annotation.Id; 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/lotteryEventResponseDto/LotteryEventDetailResponseDto.java similarity index 94% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventDetailResponseDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventDetailResponseDto.java index 855317c6..5cd27917 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/lotteryEventResponseDto/LotteryEventDetailResponseDto.java @@ -1,4 +1,4 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto; +package JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventResponseDto.java similarity index 90% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventResponseDto.java index f02417a3..f9bfb9c7 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventResponseDto.java @@ -1,4 +1,4 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto; +package JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryParticipantResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryParticipantResponseDto.java similarity index 91% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryParticipantResponseDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryParticipantResponseDto.java index a147d117..e29d8564 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryParticipantResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryParticipantResponseDto.java @@ -1,4 +1,4 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto; +package JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto; import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import java.time.LocalDateTime; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventOptionResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/MainRushEventOptionResponseDto.java similarity index 84% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventOptionResponseDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/MainRushEventOptionResponseDto.java index 7a730c27..b55446d0 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventOptionResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/MainRushEventOptionResponseDto.java @@ -1,4 +1,4 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto; +package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; public record MainRushEventOptionResponseDto(String mainText, String subText) { diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventOptionsResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/MainRushEventOptionsResponseDto.java similarity index 84% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventOptionsResponseDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/MainRushEventOptionsResponseDto.java index c0230be9..6b1294c4 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventOptionsResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/MainRushEventOptionsResponseDto.java @@ -1,4 +1,4 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto; +package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; public record MainRushEventOptionsResponseDto(MainRushEventOptionResponseDto leftOption, diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/MainRushEventResponseDto.java similarity index 91% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventResponseDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/MainRushEventResponseDto.java index cfd61949..c73bde04 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/MainRushEventResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/MainRushEventResponseDto.java @@ -1,4 +1,4 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto; +package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; import JGS.CasperEvent.domain.event.entity.event.RushEvent; import lombok.Getter; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/ResultRushEventOptionResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/ResultRushEventOptionResponseDto.java similarity index 86% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/ResultRushEventOptionResponseDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/ResultRushEventOptionResponseDto.java index 3cc2b6a2..00ff31c5 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/ResultRushEventOptionResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/ResultRushEventOptionResponseDto.java @@ -1,4 +1,4 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto; +package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; public record ResultRushEventOptionResponseDto(String mainText, String resultMainText, String resultSubText) { public static ResultRushEventOptionResponseDto of(RushEventOptionResponseDto rushEventOptionResponseDto) { diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventListResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventListResponseDto.java similarity index 91% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventListResponseDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventListResponseDto.java index abcac614..ec8b0749 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventListResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventListResponseDto.java @@ -1,4 +1,4 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto; +package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; import lombok.Getter; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventOptionResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java similarity index 89% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventOptionResponseDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java index 3d786ff7..6b6b6625 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventOptionResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java @@ -1,4 +1,4 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto; +package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; import JGS.CasperEvent.domain.event.entity.event.RushOption; import JGS.CasperEvent.global.enums.Position; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventRateResponseDto.java similarity index 55% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventRateResponseDto.java index d54e4bdc..13001088 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventRateResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventRateResponseDto.java @@ -1,4 +1,4 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto; +package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; public record RushEventRateResponseDto(int optionId, long leftOption, long rightOption) { } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventResponseDto.java similarity index 92% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventResponseDto.java index a0d45131..8aaf4cee 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventResponseDto.java @@ -1,13 +1,11 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto; +package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; import JGS.CasperEvent.domain.event.entity.event.RushEvent; -import JGS.CasperEvent.domain.event.entity.event.RushOption; 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 java.time.LocalDate; import java.time.LocalDateTime; import java.util.Set; import java.util.stream.Collectors; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResultResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventResultResponseDto.java similarity index 90% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResultResponseDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventResultResponseDto.java index 4fee8df8..8d65ce19 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/RushEventResultResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventResultResponseDto.java @@ -1,4 +1,4 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto; +package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 5b8d5f0d..2d9a34bd 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -2,8 +2,8 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventDetailResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.entity.admin.Admin; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; import JGS.CasperEvent.domain.event.repository.AdminRepository; 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 ddd1a32c..59ede967 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 @@ -1,9 +1,9 @@ package JGS.CasperEvent.domain.event.service.eventService; import JGS.CasperEvent.domain.event.dto.RequestDto.CasperBotRequestDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.CasperBotResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryParticipantResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.CasperBotResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryParticipantResponseDto; import JGS.CasperEvent.domain.event.entity.casperBot.CasperBot; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventScheduler.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventScheduler.java index b4eca6ab..0150eac1 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventScheduler.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventScheduler.java @@ -1,7 +1,6 @@ package JGS.CasperEvent.domain.event.service.eventService; -import JGS.CasperEvent.domain.event.dto.ResponseDto.RushEventResponseDto; -import JGS.CasperEvent.domain.event.entity.event.RushEvent; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventResponseDto; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java index bd7e066f..02dd4fd3 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java @@ -1,6 +1,6 @@ package JGS.CasperEvent.domain.event.service.eventService; -import JGS.CasperEvent.domain.event.dto.ResponseDto.*; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.*; import JGS.CasperEvent.domain.event.entity.event.RushEvent; import JGS.CasperEvent.domain.event.entity.event.RushOption; import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/redisService/RedisService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/redisService/RedisService.java index fcf04111..3de8b601 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/redisService/RedisService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/redisService/RedisService.java @@ -1,6 +1,6 @@ package JGS.CasperEvent.domain.event.service.redisService; -import JGS.CasperEvent.domain.event.dto.ResponseDto.CasperBotResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.CasperBotResponseDto; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; diff --git a/Server/src/main/java/JGS/CasperEvent/global/config/RedisConfig.java b/Server/src/main/java/JGS/CasperEvent/global/config/RedisConfig.java index 3862295c..ee04b77d 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/config/RedisConfig.java +++ b/Server/src/main/java/JGS/CasperEvent/global/config/RedisConfig.java @@ -1,7 +1,7 @@ package JGS.CasperEvent.global.config; -import JGS.CasperEvent.domain.event.dto.ResponseDto.CasperBotResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.RushEventResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.CasperBotResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventResponseDto; import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; From ac884a492c0fe47ce0851e9c3f8e5adcc94d5d55 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 13:37:26 +0900 Subject: [PATCH 123/289] =?UTF-8?q?feat:=20=EC=A0=84=EC=B2=B4=20=EC=B0=B8?= =?UTF-8?q?=EC=97=AC=EC=9E=90=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=EC=9A=A9=20ParticipantsListResponseDto=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ParticipantsListResponseDto.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsListResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsListResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsListResponseDto.java new file mode 100644 index 00000000..a3f4a181 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsListResponseDto.java @@ -0,0 +1,6 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto; + +import java.util.concurrent.atomic.AtomicInteger; + +public record ParticipantsListResponseDto(List, Boolean isLastPage, AtomicInteger totalParticipants) { +} From ff663023541b2d529c83a5ba1803abf2aee09bc0 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 13:44:55 +0900 Subject: [PATCH 124/289] =?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=B0=B8=EC=97=AC=EC=9E=90=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=EC=9A=A9=20ParticipantsListResponseDto=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ParticipantsListResponseDto.java | 3 ++- .../ParticipantsResponseDto.java | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsListResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsListResponseDto.java index a3f4a181..1e1da503 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsListResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsListResponseDto.java @@ -1,6 +1,7 @@ package JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -public record ParticipantsListResponseDto(List, Boolean isLastPage, AtomicInteger totalParticipants) { +public record ParticipantsListResponseDto(List participantsList, Boolean isLastPage, AtomicInteger totalParticipants) { } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsResponseDto.java new file mode 100644 index 00000000..5115bec8 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsResponseDto.java @@ -0,0 +1,23 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto; + +import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; + +import java.time.LocalDateTime; + +public record ParticipantsResponseDto( + Long id, String phoneNumber, int linkClickedCounts, + int expectation, int appliedCount, + LocalDateTime createdAt, LocalDateTime updatedAt) { + + public static ParticipantsResponseDto of(LotteryParticipants participant) { + return new ParticipantsResponseDto( + participant.getId(), + participant.getBaseUser().getId(), + participant.getLinkClickedCount(), + participant.getExpectations(), + participant.getAppliedCount(), + participant.getBaseUser().getCreatedAt(), + participant.getBaseUser().getUpdatedAt() + ); + } +} From ddd2a1af343a4318035119b131430f7349fa6b99 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 13:47:14 +0900 Subject: [PATCH 125/289] =?UTF-8?q?fix:=20BaseEvent=20=EC=A0=84=EC=B2=B4?= =?UTF-8?q?=20=EC=9D=91=EB=AA=A8=20=ED=9A=9F=EC=88=98=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=EC=9D=84=20appliedCount=20->=20totalAppli?= =?UTF-8?q?edCount=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/domain/event/entity/event/BaseEvent.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java index bd1828fd..5cd1f8eb 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java @@ -22,14 +22,14 @@ public class BaseEvent extends BaseEntity { @JsonDeserialize(using = LocalDateTimeDeserializer.class) protected LocalDateTime endDateTime; protected int winnerCount; - protected AtomicInteger appliedCount; + protected AtomicInteger totalAppliedCount; // 기본 생성자에서 디폴트 값 설정 public BaseEvent() { this.startDateTime = LocalDateTime.now(); this.endDateTime = LocalDateTime.now().plusMinutes(10); this.winnerCount = 0; // 기본 우승자 수를 0으로 설정 - this.appliedCount = new AtomicInteger(0); + this.totalAppliedCount = new AtomicInteger(0); } // 특정 값을 설정할 수 있는 생성자 @@ -40,6 +40,6 @@ public BaseEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, int win } public void addAppliedCount(){ - this.appliedCount.addAndGet(1); + this.totalAppliedCount.addAndGet(1); } } From 59a5f75db75486b4ffa82fb7a7af92ebfca730f3 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 13:47:32 +0900 Subject: [PATCH 126/289] =?UTF-8?q?fix:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=EA=B0=80=20=EC=97=86=EC=9D=84=20?= =?UTF-8?q?=EB=95=8C=20=EB=B0=9C=EC=83=9D=EC=8B=9C=ED=82=AC=20CustomErrorC?= =?UTF-8?q?ode=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index b3e82a82..49ccd332 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -5,6 +5,7 @@ @Getter public enum CustomErrorCode { NO_RUSH_EVENT("선착순 이벤트를 찾을 수 없습니다.", 404), + NO_LOTTERY_EVENT("선착순 이벤트를 찾을 수 없습니다.", 404), NO_RUSH_EVENT_OPTION("해당 밸런스 게임 선택지를 찾을 수 없습니다.", 404), INVALID_PARAMETER("잘못된 파라미터 입력입니다.", 400), CASPERBOT_NOT_FOUND("배지를 찾을 수 없습니다.", 404), From 1841fb24afe8b99218f67ae15fd7ad95f0f4c9b6 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 13:47:52 +0900 Subject: [PATCH 127/289] =?UTF-8?q?feat:=20=EC=A0=84=EC=B2=B4=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EA=B8=B0=EA=B0=84=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventController/EventController.java | 24 ++++++++++ .../service/eventService/EventService.java | 46 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/EventController.java create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/EventService.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/EventController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/EventController.java new file mode 100644 index 00000000..3183dbe5 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/EventController.java @@ -0,0 +1,24 @@ +package JGS.CasperEvent.domain.event.controller.eventController; + + +import JGS.CasperEvent.domain.event.dto.ResponseDto.TotalEventDateResponseDto; +import JGS.CasperEvent.domain.event.service.eventService.EventService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/event") + +public class EventController { + private final EventService eventService; + + @GetMapping("/total") + public ResponseEntity getTotalEventDate() { + TotalEventDateResponseDto totalEventDateResponseDto = eventService.getTotalEventDate(); + return ResponseEntity.ok(totalEventDateResponseDto); + } +} diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/EventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/EventService.java new file mode 100644 index 00000000..5d93f2ba --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/EventService.java @@ -0,0 +1,46 @@ +package JGS.CasperEvent.domain.event.service.eventService; + +import JGS.CasperEvent.domain.event.dto.ResponseDto.TotalEventDateResponseDto; +import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; +import JGS.CasperEvent.domain.event.entity.event.RushEvent; +import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; +import JGS.CasperEvent.global.enums.CustomErrorCode; +import JGS.CasperEvent.global.error.exception.CustomException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class EventService { + private final RushEventRepository rushEventRepository; + private final LotteryEventRepository lotteryEventRepository; + + public TotalEventDateResponseDto getTotalEventDate() { + List lotteryEventList = lotteryEventRepository.findAll(); + List rushEventList = rushEventRepository.findAll(); + + if (lotteryEventList.isEmpty()) { + throw new CustomException("추첨 이벤트가 DB에 존재하지 않습니다.", CustomErrorCode.NO_LOTTERY_EVENT); + } + + List localDateList = new ArrayList<>(); + + // lotteryEvent는 어차피 최대 1개만 존재 + localDateList.add(lotteryEventList.get(0).getStartDateTime().toLocalDate()); + localDateList.add(lotteryEventList.get(0).getEndDateTime().toLocalDate()); + + for (RushEvent rushEvent : rushEventList) { + localDateList.add(rushEvent.getStartDateTime().toLocalDate()); + } + + localDateList.sort(null); + + return new TotalEventDateResponseDto(localDateList.get(0), localDateList.get(localDateList.size() - 1)); + } +} + From 848240fea72dc785f25d1f07ccee1230afb1fd56 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 13:48:11 +0900 Subject: [PATCH 128/289] =?UTF-8?q?fix:=20=EC=A0=84=EC=B2=B4=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EA=B8=B0=EA=B0=84=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B2=BD=20whiteList=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java index 60c276ba..f9b7cf1e 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAuthorizationFilter.java @@ -32,7 +32,7 @@ public class JwtAuthorizationFilter implements Filter { "/event/rush", "/event/lottery/caspers", "/admin/join", "/admin/auth", "/h2", "/h2/*", "/swagger-ui/*", "/v3/api-docs", "/v3/api-docs/*", - "/event/lottery", "/link/*" + "/event/lottery", "/link/*", "/event/total" }; private final String[] blackListUris = new String[]{ "/event/rush/*", "/event/lottery/casperBot" From 9dc06d9246da9faaeb8093558f77bb330b85d9e7 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 13:48:33 +0900 Subject: [PATCH 129/289] =?UTF-8?q?fix:=20=EB=B3=80=EC=88=98=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/dto/ResponseDto/LotteryEventDetailResponseDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 855317c6..87a3bcfd 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 @@ -23,7 +23,7 @@ public static ArrayList of(List lot event.getStartDateTime().toLocalTime(), event.getEndDateTime().toLocalDate(), event.getEndDateTime().toLocalTime(), - event.getAppliedCount(), + event.getTotalAppliedCount(), event.getWinnerCount(), event.getCreatedAt(), event.getUpdatedAt())); From 87f24a495e4a01d89c596336aed2845ae0b8201b Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 13:48:47 +0900 Subject: [PATCH 130/289] =?UTF-8?q?feat:=20=EC=A0=84=EC=B2=B4=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EA=B8=B0=EA=B0=84=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?DTO=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/dto/ResponseDto/TotalEventDateResponseDto.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/TotalEventDateResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/TotalEventDateResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/TotalEventDateResponseDto.java new file mode 100644 index 00000000..44fb6411 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/TotalEventDateResponseDto.java @@ -0,0 +1,6 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto; + +import java.time.LocalDate; + +public record TotalEventDateResponseDto(LocalDate totalEventStartDate, LocalDate totalEventEndDate) { +} From 8596ee2fdff4bda3c6522717ce56842d23d81b20 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 13:51:40 +0900 Subject: [PATCH 131/289] =?UTF-8?q?feat:=20=EC=A0=84=EC=B2=B4=20=EC=B0=B8?= =?UTF-8?q?=EA=B0=80=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20API=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminController/AdminController.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 7a972985..ea3d6f83 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -4,6 +4,7 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; 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.ParticipantsListResponseDto; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.global.response.ResponseDto; import jakarta.validation.Valid; @@ -24,6 +25,7 @@ public AdminController(AdminService adminService) { this.adminService = adminService; } + // 어드민 생성 @PostMapping("/join") public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto adminRequestDto) { return ResponseEntity @@ -31,6 +33,7 @@ public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto .body(adminService.postAdmin(adminRequestDto)); } + // 추첨 이벤트 조회 @GetMapping("/event/lottery") public ResponseEntity> getLotteryEvent() { return ResponseEntity @@ -38,12 +41,23 @@ public ResponseEntity> getLotteryEvent() { .body(adminService.getLotteryEvent()); } + // 추첨 이벤트 생성 @PostMapping("/event/lottery") public ResponseEntity createLotteryEvent( - @Valid @RequestBody LotteryEventRequestDto lotteryEventRequestDto) { + @Valid @RequestBody LotteryEventRequestDto lotteryEventRequestDto) { return ResponseEntity .status(HttpStatus.CREATED) .body(adminService.createLotteryEvent(lotteryEventRequestDto)); } + // 추첨 이벤트 참여자 조회 + @GetMapping("/event/lottery/participants") + public ResponseEntity getLotteryEventParticipants( + @RequestParam(name = "size", required = false, defaultValue = "10") int size, + @RequestParam(name = "page", required = false, defaultValue = "1") int page, + @RequestParam(name = "number", required = false) String phoneNumber) { + return ResponseEntity + .status(HttpStatus.OK) + .body(adminService.getLotteryEventParticipants(size, page, phoneNumber)); + } } From 682a3dbb11ef401666aaff5af5f3ca16fbdc314c Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 14:45:09 +0900 Subject: [PATCH 132/289] =?UTF-8?q?fix:=20page=20=EA=B8=B0=EB=B3=B8?= =?UTF-8?q?=EA=B0=92=200=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD,=20number?= =?UTF-8?q?=20=EA=B8=B0=EB=B3=B8=EA=B0=92=200=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/controller/adminController/AdminController.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index ea3d6f83..bff304e6 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -4,7 +4,7 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; 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.ParticipantsListResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsListResponseDto; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.global.response.ResponseDto; import jakarta.validation.Valid; @@ -52,10 +52,10 @@ public ResponseEntity createLotteryEvent( // 추첨 이벤트 참여자 조회 @GetMapping("/event/lottery/participants") - public ResponseEntity getLotteryEventParticipants( + public ResponseEntity getLotteryEventParticipants( @RequestParam(name = "size", required = false, defaultValue = "10") int size, - @RequestParam(name = "page", required = false, defaultValue = "1") int page, - @RequestParam(name = "number", required = false) String phoneNumber) { + @RequestParam(name = "page", required = false, defaultValue = "0") int page, + @RequestParam(name = "number", required = false, defaultValue = "") String phoneNumber) { return ResponseEntity .status(HttpStatus.OK) .body(adminService.getLotteryEventParticipants(size, page, phoneNumber)); From b33e1896f27d35309119a8026fbc4ecdf633632a Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 14:45:35 +0900 Subject: [PATCH 133/289] =?UTF-8?q?feat:=20findByBaseUser=5FId=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../participantsRepository/LotteryParticipantsRepository.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java index 2adcc557..48c9be10 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java @@ -2,6 +2,8 @@ import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import JGS.CasperEvent.global.entity.BaseUser; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -10,5 +12,7 @@ @Repository public interface LotteryParticipantsRepository extends JpaRepository { Optional findByBaseUser(BaseUser baseUser); + + Page findByBaseUser_Id(String id, Pageable pageable); } From 882232ee62f63dcc1c71fb3162bb325ccb216269 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 14:46:15 +0900 Subject: [PATCH 134/289] =?UTF-8?q?chore:=20DTO=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20-=20EventParticipantsListResponseDto=20->L?= =?UTF-8?q?otteryEventParticipantsListResponseDto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - EventParticipantsResponseDto ->LotteryEventParticipantsResponseDto --- .../LotteryEventParticipantsListResponseDto.java | 6 ++++++ ...seDto.java => LotteryEventParticipantsResponseDto.java} | 6 +++--- .../ParticipantsListResponseDto.java | 7 ------- 3 files changed, 9 insertions(+), 10 deletions(-) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsListResponseDto.java rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/{ParticipantsResponseDto.java => LotteryEventParticipantsResponseDto.java} (78%) delete mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsListResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsListResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsListResponseDto.java new file mode 100644 index 00000000..fa26a30e --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsListResponseDto.java @@ -0,0 +1,6 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto; + +import java.util.List; + +public record LotteryEventParticipantsListResponseDto(List participantsList, Boolean isLastPage, long totalParticipants) { +} diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java similarity index 78% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsResponseDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java index 5115bec8..ca79a5eb 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java @@ -4,13 +4,13 @@ import java.time.LocalDateTime; -public record ParticipantsResponseDto( +public record LotteryEventParticipantsResponseDto( Long id, String phoneNumber, int linkClickedCounts, int expectation, int appliedCount, LocalDateTime createdAt, LocalDateTime updatedAt) { - public static ParticipantsResponseDto of(LotteryParticipants participant) { - return new ParticipantsResponseDto( + public static LotteryEventParticipantsResponseDto of(LotteryParticipants participant) { + return new LotteryEventParticipantsResponseDto( participant.getId(), participant.getBaseUser().getId(), participant.getLinkClickedCount(), diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsListResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsListResponseDto.java deleted file mode 100644 index 1e1da503..00000000 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/ParticipantsListResponseDto.java +++ /dev/null @@ -1,7 +0,0 @@ -package JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto; - -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -public record ParticipantsListResponseDto(List participantsList, Boolean isLastPage, AtomicInteger totalParticipants) { -} From 2ac8b3696635a5deb92ced59b0b166db6d49be80 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 14:46:33 +0900 Subject: [PATCH 135/289] =?UTF-8?q?feat:=20=EC=B0=B8=EC=97=AC=EC=9E=90=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 2d9a34bd..9e2839b4 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -3,23 +3,33 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; +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.entity.admin.Admin; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; +import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import JGS.CasperEvent.domain.event.repository.AdminRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; +import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryParticipantsRepository; import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.Role; import JGS.CasperEvent.global.error.exception.CustomException; +import JGS.CasperEvent.global.error.exception.LotteryEventNotExists; import JGS.CasperEvent.global.error.exception.TooManyLotteryEventException; import JGS.CasperEvent.global.response.ResponseDto; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; +import java.util.Optional; @RequiredArgsConstructor @Service @@ -28,6 +38,7 @@ public class AdminService { private final AdminRepository adminRepository; private final LotteryEventRepository lotteryEventRepository; private final RushEventRepository rushEventRepository; + private final LotteryParticipantsRepository lotteryParticipantsRepository; public Admin verifyAdmin(AdminRequestDto adminRequestDto) { return adminRepository.findById(adminRequestDto.getAdminId()).orElseThrow(NoSuchElementException::new); @@ -47,7 +58,7 @@ public ResponseDto postAdmin(AdminRequestDto adminRequestDto) { } public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lotteryEventRequestDto) { - if(lotteryEventRepository.count() >= 1) throw new TooManyLotteryEventException(); + if (lotteryEventRepository.count() >= 1) throw new TooManyLotteryEventException(); LotteryEvent lotteryEvent = lotteryEventRepository.save(new LotteryEvent( lotteryEventRequestDto.getEventStartDateTime(), @@ -63,4 +74,25 @@ public List getLotteryEvent() { lotteryEventRepository.findAll() ); } + + public LotteryEventParticipantsListResponseDto getLotteryEventParticipants(int size, int page, String phoneNumber) { + Pageable pageable = PageRequest.of(page, size); + + Page lotteryParticipantsPage = null; + if (phoneNumber.isEmpty()) lotteryParticipantsPage = lotteryParticipantsRepository.findAll(pageable); + else lotteryParticipantsRepository.findByBaseUser_Id(phoneNumber, pageable); + + for (LotteryParticipants participants : lotteryParticipantsPage) { + System.out.println("participants = " + participants); + } + List lotteryEventParticipantsResponseDtoList = new ArrayList<>(); + + for (LotteryParticipants lotteryParticipant : lotteryParticipantsPage) { + lotteryEventParticipantsResponseDtoList.add( + LotteryEventParticipantsResponseDto.of(lotteryParticipant) + ); + } + Boolean isLastPage = !lotteryParticipantsPage.hasNext(); + return new LotteryEventParticipantsListResponseDto(lotteryEventParticipantsResponseDtoList, isLastPage, lotteryParticipantsRepository.count()); + } } From b1b182eedb14d59bfcaeb0a6d4c195a2d40f40bd Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 14:46:33 +0900 Subject: [PATCH 136/289] =?UTF-8?q?feat:=20=EC=B0=B8=EC=97=AC=EC=9E=90=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 2d9a34bd..5913a594 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -3,21 +3,29 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; +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.entity.admin.Admin; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; +import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import JGS.CasperEvent.domain.event.repository.AdminRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; +import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryParticipantsRepository; import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.Role; import JGS.CasperEvent.global.error.exception.CustomException; import JGS.CasperEvent.global.error.exception.TooManyLotteryEventException; import JGS.CasperEvent.global.response.ResponseDto; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; @@ -28,6 +36,7 @@ public class AdminService { private final AdminRepository adminRepository; private final LotteryEventRepository lotteryEventRepository; private final RushEventRepository rushEventRepository; + private final LotteryParticipantsRepository lotteryParticipantsRepository; public Admin verifyAdmin(AdminRequestDto adminRequestDto) { return adminRepository.findById(adminRequestDto.getAdminId()).orElseThrow(NoSuchElementException::new); @@ -47,7 +56,7 @@ public ResponseDto postAdmin(AdminRequestDto adminRequestDto) { } public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lotteryEventRequestDto) { - if(lotteryEventRepository.count() >= 1) throw new TooManyLotteryEventException(); + if (lotteryEventRepository.count() >= 1) throw new TooManyLotteryEventException(); LotteryEvent lotteryEvent = lotteryEventRepository.save(new LotteryEvent( lotteryEventRequestDto.getEventStartDateTime(), @@ -63,4 +72,25 @@ public List getLotteryEvent() { lotteryEventRepository.findAll() ); } + + public LotteryEventParticipantsListResponseDto getLotteryEventParticipants(int size, int page, String phoneNumber) { + Pageable pageable = PageRequest.of(page, size); + + Page lotteryParticipantsPage = null; + if (phoneNumber.isEmpty()) lotteryParticipantsPage = lotteryParticipantsRepository.findAll(pageable); + else lotteryParticipantsRepository.findByBaseUser_Id(phoneNumber, pageable); + + for (LotteryParticipants participants : lotteryParticipantsPage) { + System.out.println("participants = " + participants); + } + List lotteryEventParticipantsResponseDtoList = new ArrayList<>(); + + for (LotteryParticipants lotteryParticipant : lotteryParticipantsPage) { + lotteryEventParticipantsResponseDtoList.add( + LotteryEventParticipantsResponseDto.of(lotteryParticipant) + ); + } + Boolean isLastPage = !lotteryParticipantsPage.hasNext(); + return new LotteryEventParticipantsListResponseDto(lotteryEventParticipantsResponseDtoList, isLastPage, lotteryParticipantsRepository.count()); + } } From 79c17beb729f9fa2cb40752b06b06efdebc6b296 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 15:09:18 +0900 Subject: [PATCH 137/289] =?UTF-8?q?refactor:=20=ED=8F=B4=EB=8D=94=20?= =?UTF-8?q?=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD=20RequestDto=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=20=EB=82=B4=EC=97=90=20=EC=84=B8=EB=B6=80=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/controller/adminController/AdminController.java | 2 +- .../controller/eventController/LotteryEventController.java | 2 +- .../RequestDto/{ => lotteryEventDto}/CasperBotRequestDto.java | 2 +- .../{ => lotteryEventDto}/LotteryEventRequestDto.java | 2 +- .../CasperEvent/domain/event/entity/casperBot/CasperBot.java | 2 +- .../domain/event/service/adminService/AdminService.java | 4 +--- .../event/service/eventService/LotteryEventService.java | 2 +- 7 files changed, 7 insertions(+), 9 deletions(-) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/{ => lotteryEventDto}/CasperBotRequestDto.java (95%) rename Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/{ => lotteryEventDto}/LotteryEventRequestDto.java (87%) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index bff304e6..63b7b9f9 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -1,7 +1,7 @@ package JGS.CasperEvent.domain.event.controller.adminController; import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; -import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto; 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; 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 7bfe669b..416ad5fa 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 @@ -1,6 +1,6 @@ package JGS.CasperEvent.domain.event.controller.eventController; -import JGS.CasperEvent.domain.event.dto.RequestDto.CasperBotRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.CasperBotRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.CasperBotResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryParticipantResponseDto; 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/lotteryEventDto/CasperBotRequestDto.java similarity index 95% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/CasperBotRequestDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/CasperBotRequestDto.java index f9a599b3..5e6da14a 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/lotteryEventDto/CasperBotRequestDto.java @@ -1,4 +1,4 @@ -package JGS.CasperEvent.domain.event.dto.RequestDto; +package JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto; import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/LotteryEventRequestDto.java similarity index 87% rename from Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java rename to Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/LotteryEventRequestDto.java index 80e2ec11..39149522 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/LotteryEventRequestDto.java @@ -1,4 +1,4 @@ -package JGS.CasperEvent.domain.event.dto.RequestDto; +package JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto; import jakarta.validation.constraints.NotNull; import lombok.Getter; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java index f79ff877..96582663 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java @@ -1,6 +1,6 @@ package JGS.CasperEvent.domain.event.entity.casperBot; -import JGS.CasperEvent.domain.event.dto.RequestDto.CasperBotRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.CasperBotRequestDto; import JGS.CasperEvent.global.entity.BaseEntity; import jakarta.persistence.*; import lombok.Getter; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 9e2839b4..cbde3bc6 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -1,7 +1,7 @@ package JGS.CasperEvent.domain.event.service.adminService; import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; -import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsListResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsResponseDto; @@ -16,7 +16,6 @@ import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.Role; import JGS.CasperEvent.global.error.exception.CustomException; -import JGS.CasperEvent.global.error.exception.LotteryEventNotExists; import JGS.CasperEvent.global.error.exception.TooManyLotteryEventException; import JGS.CasperEvent.global.response.ResponseDto; import lombok.RequiredArgsConstructor; @@ -29,7 +28,6 @@ import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; -import java.util.Optional; @RequiredArgsConstructor @Service 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 59ede967..a6fb31bc 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 @@ -1,6 +1,6 @@ package JGS.CasperEvent.domain.event.service.eventService; -import JGS.CasperEvent.domain.event.dto.RequestDto.CasperBotRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.CasperBotRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.CasperBotResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryParticipantResponseDto; From 1850f75486f2bf5ff4c525a3074482870da3d46f Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 15:29:47 +0900 Subject: [PATCH 138/289] =?UTF-8?q?fix:=20=EC=BA=90=EC=8A=A4=ED=8D=BC=20?= =?UTF-8?q?=EB=B4=87=20=EC=83=9D=EC=84=B1=20=EC=8B=9C=20referralId=20?= =?UTF-8?q?=EC=97=86=EC=96=B4=EB=8F=84=20=EC=83=9D=EC=84=B1=20=EA=B0=80?= =?UTF-8?q?=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/RequestDto/lotteryEventDto/CasperBotRequestDto.java | 3 ++- .../JGS/CasperEvent/domain/event/entity/event/BaseEvent.java | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/CasperBotRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/CasperBotRequestDto.java index 5e6da14a..d2780df1 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/CasperBotRequestDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/CasperBotRequestDto.java @@ -37,5 +37,6 @@ public class CasperBotRequestDto { private String name; private String expectation; - private String referralId; + + private String referralId = ""; } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java index 5cd1f8eb..fcd9171c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java @@ -37,6 +37,7 @@ public BaseEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, int win this.startDateTime = startDateTime; this.endDateTime = endDateTime; this.winnerCount = winnerCount; + this.totalAppliedCount = new AtomicInteger(0); } public void addAppliedCount(){ From a0ec02d3ece49afa703ea11078613f10297a240f Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 16:57:29 +0900 Subject: [PATCH 139/289] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/global/config/WebConfig.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/config/WebConfig.java b/Server/src/main/java/JGS/CasperEvent/global/config/WebConfig.java index f5137207..534352fc 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/config/WebConfig.java +++ b/Server/src/main/java/JGS/CasperEvent/global/config/WebConfig.java @@ -22,15 +22,6 @@ @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("*"); -// } - @Bean public FilterRegistrationBean corsFilterRegistrationBean() { FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); From f23964e2745d1001ce5ab58105984a94a859153f Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 16:57:59 +0900 Subject: [PATCH 140/289] =?UTF-8?q?feat:=20RushEventRequestDto=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rushEventDto/RushEventRequestDto.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventRequestDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventRequestDto.java new file mode 100644 index 00000000..fc3405b4 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventRequestDto.java @@ -0,0 +1,22 @@ +package JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.ToString; + +import java.time.LocalDate; +import java.time.LocalTime; + +@ToString +@Getter +public class RushEventRequestDto { + private LocalDate eventDate; + private LocalTime startTime; + private LocalTime endTime; + private int winnerCount; + private String prizeDescription; + @JsonProperty("leftOption") + private RushEventOptionRequestDto leftOption; + @JsonProperty("rightOption") + private RushEventOptionRequestDto rightOption; +} From 66469d6e8560bc23080ff31fd265b9627446d435 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 16:58:10 +0900 Subject: [PATCH 141/289] =?UTF-8?q?feat:=20RushEventOptionRequestDto=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rushEventDto/RushEventOptionRequestDto.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventOptionRequestDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventOptionRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventOptionRequestDto.java new file mode 100644 index 00000000..90dd2549 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventOptionRequestDto.java @@ -0,0 +1,13 @@ +package JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto; + +import lombok.Getter; +import lombok.ToString; + +@ToString +@Getter +public class RushEventOptionRequestDto { + private String mainText; + private String subText; + private String resultMainText; + private String resultSubText; +} From 80eccebf39dd787048807d176524d3457a15b90a Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Mon, 12 Aug 2024 18:04:58 +0900 Subject: [PATCH 142/289] =?UTF-8?q?fix:=20AtomicInteger=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 --- .../LotteryEventDetailResponseDto.java | 3 +-- .../domain/event/entity/event/BaseEvent.java | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventDetailResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventDetailResponseDto.java index 4aa9743f..f3180f07 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventDetailResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventDetailResponseDto.java @@ -7,12 +7,11 @@ import java.time.LocalTime; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; public record LotteryEventDetailResponseDto( LocalDate startDate, LocalTime startTime, LocalDate endDate, LocalTime endTime, - AtomicInteger appliedCount, int winnerCount, + int appliedCount, int winnerCount, LocalDateTime createdAt, LocalDateTime updatedAt) { public static ArrayList of(List lotteryEvent) { diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java index fcd9171c..e5933697 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java @@ -9,7 +9,6 @@ import lombok.Getter; import java.time.LocalDateTime; -import java.util.concurrent.atomic.AtomicInteger; @Getter @MappedSuperclass @@ -22,14 +21,14 @@ public class BaseEvent extends BaseEntity { @JsonDeserialize(using = LocalDateTimeDeserializer.class) protected LocalDateTime endDateTime; protected int winnerCount; - protected AtomicInteger totalAppliedCount; + protected int totalAppliedCount; // 기본 생성자에서 디폴트 값 설정 public BaseEvent() { this.startDateTime = LocalDateTime.now(); this.endDateTime = LocalDateTime.now().plusMinutes(10); this.winnerCount = 0; // 기본 우승자 수를 0으로 설정 - this.totalAppliedCount = new AtomicInteger(0); + this.totalAppliedCount = 0; } // 특정 값을 설정할 수 있는 생성자 @@ -37,10 +36,10 @@ public BaseEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, int win this.startDateTime = startDateTime; this.endDateTime = endDateTime; this.winnerCount = winnerCount; - this.totalAppliedCount = new AtomicInteger(0); + this.totalAppliedCount = 0; } - public void addAppliedCount(){ - this.totalAppliedCount.addAndGet(1); + public void addAppliedCount() { + this.totalAppliedCount++; } } From 4b0430a756fdd0e426203fc715460f64dec49151 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 23:28:50 +0900 Subject: [PATCH 143/289] =?UTF-8?q?fix:=20=EC=83=9D=EC=84=B1=EC=9E=90=20?= =?UTF-8?q?=EC=A3=BC=EC=9E=85=20@RequiredArgsConstructor=20=EB=8C=80?= =?UTF-8?q?=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/controller/adminController/AdminController.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 63b7b9f9..be8130eb 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -8,7 +8,7 @@ import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.global.response.ResponseDto; import jakarta.validation.Valid; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -17,14 +17,10 @@ @RestController @RequestMapping("/admin") +@RequiredArgsConstructor public class AdminController { private final AdminService adminService; - @Autowired - public AdminController(AdminService adminService) { - this.adminService = adminService; - } - // 어드민 생성 @PostMapping("/join") public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto adminRequestDto) { From cf768821e671e511dd50b3d1abb61432da321b83 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 23:29:36 +0900 Subject: [PATCH 144/289] =?UTF-8?q?fix:=20AdminService=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=EC=97=86=EB=8A=94=20=EC=9D=98=EC=A1=B4=EC=84=B1=20?= =?UTF-8?q?=EC=A3=BC=EC=9E=85=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/service/adminService/AdminService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index cbde3bc6..ffbf2085 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -11,7 +11,6 @@ import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import JGS.CasperEvent.domain.event.repository.AdminRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; -import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryParticipantsRepository; import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.Role; @@ -35,7 +34,6 @@ public class AdminService { private final AdminRepository adminRepository; private final LotteryEventRepository lotteryEventRepository; - private final RushEventRepository rushEventRepository; private final LotteryParticipantsRepository lotteryParticipantsRepository; public Admin verifyAdmin(AdminRequestDto adminRequestDto) { From df5a356a6eb61403ea0cc8db196335ba2d5c8c5a Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 23:30:33 +0900 Subject: [PATCH 145/289] =?UTF-8?q?fix:=20BaseEvent=EC=9D=98=20totalApplie?= =?UTF-8?q?dCount=20=ED=83=80=EC=9E=85=20AtomicInteger=20->=20int=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/domain/event/entity/event/BaseEvent.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java index fcd9171c..54dc7c52 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java @@ -9,7 +9,6 @@ import lombok.Getter; import java.time.LocalDateTime; -import java.util.concurrent.atomic.AtomicInteger; @Getter @MappedSuperclass @@ -22,14 +21,14 @@ public class BaseEvent extends BaseEntity { @JsonDeserialize(using = LocalDateTimeDeserializer.class) protected LocalDateTime endDateTime; protected int winnerCount; - protected AtomicInteger totalAppliedCount; + protected int totalAppliedCount; // 기본 생성자에서 디폴트 값 설정 public BaseEvent() { this.startDateTime = LocalDateTime.now(); this.endDateTime = LocalDateTime.now().plusMinutes(10); this.winnerCount = 0; // 기본 우승자 수를 0으로 설정 - this.totalAppliedCount = new AtomicInteger(0); + this.totalAppliedCount = 0; } // 특정 값을 설정할 수 있는 생성자 @@ -37,10 +36,10 @@ public BaseEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, int win this.startDateTime = startDateTime; this.endDateTime = endDateTime; this.winnerCount = winnerCount; - this.totalAppliedCount = new AtomicInteger(0); + this.totalAppliedCount = 0; } public void addAppliedCount(){ - this.totalAppliedCount.addAndGet(1); + this.totalAppliedCount++; } } From 5d5eafbbec61f62233f5cd2af7785805ff6512eb Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 23:30:53 +0900 Subject: [PATCH 146/289] =?UTF-8?q?fix:=20=ED=95=84=EC=9A=94=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/global/jwt/filter/JwtAdminFilter.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAdminFilter.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAdminFilter.java index be95e09f..128fb17f 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAdminFilter.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtAdminFilter.java @@ -29,8 +29,5 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(json); - -// HttpServletResponse httpServletResponse = (HttpServletResponse) response; -// httpServletResponse.sendError(HttpStatus.BAD_REQUEST.value()); } } \ No newline at end of file From 7b88c44502dec0886be0f33ae1ca05fb3cab2bf5 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 23:31:12 +0900 Subject: [PATCH 147/289] =?UTF-8?q?fix:=20JwtProvider=20=EB=82=B4=EB=B6=80?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=82=AC=EC=9A=A9=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EB=8A=94=20public=20->=20private=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/global/jwt/util/JwtProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/util/JwtProvider.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/util/JwtProvider.java index a39170f7..8797f4f3 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/util/JwtProvider.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/util/JwtProvider.java @@ -22,7 +22,7 @@ public Jwt createJwt(Map claims) { .build(); } - public String createToken(Map claims, Date expireDate) { + private String createToken(Map claims, Date expireDate) { return Jwts.builder() .setClaims(claims) .setExpiration(expireDate) @@ -39,7 +39,7 @@ public Claims getClaims(String token) { } - public Date getExpireDateAccessToken() { + private Date getExpireDateAccessToken() { long expireTimeMils = 1000L * 60 * 60 * 24 * 365; return new Date(System.currentTimeMillis() + expireTimeMils); } From 7eb6a79e52234d620cf98ee836c691fbd6d1d0a2 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 23:31:26 +0900 Subject: [PATCH 148/289] =?UTF-8?q?fix:=20JwtUserFilter=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=EC=97=86=EB=8A=94=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/global/jwt/filter/JwtUserFilter.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtUserFilter.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtUserFilter.java index aed5767a..935fad60 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtUserFilter.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/JwtUserFilter.java @@ -29,8 +29,5 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(json); - -// HttpServletResponse httpServletResponse = (HttpServletResponse) response; -// httpServletResponse.sendError(HttpStatus.BAD_REQUEST.value()); } } \ No newline at end of file From 380af4c61ce74c419921346788d83be915ce3dc0 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 23:34:08 +0900 Subject: [PATCH 149/289] =?UTF-8?q?fix:=20appliedCount=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20AtomicInteger=20->=20int=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lotteryEventResponseDto/LotteryEventDetailResponseDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventDetailResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventDetailResponseDto.java index 4aa9743f..245e1194 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventDetailResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventDetailResponseDto.java @@ -12,7 +12,7 @@ public record LotteryEventDetailResponseDto( LocalDate startDate, LocalTime startTime, LocalDate endDate, LocalTime endTime, - AtomicInteger appliedCount, int winnerCount, + int appliedCount, int winnerCount, LocalDateTime createdAt, LocalDateTime updatedAt) { public static ArrayList of(List lotteryEvent) { From 8541804850297ca6ee6fae0558df3fa3838ef70f Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 23:35:38 +0900 Subject: [PATCH 150/289] =?UTF-8?q?feat:=20RushEventControllerTest=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1.=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=EC=96=B4=EC=97=90=EC=84=9C=EB=A7=8C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RushEventControllerTest.java | 263 ++++++++++++++++-- 1 file changed, 236 insertions(+), 27 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventControllerTest.java index 42fef846..1ae656c3 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventControllerTest.java @@ -1,50 +1,127 @@ package JGS.CasperEvent.domain.event.controller.eventController; -import JGS.CasperEvent.domain.event.entity.event.RushEvent; -import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.*; +import JGS.CasperEvent.domain.event.service.adminService.AdminService; +import JGS.CasperEvent.domain.event.service.eventService.RushEventService; +import JGS.CasperEvent.global.entity.BaseUser; +import JGS.CasperEvent.global.enums.CustomErrorCode; +import JGS.CasperEvent.global.enums.Role; +import JGS.CasperEvent.global.error.exception.CustomException; +import JGS.CasperEvent.global.jwt.service.UserService; +import JGS.CasperEvent.global.jwt.util.JwtProvider; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Profile; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; import org.springframework.http.MediaType; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.Arrays; +import static org.mockito.BDDMockito.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@SpringBootTest -@AutoConfigureMockMvc -@ActiveProfiles("local") -class RushEventControllerTest { +@WebMvcTest(RushEventController.class) +@Import(JwtProvider.class) +public class RushEventControllerTest { @Autowired private MockMvc mockMvc; - @Autowired - private RushEventRepository rushEventRepository; + @MockBean + private RushEventService rushEventService; + + @MockBean + private UserService userService; + + @MockBean + private AdminService adminService; + + private String phoneNumber; + private String accessToken; @BeforeEach - void setUp() { - // 테스트 데이터 초기화 - rushEventRepository.deleteAll(); // 기존 데이터 삭제 + void setUp() throws Exception { + this.phoneNumber = "010-0000-0000"; + + // userService 모킹 + given(userService.verifyUser(any())).willReturn(new BaseUser(this.phoneNumber, Role.USER)); + + // 액세스 토큰 설정 + this.accessToken = getToken(this.phoneNumber); + + // Mock 데이터 설정 + RushEventListResponseDto rushEventListResponseDto = new RushEventListResponseDto( + Arrays.asList( + new MainRushEventResponseDto(37L, LocalDateTime.of(2024, 8, 11, 22, 0), LocalDateTime.of(2024, 8, 11, 22, 10)), + new MainRushEventResponseDto(38L, LocalDateTime.of(2024, 8, 12, 22, 0), LocalDateTime.of(2024, 8, 12, 22, 10)), + new MainRushEventResponseDto(39L, LocalDateTime.of(2024, 8, 13, 22, 0), LocalDateTime.of(2024, 8, 13, 22, 10)), + new MainRushEventResponseDto(40L, LocalDateTime.of(2024, 8, 14, 22, 0), LocalDateTime.of(2024, 8, 14, 22, 10)), + new MainRushEventResponseDto(41L, LocalDateTime.of(2024, 8, 15, 22, 0), LocalDateTime.of(2024, 8, 15, 22, 10)), + new MainRushEventResponseDto(42L, LocalDateTime.of(2024, 8, 16, 22, 0), LocalDateTime.of(2024, 8, 16, 22, 10)) + ), + LocalDateTime.of(2024, 8, 12, 13, 46, 29, 48782), + 37L, + LocalDate.of(2024, 8, 11), + LocalDate.of(2024, 8, 16), + 6L + ); + + given(rushEventService.getAllRushEvents()).willReturn(rushEventListResponseDto); + + MainRushEventOptionsResponseDto mainRushEventOptionsResponseDto = new MainRushEventOptionsResponseDto( + new MainRushEventOptionResponseDto("leftMainText", "leftSubText"), + new MainRushEventOptionResponseDto("rightMainText", "rightSubText") + ); + + given(rushEventService.getTodayRushEventOptions()).willReturn(mainRushEventOptionsResponseDto); - // 새로운 생성자를 사용한 RushEvent 생성 - RushEvent rushEvent1 = new RushEvent("https://example.com/image1.png", "First prize"); - RushEvent rushEvent2 = new RushEvent("https://example.com/image2.png", "Second prize"); + ResultRushEventOptionResponseDto resultRushEventOptionResponseDto = new ResultRushEventOptionResponseDto( + "mainText", + "resultMainText", + "resultSubText" + ); - // 엔티티 저장 - rushEventRepository.saveAll(Arrays.asList(rushEvent1, rushEvent2)); + given(rushEventService.getRushEventOptionResult(1)).willReturn(resultRushEventOptionResponseDto); + given(rushEventService.getRushEventOptionResult(2)).willReturn(resultRushEventOptionResponseDto); + + // 예: apply 메서드가 정상적으로 동작하는 경우 (optionId가 2일 때) + willDoNothing().given(rushEventService).apply(any(BaseUser.class), eq(2)); + + // 예: apply 메서드가 실패하는 경우 (optionId가 1일 때) + willThrow(new CustomException("이미 응모한 회원입니다.", CustomErrorCode.CONFLICT)) + .given(rushEventService).apply(any(BaseUser.class), eq(1)); + + RushEventRateResponseDto rushEventRateResponseDto = new RushEventRateResponseDto( + 1, + 315, + 1000 + ); + + given(rushEventService.getRushEventRate(any())).willReturn(rushEventRateResponseDto); + + RushEventResultResponseDto rushEventResultResponseDto = new RushEventResultResponseDto( + rushEventRateResponseDto, + 1, + 1000, + 315 + ); + + given(rushEventService.getRushEventResult(any())).willReturn(rushEventResultResponseDto); } @Test + @DisplayName("메인화면 선착순 이벤트 전체 조회 API 테스트") public void getRushEventListAndServerTime() throws Exception { // when ResultActions perform = mockMvc.perform(get("/event/rush") @@ -53,12 +130,144 @@ public void getRushEventListAndServerTime() throws Exception { // then perform.andExpect(status().isOk()) .andExpect(jsonPath("$.events").isArray()) - .andExpect(jsonPath("$.events.length()").value(2)) - .andExpect(jsonPath("$.events[0].prizeImageUrl").value("https://example.com/image1.png")) - .andExpect(jsonPath("$.events[0].prizeDescription").value("First prize")) - .andExpect(jsonPath("$.events[1].prizeImageUrl").value("https://example.com/image2.png")) - .andExpect(jsonPath("$.events[1].prizeDescription").value("Second prize")) - .andExpect(jsonPath("$.serverTime").exists()) + .andExpect(jsonPath("$.events.length()").value(6)) + .andExpect(jsonPath("$.events[0].rushEventId").value(37)) + .andExpect(jsonPath("$.serverTime").value("2024-08-12T13:46:29.000048782")) + .andExpect(jsonPath("$.todayEventId").value(37)) + .andExpect(jsonPath("$.eventStartDate").value("2024-08-11")) + .andExpect(jsonPath("$.eventEndDate").value("2024-08-16")) + .andExpect(jsonPath("$.activePeriod").value(6)) + .andDo(print()); + } + + @Test + @DisplayName("오늘의 선착순 이벤트 조회 API 성공 테스트") + public void getTodayEventTest() throws Exception { + // given + String accessToken = this.accessToken; + + // when + ResultActions perform = mockMvc.perform(get("/event/rush/today") + .header("Authorization", accessToken) + .contentType(MediaType.APPLICATION_JSON)); + + // then + perform.andExpect(status().isOk()) + .andExpect(jsonPath("$.leftOption.mainText").value("leftMainText")) + .andExpect(jsonPath("$.leftOption.subText").value("leftSubText")) + .andExpect(jsonPath("$.rightOption.mainText").value("rightMainText")) + .andExpect(jsonPath("$.rightOption.subText").value("rightSubText")) .andDo(print()); } -} \ No newline at end of file + + + @Test + @DisplayName("응모 성공 테스트 - Option ID 2") + public void applyRushEvent_Success() throws Exception { + String accessToken = this.accessToken; + int optionId = 2; + + ResultActions perform = mockMvc.perform(post("/event/rush/options/{optionId}/apply", optionId) + .header("Authorization", accessToken) + .contentType(MediaType.APPLICATION_JSON)); + + perform.andExpect(status().isNoContent()) // 204 No Content 응답 확인 + .andDo(print()); +} + + @Test + @DisplayName("응모 실패 테스트 - Option ID 1") + public void applyRushEvent_Failure_AlreadyApplied() throws Exception { + String accessToken = this.accessToken; + int optionId = 1; + + ResultActions perform = mockMvc.perform(post("/event/rush/options/{optionId}/apply", optionId) + .header("Authorization", accessToken) + .contentType(MediaType.APPLICATION_JSON)); + + perform.andExpect(status().isConflict()) // 409 Conflict 응답 확인 + .andExpect(jsonPath("$.errorCode").value("CONFLICT")) + .andExpect(jsonPath("$.message").value("이미 응모한 회원입니다.")) + .andDo(print()); + } + + @Test + @DisplayName("선택지 결과 조회 성공 테스트") + public void getResultOptionTest() throws Exception { + // given + String accessToken = this.accessToken; + + int optionId = 1; + + // when + ResultActions perform = mockMvc.perform(get("/event/rush/options/{optionId}/result", optionId) + .header("Authorization", accessToken) + .contentType(MediaType.APPLICATION_JSON)); + + // then + perform.andExpect(status().isOk()) + .andExpect(jsonPath("$.mainText").value("mainText")) + .andExpect(jsonPath("$.resultMainText").value("resultMainText")) + .andExpect(jsonPath("$.resultSubText").value("resultSubText")) + .andDo(print()); + } + + @Test + @DisplayName("밸런스 게임 비율 조회 API 테스트") + public void getRushEventRateTest() throws Exception { + // given + String accessToken = this.accessToken; + + // when + ResultActions perform = mockMvc.perform(get("/event/rush/balance") + .header("Authorization", accessToken) + .contentType(MediaType.APPLICATION_JSON)); + + // then + perform.andExpect(status().isOk()) + .andExpect(jsonPath("$.optionId").value(1)) + .andExpect(jsonPath("$.leftOption").value(315)) + .andExpect(jsonPath("$.rightOption").value(1000)) + .andDo(print()); + } + + @Test + @DisplayName("밸런스 게임 최종 결과 조회 API 테스트") + public void getRushEventResultTest() throws Exception { + // given + String accessToken = this.accessToken; + + // when + ResultActions perform = mockMvc.perform(get("/event/rush/result") + .header("Authorization", accessToken) + .contentType(MediaType.APPLICATION_JSON)); + + // then + perform.andExpect(status().isOk()) + .andExpect(jsonPath("$.leftOption").value(315)) + .andExpect(jsonPath("$.rightOption").value(1000)) + .andExpect(jsonPath("$.rank").value(1)) + .andExpect(jsonPath("$.totalParticipants").value(1000)) + .andExpect(jsonPath("$.winnerCount").value(315)) + .andDo(print()); + } + + private String getToken(String phoneNumber) throws Exception { + String requestBody = String.format(""" + { + "phoneNumber": "%s" + } + """, phoneNumber); + + ResultActions perform = mockMvc.perform(post("/event/auth") + .contentType(MediaType.APPLICATION_JSON) + .content(requestBody)); + + String jsonString = perform.andReturn().getResponse().getContentAsString(); + String tokenPrefix = "\"accessToken\":\""; + int start = jsonString.indexOf(tokenPrefix) + tokenPrefix.length(); + int end = jsonString.indexOf("\"", start); + + return "Bearer " + jsonString.substring(start, end); + } +} From 6d29479ef0497b47d50e4d5e90f7919982b69885 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 23:36:44 +0900 Subject: [PATCH 151/289] =?UTF-8?q?feat:=20UserLoginDto=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/global/jwt/dto/UserLoginDto.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/dto/UserLoginDto.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/dto/UserLoginDto.java index 4f583765..19baa2b2 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/dto/UserLoginDto.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/dto/UserLoginDto.java @@ -1,8 +1,14 @@ package JGS.CasperEvent.global.jwt.dto; import lombok.Getter; +import lombok.NoArgsConstructor; @Getter +@NoArgsConstructor public class UserLoginDto { String phoneNumber; + + public UserLoginDto(String phoneNumber) { + this.phoneNumber = phoneNumber; + } } From cdd9ded2e3a5eb5f24c5f4c492ce26b6b945b15d Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Mon, 12 Aug 2024 23:37:17 +0900 Subject: [PATCH 152/289] =?UTF-8?q?feat:=20RushEventServiceTest=20?= =?UTF-8?q?=EC=84=A0=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A0=88=EC=9D=B4=EC=96=B4=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=BB=8D=EB=8D=B0=EA=B8=B0?= =?UTF-8?q?=EB=A7=8C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventService/RushEventServiceTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Server/src/test/java/JGS/CasperEvent/domain/event/service/eventService/RushEventServiceTest.java diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/eventService/RushEventServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/eventService/RushEventServiceTest.java new file mode 100644 index 00000000..0c481816 --- /dev/null +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/eventService/RushEventServiceTest.java @@ -0,0 +1,44 @@ +package JGS.CasperEvent.domain.event.service.eventService; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class RushEventServiceTest { + + @Test + void getAllRushEvents() { + } + + @Test + void isExists() { + } + + @Test + void apply() { + } + + @Test + void getRushEventRate() { + } + + @Test + void getRushEventResult() { + } + + @Test + void getTodayRushEvent() { + } + + @Test + void setTodayEventToRedis() { + } + + @Test + void getTodayRushEventOptions() { + } + + @Test + void getRushEventOptionResult() { + } +} \ No newline at end of file From 402d5c851bb147a10a5a3e16e0cb8e7055ff1f41 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 01:22:28 +0900 Subject: [PATCH 153/289] =?UTF-8?q?chore:=20S3=20=EC=97=B0=EA=B2=B0?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20yml=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/src/main/resources/application-prod.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Server/src/main/resources/application-prod.yml b/Server/src/main/resources/application-prod.yml index 65bd582a..b50f593d 100644 --- a/Server/src/main/resources/application-prod.yml +++ b/Server/src/main/resources/application-prod.yml @@ -21,6 +21,15 @@ spring: port: ${SPRING_REDIS_PORT} encryption: key: ${AES_128_ENCRYPTION_KEY} + cloud: + aws: + s3: + bucket: ${S3_IMAGE_SERVER} + region: ap-northeast-2 + credentials: + accessKey: ${AWS_ACCESS_KEY} + secretKey: ${AWS_SECRET_KEY} + client: url: ${CLIENT_URL} From 88991a951a5bada0a0a5245d81820762ba0979ca Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 01:22:43 +0900 Subject: [PATCH 154/289] =?UTF-8?q?chore:=20S3=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EC=9D=98=EC=A1=B4=EC=84=B1=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 --- Server/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/Server/build.gradle b/Server/build.gradle index 68f53cb8..edfad680 100644 --- a/Server/build.gradle +++ b/Server/build.gradle @@ -32,6 +32,7 @@ dependencies { implementation 'io.awspring.cloud:spring-cloud-aws-starter-parameter-store' implementation 'mysql:mysql-connector-java:8.0.33' // MySQL JDBC 드라이버 추가 implementation 'org.springframework.boot:spring-boot-starter-aop' + implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0' From 6015dcaf011e8f2c4ee024acc0898f688af81bde Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 01:23:05 +0900 Subject: [PATCH 155/289] =?UTF-8?q?chore:=20S3=20=EC=A0=91=EA=B7=BC=20?= =?UTF-8?q?=EB=B0=8F=20=EA=B4=80=EB=A6=AC=20=EC=9C=84=ED=95=9C=20S3Config?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/global/config/S3Config.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java b/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java new file mode 100644 index 00000000..2958e31e --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java @@ -0,0 +1,33 @@ +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; + +@Configuration +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(); + }; +} From c6888c7b8506187b97bd936f04c903c840cd23b2 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 01:23:40 +0900 Subject: [PATCH 156/289] =?UTF-8?q?feat:=20RushEvent=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20api=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminController/AdminController.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index be8130eb..84c61e2f 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -2,9 +2,11 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto; 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.RushEventResponseDto; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.global.response.ResponseDto; import jakarta.validation.Valid; @@ -12,6 +14,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -56,4 +59,16 @@ public ResponseEntity getLotteryEventPa .status(HttpStatus.OK) .body(adminService.getLotteryEventParticipants(size, page, phoneNumber)); } + + // 선착순 이벤트 생성 + @PostMapping("/event/rush") + public ResponseEntity createRushEvent( + @RequestPart(value = "dto") RushEventRequestDto rushEventRequestDto, + @RequestPart(value = "prizeImg")MultipartFile prizeImg, + @RequestPart(value = "leftOptionImg")MultipartFile leftOptionImg, + @RequestPart(value = "rightOptionImg")MultipartFile rightOptionImg) { + return ResponseEntity + .status(HttpStatus.CREATED) + .body(adminService.createRushEvent(rushEventRequestDto, prizeImg, leftOptionImg, rightOptionImg)); + } } From b4830139be72c4e62153396b4fc2da595df562ea Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 01:24:44 +0900 Subject: [PATCH 157/289] =?UTF-8?q?feat:=20RushEvent=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 62 ++++++++++++++++++- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index ffbf2085..ddc5de46 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -2,26 +2,37 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventOptionRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; 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.RushEventResponseDto; import JGS.CasperEvent.domain.event.entity.admin.Admin; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; +import JGS.CasperEvent.domain.event.entity.event.RushEvent; +import JGS.CasperEvent.domain.event.entity.event.RushOption; import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import JGS.CasperEvent.domain.event.repository.AdminRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.RushOptionRepository; import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryParticipantsRepository; import JGS.CasperEvent.global.enums.CustomErrorCode; +import JGS.CasperEvent.global.enums.Position; import JGS.CasperEvent.global.enums.Role; import JGS.CasperEvent.global.error.exception.CustomException; import JGS.CasperEvent.global.error.exception.TooManyLotteryEventException; +import JGS.CasperEvent.global.error.exception.TooManyRushEventException; import JGS.CasperEvent.global.response.ResponseDto; +import JGS.CasperEvent.global.service.S3Service; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; import java.time.LocalDateTime; import java.util.ArrayList; @@ -34,7 +45,10 @@ public class AdminService { private final AdminRepository adminRepository; private final LotteryEventRepository lotteryEventRepository; + private final RushEventRepository rushEventRepository; private final LotteryParticipantsRepository lotteryParticipantsRepository; + private final RushOptionRepository rushOptionRepository; + private final S3Service s3Service; public Admin verifyAdmin(AdminRequestDto adminRequestDto) { return adminRepository.findById(adminRequestDto.getAdminId()).orElseThrow(NoSuchElementException::new); @@ -78,9 +92,6 @@ public LotteryEventParticipantsListResponseDto getLotteryEventParticipants(int s if (phoneNumber.isEmpty()) lotteryParticipantsPage = lotteryParticipantsRepository.findAll(pageable); else lotteryParticipantsRepository.findByBaseUser_Id(phoneNumber, pageable); - for (LotteryParticipants participants : lotteryParticipantsPage) { - System.out.println("participants = " + participants); - } List lotteryEventParticipantsResponseDtoList = new ArrayList<>(); for (LotteryParticipants lotteryParticipant : lotteryParticipantsPage) { @@ -91,4 +102,49 @@ public LotteryEventParticipantsListResponseDto getLotteryEventParticipants(int s Boolean isLastPage = !lotteryParticipantsPage.hasNext(); return new LotteryEventParticipantsListResponseDto(lotteryEventParticipantsResponseDtoList, isLastPage, lotteryParticipantsRepository.count()); } + + public RushEventResponseDto createRushEvent(RushEventRequestDto rushEventRequestDto, MultipartFile prizeImg, MultipartFile leftOptionImg, MultipartFile rightOptionImg) { + if (rushEventRepository.count() >= 6) throw new TooManyRushEventException(); + + String prizeImgSrc = s3Service.upload(prizeImg); + String leftOptionImgSrc = s3Service.upload(leftOptionImg); + String rightOptionImgSrc = s3Service.upload(rightOptionImg); + + // Img s3 저장 + RushEvent rushEvent = rushEventRepository.save( + new RushEvent( + LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getStartTime()), + LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getEndTime()), + rushEventRequestDto.getWinnerCount(), + prizeImgSrc, + rushEventRequestDto.getPrizeDescription() + )); + + RushEventOptionRequestDto leftOption = rushEventRequestDto.getLeftOption(); + RushEventOptionRequestDto rightOption = rushEventRequestDto.getRightOption(); + + RushOption leftRushOption = rushOptionRepository.save(new RushOption( + rushEvent, + leftOption.getMainText(), + leftOption.getSubText(), + leftOption.getResultMainText(), + leftOption.getResultSubText(), + leftOptionImgSrc, + Position.LEFT + )); + + RushOption rightRushOption = rushOptionRepository.save(new RushOption( + rushEvent, + rightOption.getMainText(), + rightOption.getSubText(), + rightOption.getResultMainText(), + rightOption.getResultSubText(), + rightOptionImgSrc, + Position.RIGHT + )); + + rushEvent.updateOption(leftRushOption, rightRushOption); + + return RushEventResponseDto.of(rushEvent); + } } From af95c0ba89444c453e6749b212ce1fa0494b0a5a Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 01:25:13 +0900 Subject: [PATCH 158/289] =?UTF-8?q?feat:=20RushEvent=20=EC=84=A0=ED=83=9D?= =?UTF-8?q?=EC=A7=80=20=EC=88=98=EC=A0=95=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/domain/event/entity/event/RushEvent.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java index 47481951..8407f308 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java @@ -36,9 +36,15 @@ public RushEvent(String prizeImageUrl, String prizeDescription) { } - public RushEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, int winnerCount, String prizeImageUrl, String prizeDescription) { + public RushEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, + int winnerCount, String prizeImageUrl, String prizeDescription) { super(startDateTime, endDateTime, winnerCount); this.prizeImageUrl = prizeImageUrl; this.prizeDescription = prizeDescription; } + + public void updateOption(RushOption leftOption, RushOption rightOption){ + this.options.add(leftOption); + this.options.add(rightOption); + } } From 6b4629f759f7cc0bb11a33ab980c075dd3cbfe88 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 01:25:53 +0900 Subject: [PATCH 159/289] =?UTF-8?q?feat:=20S3=20=EB=B2=84=ED=82=B7=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?=EB=B0=8F=20=EC=82=AD=EC=A0=9C=20=EB=A1=9C=EC=A7=81=EC=9D=84=20?= =?UTF-8?q?=ED=8F=AC=ED=95=A8=ED=95=98=EB=8A=94=20S3Service=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/global/service/S3Service.java | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/service/S3Service.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/service/S3Service.java b/Server/src/main/java/JGS/CasperEvent/global/service/S3Service.java new file mode 100644 index 00000000..48b7744c --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/service/S3Service.java @@ -0,0 +1,110 @@ +package JGS.CasperEvent.global.service; + +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.model.*; +import com.amazonaws.util.IOUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLDecoder; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.UUID; + +@RequiredArgsConstructor +@Component +public class S3Service { + + private final AmazonS3 amazonS3; + + @Value("${spring.cloud.aws.s3.bucket}") + private String bucketName; + + public String upload(MultipartFile image) { + if (image.isEmpty() || Objects.isNull(image.getOriginalFilename())) + throw new AmazonS3Exception("파일이 유효하지 않습니다."); + return this.uploadImage(image); + } + + private String uploadImage(MultipartFile image) { + this.validateImageFileExtension(image.getOriginalFilename()); + try { + return this.uploadImageToS3(image); + } catch (IOException e) { + throw new AmazonS3Exception("io exception on image upload"); + } + } + + private void validateImageFileExtension(String filename) { + int lastDotIndex = filename.lastIndexOf("."); + if (lastDotIndex == -1) { + throw new AmazonS3Exception("파일에 확장자가 존재하지 않습니다."); + } + + String extension = filename.substring(lastDotIndex + 1).toLowerCase(); + List allowedExtentionList = Arrays.asList("jpg", "jpeg", "png", "gif"); + + if (!allowedExtentionList.contains(extension)) { + throw new AmazonS3Exception("유효하지 않은 확장자입니다."); + } + } + + private String uploadImageToS3(MultipartFile image) throws IOException { + String originalFilename = image.getOriginalFilename(); //원본 파일 명 + String extension = Objects.requireNonNull(originalFilename).substring(originalFilename.lastIndexOf(".") + 1); //확장자 명 + + String s3FileName = "image/" + UUID.randomUUID().toString().substring(0, 10) + originalFilename; //변경된 파일 명 + + InputStream is = image.getInputStream(); + byte[] bytes = IOUtils.toByteArray(is); + + ObjectMetadata metadata = new ObjectMetadata(); //metadata 생성 + metadata.setContentType("image/" + extension); + metadata.setContentLength(bytes.length); + + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); + + try { + PutObjectRequest putObjectRequest = + new PutObjectRequest(bucketName, s3FileName, byteArrayInputStream, metadata); +// .withCannedAcl(CannedAccessControlList.PublicRead); + //실제로 S3에 이미지 데이터를 넣는 부분이다. + amazonS3.putObject(putObjectRequest); // put image to S3 + } catch (Exception e) { + throw new AmazonS3Exception("이미지 업로드에 실패했습니다."); + } finally { + byteArrayInputStream.close(); + is.close(); + } + + return amazonS3.getUrl(bucketName, s3FileName).toString(); + } + + public void deleteImageFromS3(String imageAddress) { + String key = getKeyFromImageAddress(imageAddress); + try { + amazonS3.deleteObject(new DeleteObjectRequest(bucketName, key)); + } catch (Exception e) { + throw new AmazonS3Exception("이미지 삭제에 실패했습니다."); + } + } + + private String getKeyFromImageAddress(String imageAddress) { + try { + URL url = new URL(imageAddress); + String decodingKey = URLDecoder.decode(url.getPath(), "UTF-8"); + return decodingKey.substring(1); // 맨 앞의 '/' 제거 + } catch (MalformedURLException | UnsupportedEncodingException e) { + throw new AmazonS3Exception("이미지 삭제에 실패했습니다."); + } + } +} From 3739d3bc1fa1e174d9bcb339efab284369c42770 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 01:26:35 +0900 Subject: [PATCH 160/289] =?UTF-8?q?chore:=20=ED=8C=8C=EC=8B=B1=EC=8B=9C=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D=ED=95=98=EB=8A=94=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/global/enums/CustomErrorCode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index 49ccd332..24d8db6d 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -21,7 +21,8 @@ public enum CustomErrorCode { TODAY_RUSH_EVENT_NOT_FOUND("오늘의 이벤트를 찾을 수 없습니다.", 404), LOTTERY_EVENT_ALREADY_EXISTS("추첨 이벤트가 이미 존재합니다.", 409), INVALID_RUSH_EVENT_OPTIONS_COUNT("이벤트의 옵션 수가 올바르지 않습니다.", 500), - INVALID_RUSH_EVENT_OPTION_ID("옵션 ID는 1 또는 2여야 합니다.", 400); + INVALID_RUSH_EVENT_OPTION_ID("옵션 ID는 1 또는 2여야 합니다.", 400), + EMPTY_FILE("유효하지 않은 파일입니다.", 422); private final String message; private int status; From 848e0bbe6578807f8684db2adcd75609cd3d5969 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 01:27:18 +0900 Subject: [PATCH 161/289] =?UTF-8?q?chore:=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=EC=97=90=207=EA=B0=9C=20=EC=9D=B4?= =?UTF-8?q?=EC=83=81=EC=9D=98=20=EC=84=A0=EC=B0=A9=EC=88=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EC=83=9D=EC=84=B1=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=EC=9D=B4=20=EC=9E=88=EC=9D=84=EB=95=8C=20TooManyRushEventExcep?= =?UTF-8?q?tion=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/JGS/CasperEvent/global/config/S3Config.java | 2 +- .../global/error/exception/TooManyRushEventException.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/error/exception/TooManyRushEventException.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java b/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java index 2958e31e..66ba1e03 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java +++ b/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java @@ -29,5 +29,5 @@ public AmazonS3 amazonS3(){ .withCredentials(new AWSStaticCredentialsProvider(credentials)) .withRegion(region) .build(); - }; + } } diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/exception/TooManyRushEventException.java b/Server/src/main/java/JGS/CasperEvent/global/error/exception/TooManyRushEventException.java new file mode 100644 index 00000000..8f48f25d --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/error/exception/TooManyRushEventException.java @@ -0,0 +1,4 @@ +package JGS.CasperEvent.global.error.exception; + +public class TooManyRushEventException extends RuntimeException{ +} From cd0fc8f0982315b79fafad9152e5085f7d39ce55 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 10:57:15 +0900 Subject: [PATCH 162/289] =?UTF-8?q?chore:=20application-prod.yml=EC=97=90?= =?UTF-8?q?=20=ED=81=AC=EB=A0=88=EB=8D=B4=EC=85=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/src/main/resources/application-prod.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Server/src/main/resources/application-prod.yml b/Server/src/main/resources/application-prod.yml index b50f593d..ebe677d7 100644 --- a/Server/src/main/resources/application-prod.yml +++ b/Server/src/main/resources/application-prod.yml @@ -26,9 +26,6 @@ spring: s3: bucket: ${S3_IMAGE_SERVER} region: ap-northeast-2 - credentials: - accessKey: ${AWS_ACCESS_KEY} - secretKey: ${AWS_SECRET_KEY} client: From 7d425211c97a54b84c7019b20cb86bf49e034b4f Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 10:57:50 +0900 Subject: [PATCH 163/289] =?UTF-8?q?feat:=20S3Client=20=EB=94=94=ED=8F=B4?= =?UTF-8?q?=ED=8A=B8=20=ED=81=B4=EB=9D=BC=EC=9D=B4=EC=96=B8=ED=8A=B8=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/global/config/S3Config.java | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java b/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java index 66ba1e03..39fba5fc 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java +++ b/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java @@ -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(); } -} +} \ No newline at end of file From 1f570ce4ae24749bab207452a0be344823e9fbdd Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 10:58:37 +0900 Subject: [PATCH 164/289] =?UTF-8?q?feat:=20=EB=A1=9C=EC=BB=AC=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=9A=A9=20S3config=20=EB=B6=84=EB=A6=AC?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/config/LocalS3Config.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/config/LocalS3Config.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/config/LocalS3Config.java b/Server/src/main/java/JGS/CasperEvent/global/config/LocalS3Config.java new file mode 100644 index 00000000..699f98d3 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/config/LocalS3Config.java @@ -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(); + } +} From 7c965e52def350d7d4d370534f8da807f86ddfc1 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 10:58:51 +0900 Subject: [PATCH 165/289] =?UTF-8?q?feat:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20=ED=91=9C=ED=98=84=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?Enum=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/global/enums/EventStatus.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/enums/EventStatus.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/EventStatus.java b/Server/src/main/java/JGS/CasperEvent/global/enums/EventStatus.java new file mode 100644 index 00000000..84ddd1c0 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/EventStatus.java @@ -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; + } +} From 420d924a9a804b3106fc8a04aa699da8f585d2e4 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 11:00:04 +0900 Subject: [PATCH 166/289] =?UTF-8?q?feat:=20=EB=B0=98=ED=99=98=20=ED=98=95?= =?UTF-8?q?=EC=8B=9D=EC=97=90=20=EB=A7=9E=EA=B2=8C=20RushEventOptionRespon?= =?UTF-8?q?seDto=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RushEventOptionResponseDto.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java index 6b6b6625..6f28f0b1 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java @@ -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() ); } + } From c8a780df12aa7f832f31374db93a994d3d7ec57a Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 11:00:56 +0900 Subject: [PATCH 167/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=A0=84=EC=B2=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/adminController/AdminController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 84c61e2f..8f8d71d8 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -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; @@ -71,4 +72,12 @@ public ResponseEntity createRushEvent( .status(HttpStatus.CREATED) .body(adminService.createRushEvent(rushEventRequestDto, prizeImg, leftOptionImg, rightOptionImg)); } + + // 선착순 이벤트 전체 조회 + @GetMapping("/event/rush") + public ResponseEntity> getRushEvents(){ + return ResponseEntity + .status(HttpStatus.OK) + .body(adminService.getRushEvents()); + } } From 994dd3b25abd34c74d99d3aa54c433dfdaaf478d Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 11:01:11 +0900 Subject: [PATCH 168/289] =?UTF-8?q?feat:=20RushEvent=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=EC=9A=A9=20AdminRushEventResponseDto=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminRushEventResponseDto.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/AdminRushEventResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/AdminRushEventResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/AdminRushEventResponseDto.java new file mode 100644 index 00000000..cfdda64c --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/AdminRushEventResponseDto.java @@ -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 options) { + + public static List of(List rushEvents) { + List dtoList = new ArrayList<>(); + for (RushEvent rushEvent : rushEvents) { + Set 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; + } +} From dde40bcc3d9f2d96591db61aa1ba9a158d1d1683 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 11:01:23 +0900 Subject: [PATCH 169/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=A0=84=EC=B2=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/service/adminService/AdminService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index ddc5de46..f7643022 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -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; @@ -147,4 +148,9 @@ public RushEventResponseDto createRushEvent(RushEventRequestDto rushEventRequest return RushEventResponseDto.of(rushEvent); } + + public List getRushEvents(){ + List rushEvents = rushEventRepository.findAll(); + return AdminRushEventResponseDto.of(rushEvents); + } } From 3581694d7ce9edda3e4f34203864c072ede99958 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 11:21:11 +0900 Subject: [PATCH 170/289] =?UTF-8?q?feat:=20s3Config=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/JGS/CasperEvent/global/config/S3Config.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java b/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java index 39fba5fc..428ab1f4 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java +++ b/Server/src/main/java/JGS/CasperEvent/global/config/S3Config.java @@ -2,6 +2,7 @@ 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; @@ -9,8 +10,12 @@ @Configuration @Profile("prod") public class S3Config { + @Value("${spring.cloud.aws.s3.region}") + private String region; @Bean public AmazonS3 amazonS3(){ - return AmazonS3ClientBuilder.defaultClient(); + return AmazonS3ClientBuilder.standard() + .withRegion(region) + .build(); } } \ No newline at end of file From e4d3765fdfbb298a54a44f3877836eb41a9cc11f Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 11:26:39 +0900 Subject: [PATCH 171/289] =?UTF-8?q?chore:=20@Component=20->=20@Service?= =?UTF-8?q?=EB=A1=9C=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/JGS/CasperEvent/global/service/S3Service.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/service/S3Service.java b/Server/src/main/java/JGS/CasperEvent/global/service/S3Service.java index 48b7744c..87531748 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/service/S3Service.java +++ b/Server/src/main/java/JGS/CasperEvent/global/service/S3Service.java @@ -5,7 +5,7 @@ import com.amazonaws.util.IOUtils; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.ByteArrayInputStream; @@ -21,7 +21,7 @@ import java.util.UUID; @RequiredArgsConstructor -@Component +@Service public class S3Service { private final AmazonS3 amazonS3; From ab0e5918ed1b18c90271bc18da0c47428a1aed94 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 11:49:37 +0900 Subject: [PATCH 172/289] =?UTF-8?q?chore:=20Json=EC=A7=81=EB=A0=AC?= =?UTF-8?q?=ED=99=94,=20=EC=97=AD=EC=A7=81=EB=A0=AC=ED=99=94=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RushEventParticipantsListResponseDto.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantsListResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantsListResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantsListResponseDto.java new file mode 100644 index 00000000..d41e8af6 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantsListResponseDto.java @@ -0,0 +1,4 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; + +public class RushEventParticipantsListResponseDto { +} From 66539a254a425cf0062551a016e1792f0f994306 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 12:03:22 +0900 Subject: [PATCH 173/289] =?UTF-8?q?chore:=20Json=EC=A7=81=EB=A0=AC?= =?UTF-8?q?=ED=99=94,=20=EC=97=AD=EC=A7=81=EB=A0=AC=ED=99=94=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RushEventOptionResponseDto.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java index 6f28f0b1..5d09bf73 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java @@ -2,13 +2,23 @@ import JGS.CasperEvent.domain.event.entity.event.RushOption; import JGS.CasperEvent.global.enums.Position; +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 java.time.LocalDateTime; public record RushEventOptionResponseDto(long optionId, String mainText, String subText, String resultMainText, String resultSubText, String imageUrl, - Position position, LocalDateTime createdAt, LocalDateTime updatedAt) { + Position position, + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonDeserialize(using = LocalDateTimeDeserializer.class) + LocalDateTime createdAt, + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonDeserialize(using = LocalDateTimeDeserializer.class) + LocalDateTime updatedAt) { public static RushEventOptionResponseDto of(RushOption rushOption) { return new RushEventOptionResponseDto( rushOption.getOptionId(), From 1e87352e24df7225748c07c25ac15cc7fd13b759 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 12:04:35 +0900 Subject: [PATCH 174/289] =?UTF-8?q?chore:=20Json=EC=A7=81=EB=A0=AC?= =?UTF-8?q?=ED=99=94,=20=EC=97=AD=EC=A7=81=EB=A0=AC=ED=99=94=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rushEventResponseDto/RushEventResponseDto.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventResponseDto.java index 8aaf4cee..b73c65ae 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventResponseDto.java @@ -13,12 +13,12 @@ public record RushEventResponseDto(Long rushEventId, @JsonSerialize(using = LocalDateTimeSerializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class) - LocalDateTime startDateTime, + @JsonSerialize(using = LocalDateTimeSerializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class) - LocalDateTime endDateTime, + int winnerCount, String prizeImageUrl, String prizeDescription, Set options){ From 72a62fb9fc60800561bf37241e989225e5f20ddf Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 15:34:20 +0900 Subject: [PATCH 175/289] =?UTF-8?q?feat:=20Admin=20LotteryEvent=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminController/AdminController.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 8f8d71d8..a0ada693 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -65,9 +65,9 @@ public ResponseEntity getLotteryEventPa @PostMapping("/event/rush") public ResponseEntity createRushEvent( @RequestPart(value = "dto") RushEventRequestDto rushEventRequestDto, - @RequestPart(value = "prizeImg")MultipartFile prizeImg, - @RequestPart(value = "leftOptionImg")MultipartFile leftOptionImg, - @RequestPart(value = "rightOptionImg")MultipartFile rightOptionImg) { + @RequestPart(value = "prizeImg") MultipartFile prizeImg, + @RequestPart(value = "leftOptionImg") MultipartFile leftOptionImg, + @RequestPart(value = "rightOptionImg") MultipartFile rightOptionImg) { return ResponseEntity .status(HttpStatus.CREATED) .body(adminService.createRushEvent(rushEventRequestDto, prizeImg, leftOptionImg, rightOptionImg)); @@ -75,9 +75,16 @@ public ResponseEntity createRushEvent( // 선착순 이벤트 전체 조회 @GetMapping("/event/rush") - public ResponseEntity> getRushEvents(){ + public ResponseEntity> getRushEvents() { return ResponseEntity .status(HttpStatus.OK) .body(adminService.getRushEvents()); } + + // 추첨 이벤트 삭제 + @DeleteMapping("/event/lottery") + public ResponseEntity deleteLotteryEvent() { + adminService.deleteLotteryEvent(); + return ResponseEntity.noContent().build(); // 204 No Content + } } From f88ad304388020860d203d859293533106919fb5 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 15:34:41 +0900 Subject: [PATCH 176/289] =?UTF-8?q?feat:=20Admin=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=8B=9C=20=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8?= =?UTF-8?q?=EA=B9=8C=EC=A7=80=20=EA=B0=99=EC=9D=B4=20=EA=B2=80=EC=A6=9D?= =?UTF-8?q?=ED=95=98=EB=8A=94=20JPA=20=EA=B8=B0=EB=B3=B8=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/domain/event/repository/AdminRepository.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/AdminRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/AdminRepository.java index cec89467..d7189cc0 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/AdminRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/AdminRepository.java @@ -4,6 +4,9 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.Optional; + @Repository public interface AdminRepository extends JpaRepository { + Optional findByIdAndPassword(String id, String password); } From 6ff1ebc0825ce8783c880ee207036867b923eac2 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 15:35:13 +0900 Subject: [PATCH 177/289] =?UTF-8?q?feat:=20Admin=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=8B=9C=20=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8?= =?UTF-8?q?=EA=B9=8C=EC=A7=80=20=EA=B0=99=EC=9D=B4=20=EA=B2=80=EC=A6=9D?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20?= =?UTF-8?q?=EC=B6=94=EC=B2=A8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20API=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/adminService/AdminService.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index f7643022..fc71182d 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -52,7 +52,7 @@ public class AdminService { private final S3Service s3Service; public Admin verifyAdmin(AdminRequestDto adminRequestDto) { - return adminRepository.findById(adminRequestDto.getAdminId()).orElseThrow(NoSuchElementException::new); + return adminRepository.findByIdAndPassword(adminRequestDto.getAdminId(), adminRequestDto.getPassword()).orElseThrow(NoSuchElementException::new); } public ResponseDto postAdmin(AdminRequestDto adminRequestDto) { @@ -153,4 +153,18 @@ public List getRushEvents(){ List rushEvents = rushEventRepository.findAll(); return AdminRushEventResponseDto.of(rushEvents); } + + public void deleteLotteryEvent() { + List lotteryEventList = lotteryEventRepository.findAll(); + + if (lotteryEventList.isEmpty()) { + throw new CustomException("현재 진행중인 lotteryEvent가 존재하지 않습니다.", CustomErrorCode.NO_LOTTERY_EVENT); + } + + if (lotteryEventList.size() > 1) { + throw new CustomException("현재 진행중인 lotteryEvent가 1개 이상입니다.", CustomErrorCode.TOO_MANY_LOTTERY_EVENT); + } + + lotteryEventRepository.deleteAll(); + } } From c9715488b711a2b22ffc013ebffe76b97d70d159 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 15:35:36 +0900 Subject: [PATCH 178/289] =?UTF-8?q?feat:=20LotteryEvent=EA=B0=80=202?= =?UTF-8?q?=EA=B0=9C=20=EC=9D=B4=EC=83=81=EC=9D=BC=20=EB=95=8C=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=EC=8B=9C=ED=82=AC=20CustomErrorCode=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 --- .../java/JGS/CasperEvent/global/enums/CustomErrorCode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index 24d8db6d..bb487359 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -22,7 +22,8 @@ public enum CustomErrorCode { LOTTERY_EVENT_ALREADY_EXISTS("추첨 이벤트가 이미 존재합니다.", 409), INVALID_RUSH_EVENT_OPTIONS_COUNT("이벤트의 옵션 수가 올바르지 않습니다.", 500), INVALID_RUSH_EVENT_OPTION_ID("옵션 ID는 1 또는 2여야 합니다.", 400), - EMPTY_FILE("유효하지 않은 파일입니다.", 422); + EMPTY_FILE("유효하지 않은 파일입니다.", 422), + TOO_MANY_LOTTERY_EVENT("현재 진행중인 추첨 이벤트가 2개 이상입니다.", 409); private final String message; private int status; From 8d3d8eeba940a15eafce264c29992be5b3cc574d Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 15:38:55 +0900 Subject: [PATCH 179/289] =?UTF-8?q?fix:=20=EA=B8=B0=EC=A1=B4=20=EB=AC=B4?= =?UTF-8?q?=EC=A1=B0=EA=B1=B4=20id=20=EA=B0=92=EC=9D=B4=201=EC=9D=B8=20Lot?= =?UTF-8?q?teryEvent=EB=A5=BC=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventService/LotteryEventService.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 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 a6fb31bc..59baa705 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 @@ -29,6 +29,7 @@ import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.time.LocalDateTime; +import java.util.List; import java.util.Optional; @Service @@ -45,7 +46,18 @@ public class LotteryEventService { 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); + + List lotteryEventList = lotteryEventRepository.findAll(); + + if (lotteryEventList.isEmpty()) { + throw new CustomException("현재 진행중인 lotteryEvent가 존재하지 않습니다.", CustomErrorCode.NO_LOTTERY_EVENT); + } + + if (lotteryEventList.size() > 1) { + throw new CustomException("현재 진행중인 lotteryEvent가 1개 이상입니다.", CustomErrorCode.TOO_MANY_LOTTERY_EVENT); + } + + LotteryEvent lotteryEvent = lotteryEventList.get(0); CasperBot casperBot = casperBotRepository.save(new CasperBot(casperBotRequestDto, user.getId())); lotteryEvent.addAppliedCount(); @@ -100,8 +112,17 @@ public LotteryParticipants registerUserIfNeed(BaseUser user, CasperBotRequestDto } public LotteryEventResponseDto getLotteryEvent() { - LotteryEvent lotteryEvent = lotteryEventRepository.findById(1L).orElseThrow(LotteryEventNotExists::new); + List lotteryEventList = lotteryEventRepository.findAll(); + + if (lotteryEventList.isEmpty()) { + throw new CustomException("현재 진행중인 lotteryEvent가 존재하지 않습니다.", CustomErrorCode.NO_LOTTERY_EVENT); + } + + if (lotteryEventList.size() > 1) { + throw new CustomException("현재 진행중인 lotteryEvent가 1개 이상입니다.", CustomErrorCode.TOO_MANY_LOTTERY_EVENT); + } + + LotteryEvent lotteryEvent = lotteryEventList.get(0); return LotteryEventResponseDto.of(lotteryEvent, LocalDateTime.now()); } - } From a740121db4f285247b3ae32e51c2c12f86ac5316 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 15:43:32 +0900 Subject: [PATCH 180/289] =?UTF-8?q?fix:=20=EC=97=90=EB=9F=AC=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/service/adminService/AdminService.java | 2 +- .../event/service/eventService/LotteryEventService.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index fc71182d..f9b0ef3d 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -162,7 +162,7 @@ public void deleteLotteryEvent() { } if (lotteryEventList.size() > 1) { - throw new CustomException("현재 진행중인 lotteryEvent가 1개 이상입니다.", CustomErrorCode.TOO_MANY_LOTTERY_EVENT); + throw new CustomException("현재 진행중인 lotteryEvent가 2개 이상입니다.", CustomErrorCode.TOO_MANY_LOTTERY_EVENT); } lotteryEventRepository.deleteAll(); 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 59baa705..c5a3c572 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 @@ -54,7 +54,7 @@ public CasperBotResponseDto postCasperBot(BaseUser user, CasperBotRequestDto cas } if (lotteryEventList.size() > 1) { - throw new CustomException("현재 진행중인 lotteryEvent가 1개 이상입니다.", CustomErrorCode.TOO_MANY_LOTTERY_EVENT); + throw new CustomException("현재 진행중인 lotteryEvent가 2개 이상입니다.", CustomErrorCode.TOO_MANY_LOTTERY_EVENT); } LotteryEvent lotteryEvent = lotteryEventList.get(0); @@ -119,7 +119,7 @@ public LotteryEventResponseDto getLotteryEvent() { } if (lotteryEventList.size() > 1) { - throw new CustomException("현재 진행중인 lotteryEvent가 1개 이상입니다.", CustomErrorCode.TOO_MANY_LOTTERY_EVENT); + throw new CustomException("현재 진행중인 lotteryEvent가 2개 이상입니다.", CustomErrorCode.TOO_MANY_LOTTERY_EVENT); } LotteryEvent lotteryEvent = lotteryEventList.get(0); From 814c5d7190116f044bd306e546fde64bcf9e8ed3 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 16:13:46 +0900 Subject: [PATCH 181/289] =?UTF-8?q?feat:=20=EC=A1=B0=EA=B1=B4=EB=B3=84=20?= =?UTF-8?q?=EC=84=A0=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B0=B8=EC=97=AC=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RushParticipantsRepository.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java index f53b74f7..138802b7 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java @@ -1,6 +1,8 @@ package JGS.CasperEvent.domain.event.repository.participantsRepository; import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -9,7 +11,7 @@ import java.util.Optional; @Repository -public interface RushParticipantsRepository extends JpaRepository { +public interface RushParticipantsRepository extends JpaRepository { boolean existsByRushEvent_RushEventIdAndBaseUser_Id(Long eventId, String userId); long countByRushEvent_RushEventIdAndOptionId(Long eventId, int optionId); @Query("SELECT COUNT(rp) + 1 FROM RushParticipants rp " + @@ -25,4 +27,12 @@ long findUserRankByEventIdAndUserIdAndOptionId(@Param("eventId") Long eventId, @Query("SELECT rp.optionId FROM RushParticipants rp WHERE rp.baseUser.id = :userId") Optional getOptionIdByUserId(@Param("userId") String userId); + Page findByRushEvent_RushEventId(Long rushEventId, Pageable pageable); + + Page findByRushEvent_RushEventIdAndBaseUser_Id(Long rushEventId, String baseUser_id, Pageable pageable); + + Page findByRushEvent_RushEventIdAndOptionId(Long rushEventId, int optionId, Pageable pageable); + + Page findByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(Long rushEventId, int optionId, String baseUser_id, Pageable pageable); + } From 2788793df167343286a963d02ab823c6f83596fc Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 16:14:01 +0900 Subject: [PATCH 182/289] =?UTF-8?q?feat:=20@Getter=20=EC=96=B4=EB=85=B8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/participants/RushParticipants.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/RushParticipants.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/RushParticipants.java index d3d5b213..94111d30 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/RushParticipants.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/RushParticipants.java @@ -1,12 +1,15 @@ package JGS.CasperEvent.domain.event.entity.participants; import JGS.CasperEvent.domain.event.entity.event.RushEvent; +import JGS.CasperEvent.global.entity.BaseEntity; import JGS.CasperEvent.global.entity.BaseUser; import com.fasterxml.jackson.annotation.JsonBackReference; import jakarta.persistence.*; +import lombok.Getter; @Entity -public class RushParticipants { +@Getter +public class RushParticipants extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; From 5170bf4512aad105a6eb67f11f467fef5c272d8e Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 16:14:33 +0900 Subject: [PATCH 183/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=B0=B8=EC=97=AC=EC=9E=90=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EB=B0=98=ED=99=98=EC=9A=A9=20Rus?= =?UTF-8?q?hEventParticipantListResponseDto=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RushEventParticipantsListResponseDto.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantsListResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantsListResponseDto.java index d41e8af6..655c4b2e 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantsListResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantsListResponseDto.java @@ -1,4 +1,5 @@ package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; -public class RushEventParticipantsListResponseDto { +import java.util.List; +public record RushEventParticipantsListResponseDto(List participantsList, Boolean isLastPage, long totalParticipants) { } From f0cb006520b159a68ca72be83022c5ef79858edb Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 16:14:50 +0900 Subject: [PATCH 184/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=B0=B8=EC=97=AC=EC=9E=90=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=EC=9A=A9=20RushEventParticipantResponseDto?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RushEventParticipantResponseDto.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java new file mode 100644 index 00000000..5dd6362e --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java @@ -0,0 +1,20 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; + +import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; + +import java.time.LocalDateTime; + +public record RushEventParticipantResponseDto(Long id, String phoneNumber, + int balanceGameChoice, LocalDateTime createdAt, LocalDateTime updatedAt, + Long rank) { + public static RushEventParticipantResponseDto of(RushParticipants rushParticipants, Long rank){ + return new RushEventParticipantResponseDto( + rushParticipants.getId(), + rushParticipants.getBaseUser().getId(), + rushParticipants.getOptionId(), + rushParticipants.getCreatedAt(), + rushParticipants.getUpdatedAt(), + rank + ); + } +} From ad565f857d8f35c06220770cbd3565507b231ff5 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 16:15:16 +0900 Subject: [PATCH 185/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=B0=B8=EC=97=AC=EC=9E=90=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20=ED=8E=98=EC=9D=B4=EC=A7=80=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EC=85=98,=20=EA=B2=80=EC=83=89=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 47 +++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index f7643022..a665b91a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -9,17 +9,21 @@ 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.RushEventParticipantResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantsListResponseDto; 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; import JGS.CasperEvent.domain.event.entity.event.RushEvent; import JGS.CasperEvent.domain.event.entity.event.RushOption; import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; +import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; import JGS.CasperEvent.domain.event.repository.AdminRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.RushOptionRepository; import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryParticipantsRepository; +import JGS.CasperEvent.domain.event.repository.participantsRepository.RushParticipantsRepository; import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.Position; import JGS.CasperEvent.global.enums.Role; @@ -48,6 +52,7 @@ public class AdminService { private final LotteryEventRepository lotteryEventRepository; private final RushEventRepository rushEventRepository; private final LotteryParticipantsRepository lotteryParticipantsRepository; + private final RushParticipantsRepository rushParticipantsRepository; private final RushOptionRepository rushOptionRepository; private final S3Service s3Service; @@ -80,9 +85,9 @@ public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lottery return LotteryEventResponseDto.of(lotteryEvent, LocalDateTime.now()); } - public List getLotteryEvent() { + public LotteryEventDetailResponseDto getLotteryEvent() { return LotteryEventDetailResponseDto.of( - lotteryEventRepository.findAll() + lotteryEventRepository.findAll().get(0) ); } @@ -149,8 +154,44 @@ public RushEventResponseDto createRushEvent(RushEventRequestDto rushEventRequest return RushEventResponseDto.of(rushEvent); } - public List getRushEvents(){ + public List getRushEvents() { List rushEvents = rushEventRepository.findAll(); return AdminRushEventResponseDto.of(rushEvents); } + + public RushEventParticipantsListResponseDto getRushEventParticipants(long rushEventId, int size, int page, int optionId, String phoneNumber) { + Pageable pageable = PageRequest.of(page, size); + + Page rushParticipantsPage = null; + + boolean isPhoneNumberEmpty = phoneNumber.isEmpty(); + boolean isOptionIdValid = optionId == 1 || optionId == 2; + + if (!isPhoneNumberEmpty && isOptionIdValid) { + // 전화번호와 유효한 옵션 ID가 있는 경우 + rushParticipantsPage = rushParticipantsRepository.findByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(rushEventId, optionId, phoneNumber, pageable); + } else if (isPhoneNumberEmpty && !isOptionIdValid) { + // 전화번호가 비어있고 유효하지 않은 옵션 ID가 있는 경우 + rushParticipantsPage = rushParticipantsRepository.findByRushEvent_RushEventId(rushEventId, pageable); + } else if (isOptionIdValid) { + // 유효한 옵션 ID가 있지만 전화번호는 비어있는 경우 + rushParticipantsPage = rushParticipantsRepository.findByRushEvent_RushEventIdAndOptionId(rushEventId, optionId, pageable); + } else { + // 유효하지 않은 옵션 ID와 전화번호가 주어진 경우 + rushParticipantsPage = rushParticipantsRepository.findByRushEvent_RushEventIdAndBaseUser_Id(rushEventId, phoneNumber, pageable); + } + + List rushEventParticipantResponseDtoList = new ArrayList<>(); + for (RushParticipants rushParticipant : rushParticipantsPage) { + String userId = rushParticipant.getBaseUser().getId(); + int userChoice = rushParticipant.getOptionId(); + long rank = rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(rushEventId, userId, userChoice); + rushEventParticipantResponseDtoList.add( + RushEventParticipantResponseDto.of(rushParticipant, rank) + ); + } + + Boolean isLastPage = !rushParticipantsPage.hasNext(); + return new RushEventParticipantsListResponseDto(rushEventParticipantResponseDtoList, isLastPage, rushParticipantsRepository.count()); + } } From f54835213d114898eed4864eecf734d3a2f6d7c5 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 16:15:25 +0900 Subject: [PATCH 186/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=B0=B8=EC=97=AC=EC=9E=90=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminController/AdminController.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 8f8d71d8..61aa06e6 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -7,6 +7,7 @@ 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.RushEventParticipantsListResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventResponseDto; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.global.response.ResponseDto; @@ -35,7 +36,7 @@ public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto // 추첨 이벤트 조회 @GetMapping("/event/lottery") - public ResponseEntity> getLotteryEvent() { + public ResponseEntity getLotteryEvent() { return ResponseEntity .status(HttpStatus.OK) .body(adminService.getLotteryEvent()); @@ -65,9 +66,9 @@ public ResponseEntity getLotteryEventPa @PostMapping("/event/rush") public ResponseEntity createRushEvent( @RequestPart(value = "dto") RushEventRequestDto rushEventRequestDto, - @RequestPart(value = "prizeImg")MultipartFile prizeImg, - @RequestPart(value = "leftOptionImg")MultipartFile leftOptionImg, - @RequestPart(value = "rightOptionImg")MultipartFile rightOptionImg) { + @RequestPart(value = "prizeImg") MultipartFile prizeImg, + @RequestPart(value = "leftOptionImg") MultipartFile leftOptionImg, + @RequestPart(value = "rightOptionImg") MultipartFile rightOptionImg) { return ResponseEntity .status(HttpStatus.CREATED) .body(adminService.createRushEvent(rushEventRequestDto, prizeImg, leftOptionImg, rightOptionImg)); @@ -75,9 +76,22 @@ public ResponseEntity createRushEvent( // 선착순 이벤트 전체 조회 @GetMapping("/event/rush") - public ResponseEntity> getRushEvents(){ + public ResponseEntity> getRushEvents() { return ResponseEntity .status(HttpStatus.OK) .body(adminService.getRushEvents()); } + + // 선착순 이벤트 참여자 조회 + @GetMapping("/event/rush/{rushEventId}/participants") + public ResponseEntity getRushEventParticipants( + @PathVariable("rushEventId") Long rushEventId, + @RequestParam(name = "size", required = false, defaultValue = "10") int size, + @RequestParam(name = "page", required = false, defaultValue = "0") int page, + @RequestParam(name = "option", required = false, defaultValue = "0") int option, + @RequestParam(name = "number", required = false, defaultValue = "") String phoneNumber) { + return ResponseEntity + .status(HttpStatus.OK) + .body(adminService.getRushEventParticipants(rushEventId, size, page, option, phoneNumber)); + } } From 651ab67854a9b43bd3d1575331403122396144a4 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 16:16:21 +0900 Subject: [PATCH 187/289] =?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=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EC=A7=84=ED=96=89=EC=83=81=ED=99=A9=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=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 --- .../LotteryEventDetailResponseDto.java | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventDetailResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventDetailResponseDto.java index f3180f07..d7237273 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventDetailResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventDetailResponseDto.java @@ -1,32 +1,37 @@ package JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; +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; public record LotteryEventDetailResponseDto( LocalDate startDate, LocalTime startTime, LocalDate endDate, LocalTime endTime, int appliedCount, int winnerCount, + EventStatus status, LocalDateTime createdAt, LocalDateTime updatedAt) { - public static ArrayList of(List lotteryEvent) { - ArrayList lotteryEventDtoList = new ArrayList<>(); - for (LotteryEvent event : lotteryEvent) { - lotteryEventDtoList.add(new LotteryEventDetailResponseDto( - event.getStartDateTime().toLocalDate(), - event.getStartDateTime().toLocalTime(), - event.getEndDateTime().toLocalDate(), - event.getEndDateTime().toLocalTime(), - event.getTotalAppliedCount(), - event.getWinnerCount(), - event.getCreatedAt(), - event.getUpdatedAt())); - } - return lotteryEventDtoList; + public static LotteryEventDetailResponseDto of(LotteryEvent event) { + + EventStatus status; + LocalDateTime now = LocalDateTime.now(); + + if (now.isBefore(event.getStartDateTime())) status = EventStatus.BEFORE; + else if (now.isAfter(event.getEndDateTime())) status = EventStatus.AFTER; + else status = EventStatus.DURING; + + return new LotteryEventDetailResponseDto( + event.getStartDateTime().toLocalDate(), + event.getStartDateTime().toLocalTime(), + event.getEndDateTime().toLocalDate(), + event.getEndDateTime().toLocalTime(), + event.getTotalAppliedCount(), + event.getWinnerCount(), + status, + event.getCreatedAt(), + event.getUpdatedAt()); } } From 379b9949729b5bcf48f27c75d3f82f802a6c525a Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 18:20:44 +0900 Subject: [PATCH 188/289] =?UTF-8?q?feat:=20=EC=96=B4=EB=93=9C=EB=AF=BC=20?= =?UTF-8?q?=EC=B6=94=EC=B2=A8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/adminController/AdminController.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 853b1548..ca82a574 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -9,6 +9,7 @@ import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantsListResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventResponseDto; +import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.global.response.ResponseDto; import jakarta.validation.Valid; @@ -25,6 +26,7 @@ @RequiredArgsConstructor public class AdminController { private final AdminService adminService; + private final LotteryEventRepository lotteryEventRepository; // 어드민 생성 @PostMapping("/join") @@ -103,4 +105,12 @@ public ResponseEntity deleteLotteryEvent() { return ResponseEntity.noContent().build(); // 204 No Content } + + // 추첨 이벤트 수정 + @PutMapping("/event/lottery") + public ResponseEntity updateLotteryEvent(@RequestBody @Valid LotteryEventRequestDto lotteryEventRequestDto) { + LotteryEventDetailResponseDto updatedLotteryEventDetailResponseDto = adminService.updateLotteryEvent(lotteryEventRequestDto); + + return ResponseEntity.ok(updatedLotteryEventDetailResponseDto); + } } From 6c5a151192f2542591e2c769b42e4dc016a0bdf9 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 18:26:21 +0900 Subject: [PATCH 189/289] =?UTF-8?q?feat:=20=EC=96=B4=EB=93=9C=EB=AF=BC=20?= =?UTF-8?q?=EC=B6=94=EC=B2=A8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=9E=91=EC=84=B1,=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 56 +++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 70d4e7b6..69ca4d18 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -37,6 +37,7 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import java.time.LocalDateTime; @@ -77,8 +78,8 @@ public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lottery if (lotteryEventRepository.count() >= 1) throw new TooManyLotteryEventException(); LotteryEvent lotteryEvent = lotteryEventRepository.save(new LotteryEvent( - lotteryEventRequestDto.getEventStartDateTime(), - lotteryEventRequestDto.getEventEndDateTime(), + LocalDateTime.of(lotteryEventRequestDto.getEventStartDate(), lotteryEventRequestDto.getEventStartTime()), + LocalDateTime.of(lotteryEventRequestDto.getEventEndDate(), lotteryEventRequestDto.getEventEndTime()), lotteryEventRequestDto.getWinnerCount() )); @@ -87,7 +88,7 @@ public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lottery public LotteryEventDetailResponseDto getLotteryEvent() { return LotteryEventDetailResponseDto.of( - lotteryEventRepository.findAll().get(0) + getCurrentLotteryEvent() ); } @@ -194,8 +195,53 @@ public RushEventParticipantsListResponseDto getRushEventParticipants(long rushEv Boolean isLastPage = !rushParticipantsPage.hasNext(); return new RushEventParticipantsListResponseDto(rushEventParticipantResponseDtoList, isLastPage, rushParticipantsRepository.count()); } - + + @Transactional public void deleteLotteryEvent() { + LotteryEvent currentLotteryEvent = getCurrentLotteryEvent(); + lotteryEventRepository.deleteById(currentLotteryEvent.getLotteryEventId()); + } + + @Transactional + public LotteryEventDetailResponseDto updateLotteryEvent(LotteryEventRequestDto lotteryEventRequestDto) { + LotteryEvent currentLotteryEvent = getCurrentLotteryEvent(); + + LocalDateTime now = LocalDateTime.now(); + LocalDateTime newStartDateTime = LocalDateTime.of(lotteryEventRequestDto.getEventStartDate(), lotteryEventRequestDto.getEventStartTime()); + LocalDateTime newEndDateTime = LocalDateTime.of(lotteryEventRequestDto.getEventEndDate(), lotteryEventRequestDto.getEventEndTime()); + + // 종료 날짜가 시작 날짜보다 뒤인지 체크 + if (newEndDateTime.isBefore(newStartDateTime)) { + throw new CustomException(CustomErrorCode.EVENT_END_TIME_BEFORE_START_TIME); + } + + if (currentLotteryEvent.getStartDateTime().isBefore(now) && currentLotteryEvent.getEndDateTime().isAfter(now)) { + // 현재 진행 중인 이벤트인 경우 + if (!currentLotteryEvent.getStartDateTime().equals(newStartDateTime)) { + throw new CustomException(CustomErrorCode.EVENT_IN_PROGRESS_CANNOT_CHANGE_START_TIME); + } + if (newEndDateTime.isBefore(now)) { + throw new CustomException(CustomErrorCode.EVENT_IN_PROGRESS_END_TIME_BEFORE_NOW); + } + } + + // 이벤트가 시작 전인 경우 + else if (newStartDateTime.isBefore(now)) { + throw new CustomException(CustomErrorCode.EVENT_BEFORE_START_TIME); + } + + // 필드 업데이트 + currentLotteryEvent.setStartDateTime(newStartDateTime); + currentLotteryEvent.setEndDateTime(newEndDateTime); + currentLotteryEvent.setWinnerCount(lotteryEventRequestDto.getWinnerCount()); + + // 저장 + lotteryEventRepository.save(currentLotteryEvent); + + return LotteryEventDetailResponseDto.of(currentLotteryEvent); + } + + private LotteryEvent getCurrentLotteryEvent() { List lotteryEventList = lotteryEventRepository.findAll(); if (lotteryEventList.isEmpty()) { @@ -206,6 +252,6 @@ public void deleteLotteryEvent() { throw new CustomException("현재 진행중인 lotteryEvent가 2개 이상입니다.", CustomErrorCode.TOO_MANY_LOTTERY_EVENT); } - lotteryEventRepository.deleteAll(); + return lotteryEventList.get(0); } } From 0e66a560cea82bc0af1ab01be2ebdbac473b26ff Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 18:28:07 +0900 Subject: [PATCH 190/289] =?UTF-8?q?fix:=20update=EB=A5=BC=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20BaseEvent=20=ED=81=B4=EB=9E=98=EC=8A=A4=EC=97=90=20?= =?UTF-8?q?@Setter=20=EC=B6=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/domain/event/entity/event/BaseEvent.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java index e5933697..9ebf46fc 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/BaseEvent.java @@ -7,10 +7,12 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import jakarta.persistence.MappedSuperclass; import lombok.Getter; +import lombok.Setter; import java.time.LocalDateTime; @Getter +@Setter @MappedSuperclass public class BaseEvent extends BaseEntity { @JsonSerialize(using = LocalDateTimeSerializer.class) From f80e0b12a032aa9281e5089a878919b1cb392ef5 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 18:30:53 +0900 Subject: [PATCH 191/289] =?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=88=98=EC=A0=95=20=EC=8B=9C=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=EC=8B=9C=ED=82=AC=20CustomErrorCode=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 --- .../java/JGS/CasperEvent/global/enums/CustomErrorCode.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index bb487359..76eaadbf 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -23,7 +23,12 @@ public enum CustomErrorCode { INVALID_RUSH_EVENT_OPTIONS_COUNT("이벤트의 옵션 수가 올바르지 않습니다.", 500), INVALID_RUSH_EVENT_OPTION_ID("옵션 ID는 1 또는 2여야 합니다.", 400), EMPTY_FILE("유효하지 않은 파일입니다.", 422), - TOO_MANY_LOTTERY_EVENT("현재 진행중인 추첨 이벤트가 2개 이상입니다.", 409); + TOO_MANY_LOTTERY_EVENT("현재 진행중인 추첨 이벤트가 2개 이상입니다.", 409), + EVENT_IN_PROGRESS_CANNOT_CHANGE_START_TIME("현재 진행 중인 이벤트의 시작 시간을 변경할 수 없습니다.", 400), + EVENT_IN_PROGRESS_END_TIME_BEFORE_NOW("현재 진행 중인 이벤트의 종료 시간을 현재 시간보다 이전으로 설정할 수 없습니다.", 400), + EVENT_BEFORE_START_TIME("이벤트 시작 시간은 현재 시간 이후로 설정해야 합니다.", 400), + EVENT_END_TIME_BEFORE_START_TIME("종료 시간은 시작 시간 이후로 설정해야 합니다.", 400); + private final String message; private int status; From e304ad16c756c3bf9a726847f06537e59536f56c Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 18:31:16 +0900 Subject: [PATCH 192/289] =?UTF-8?q?feat:=20CustomException=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=EC=8B=9C=ED=82=AC=20=EB=95=8C=20CurtomErrorCode?= =?UTF-8?q?=EB=A7=8C=20=EC=9D=B8=EC=9E=90=EB=A1=9C=20=EB=B0=9B=EB=8A=94=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/error/exception/CustomException.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/exception/CustomException.java b/Server/src/main/java/JGS/CasperEvent/global/error/exception/CustomException.java index 6005e4e5..75eae33f 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/error/exception/CustomException.java +++ b/Server/src/main/java/JGS/CasperEvent/global/error/exception/CustomException.java @@ -1,7 +1,9 @@ package JGS.CasperEvent.global.error.exception; import JGS.CasperEvent.global.enums.CustomErrorCode; +import lombok.Getter; +@Getter public class CustomException extends RuntimeException { private final CustomErrorCode errorCode; @@ -10,7 +12,9 @@ public CustomException(String message, CustomErrorCode errorCode) { this.errorCode = errorCode; } - public CustomErrorCode getErrorCode() { - return errorCode; + public CustomException(CustomErrorCode errorCode) { + super(errorCode.getMessage()); + this.errorCode = errorCode; } + } From 8b5afa3827967f6144a88359ae22c5b6729ea0bb Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 18:31:45 +0900 Subject: [PATCH 193/289] =?UTF-8?q?fix:=20LotteryEventRequestDto=20?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=82=A0=EC=A7=9C=EC=99=80=20=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=EC=9D=84=20=EB=B6=84=EB=A6=AC=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lotteryEventDto/LotteryEventRequestDto.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/LotteryEventRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/LotteryEventRequestDto.java index 39149522..c04b978e 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/LotteryEventRequestDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/LotteryEventRequestDto.java @@ -3,16 +3,23 @@ import jakarta.validation.constraints.NotNull; import lombok.Getter; -import java.time.LocalDateTime; +import java.time.LocalDate; +import java.time.LocalTime; @Getter public class LotteryEventRequestDto { - @NotNull(message = "이벤트 시작 일자를 지정하세요.") - private LocalDateTime eventStartDateTime; + @NotNull(message = "이벤트 시작 날짜를 지정하세요.") + private LocalDate eventStartDate; - @NotNull(message = "이벤트 종료 일자를 지정하세요.") - private LocalDateTime eventEndDateTime; + @NotNull(message = "이벤트 시작 시간을 지정하세요.") + private LocalTime eventStartTime; + + @NotNull(message = "이벤트 종료 날짜를 지정하세요.") + private LocalDate eventEndDate; + + @NotNull(message = "이벤트 시작 시간을 지정하세요.") + private LocalTime eventEndTime; @NotNull(message = "당첨인원 수를 지정하세요.") private int winnerCount; From 005fcfe40a163839da04ad99f0a8643f401a53ae Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 20:57:26 +0900 Subject: [PATCH 194/289] =?UTF-8?q?chore:=20=EC=84=A0=ED=83=9D=EC=A7=80?= =?UTF-8?q?=EB=A5=BC=20Json=EC=9C=BC=EB=A1=9C=20=EB=94=B0=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=ED=95=98=EB=8A=94=20=EB=B0=A9=EC=8B=9D?= =?UTF-8?q?=EC=97=90=EC=84=9C=20Set=EC=9C=BC=EB=A1=9C=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rushEventDto/RushEventRequestDto.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventRequestDto.java index fc3405b4..43b61643 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventRequestDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventRequestDto.java @@ -1,22 +1,35 @@ package JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto; -import com.fasterxml.jackson.annotation.JsonProperty; +import JGS.CasperEvent.global.enums.CustomErrorCode; +import JGS.CasperEvent.global.enums.Position; +import JGS.CasperEvent.global.error.exception.CustomException; import lombok.Getter; import lombok.ToString; import java.time.LocalDate; import java.time.LocalTime; +import java.util.Set; @ToString @Getter public class RushEventRequestDto { + private Long rushEventId; private LocalDate eventDate; private LocalTime startTime; private LocalTime endTime; private int winnerCount; private String prizeDescription; - @JsonProperty("leftOption") - private RushEventOptionRequestDto leftOption; - @JsonProperty("rightOption") - private RushEventOptionRequestDto rightOption; + private Set options; + + public RushEventOptionRequestDto getLeftOption() { + return options.stream() + .filter(option -> option.getPosition() == Position.LEFT) + .findFirst().orElseThrow(() -> new CustomException(CustomErrorCode.INVALID_RUSH_EVENT_OPTION)); + } + + public RushEventOptionRequestDto getRightOption() { + return options.stream() + .filter(option -> option.getPosition() == Position.RIGHT) + .findFirst().orElseThrow(() -> new CustomException(CustomErrorCode.INVALID_RUSH_EVENT_OPTION)); + } } From 02e83a156fdf0efb2d01e76bca186f929a858b0b Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 20:58:36 +0900 Subject: [PATCH 195/289] =?UTF-8?q?chore:=20RushEventOptionRequestDto=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80=20-=20Position:=20?= =?UTF-8?q?=EC=99=BC=EC=AA=BD=20=EC=98=A4=EB=A5=B8=EC=AA=BD=20=EA=B5=AC?= =?UTF-8?q?=EB=B6=84=20=EA=B0=80=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/RequestDto/rushEventDto/RushEventOptionRequestDto.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventOptionRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventOptionRequestDto.java index 90dd2549..5ad53826 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventOptionRequestDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventOptionRequestDto.java @@ -1,11 +1,14 @@ package JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto; +import JGS.CasperEvent.global.enums.Position; import lombok.Getter; import lombok.ToString; @ToString @Getter public class RushEventOptionRequestDto { + private Long rushOptionId; + private Position position; private String mainText; private String subText; private String resultMainText; From 118dd9f91c7e12870df1d609e492ebe51f171b53 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 20:59:11 +0900 Subject: [PATCH 196/289] =?UTF-8?q?refactor:=20updateOption=20->=20addOpti?= =?UTF-8?q?on=EC=9C=BC=EB=A1=9C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/domain/event/entity/event/RushEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java index 8407f308..dbdf7279 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java @@ -43,7 +43,7 @@ public RushEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, this.prizeDescription = prizeDescription; } - public void updateOption(RushOption leftOption, RushOption rightOption){ + public void addOption(RushOption leftOption, RushOption rightOption){ this.options.add(leftOption); this.options.add(rightOption); } From 15f64849669690589adf60750c35888c4e4b6f8a Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 20:59:39 +0900 Subject: [PATCH 197/289] =?UTF-8?q?feat:=20=EC=84=A0=ED=83=9D=EC=A7=80?= =?UTF-8?q?=EA=B0=80=20=EC=9C=A0=ED=9A=A8=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=9D=84=20=EB=95=8C=20=EB=B0=9C=EC=83=9D=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/global/enums/CustomErrorCode.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index 76eaadbf..cd1b74eb 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -27,7 +27,9 @@ public enum CustomErrorCode { EVENT_IN_PROGRESS_CANNOT_CHANGE_START_TIME("현재 진행 중인 이벤트의 시작 시간을 변경할 수 없습니다.", 400), EVENT_IN_PROGRESS_END_TIME_BEFORE_NOW("현재 진행 중인 이벤트의 종료 시간을 현재 시간보다 이전으로 설정할 수 없습니다.", 400), EVENT_BEFORE_START_TIME("이벤트 시작 시간은 현재 시간 이후로 설정해야 합니다.", 400), - EVENT_END_TIME_BEFORE_START_TIME("종료 시간은 시작 시간 이후로 설정해야 합니다.", 400); + EVENT_END_TIME_BEFORE_START_TIME("종료 시간은 시작 시간 이후로 설정해야 합니다.", 400), + INVALID_RUSH_EVENT_OPTION("밸런스 게임 선택지가 유효하지 않습니다."); + private final String message; From 03fcb68220fa8a4eea08b848aea68a836c8e5c87 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 21:16:41 +0900 Subject: [PATCH 198/289] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20S?= =?UTF-8?q?3=EC=A3=BC=EC=86=8C=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20Im?= =?UTF-8?q?ageUrlResponseDto=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/dto/ResponseDto/ImageUrlResponseDto.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/ImageUrlResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/ImageUrlResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/ImageUrlResponseDto.java new file mode 100644 index 00000000..d1c49e1d --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/ImageUrlResponseDto.java @@ -0,0 +1,4 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto; + +public record ImageUrlResponseDto(String imageUrl) { +} From 1b0001e49a7564a34eade98926ab5e6862837040 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 21:20:02 +0900 Subject: [PATCH 199/289] =?UTF-8?q?feat:=20=EC=A0=84=EB=8B=AC=EB=B0=9B?= =?UTF-8?q?=EC=9D=80=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20S3=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/adminService/AdminService.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 69ca4d18..e6b971cf 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -4,6 +4,7 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventOptionRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.ImageUrlResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsListResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsResponseDto; @@ -74,6 +75,10 @@ public ResponseDto postAdmin(AdminRequestDto adminRequestDto) { return ResponseDto.of("관리자 생성 성공"); } + public ImageUrlResponseDto postImage(MultipartFile image){ + return new ImageUrlResponseDto(s3Service.upload(image)); + } + public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lotteryEventRequestDto) { if (lotteryEventRepository.count() >= 1) throw new TooManyLotteryEventException(); @@ -150,7 +155,7 @@ public RushEventResponseDto createRushEvent(RushEventRequestDto rushEventRequest Position.RIGHT )); - rushEvent.updateOption(leftRushOption, rightRushOption); + rushEvent.addOption(leftRushOption, rightRushOption); return RushEventResponseDto.of(rushEvent); } @@ -254,4 +259,10 @@ private LotteryEvent getCurrentLotteryEvent() { return lotteryEventList.get(0); } + + public List updateRushEvents(List rushEventRequestDtoList, List images) { + LocalDateTime now = LocalDateTime.now(); + + return null; + } } From 9a6a4fbd24127696065616dfb9cd01ac66fbe729 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 21:20:36 +0900 Subject: [PATCH 200/289] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20S?= =?UTF-8?q?3=EB=B2=84=ED=82=B7=EC=97=90=20=EC=97=85=EB=A1=9C=EB=93=9C?= =?UTF-8?q?=ED=95=98=EB=8A=94=20API=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminController/AdminController.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index ca82a574..4c29ef1d 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -3,6 +3,7 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.ImageUrlResponseDto; 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; @@ -36,6 +37,16 @@ public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto .body(adminService.postAdmin(adminRequestDto)); } + // 이미지 업로드 + @PostMapping("/image") + public ResponseEntity postImage( + @RequestPart(value = "image") MultipartFile image){ + return ResponseEntity + .status(HttpStatus.CREATED) + .body(adminService.postImage(image)); + + } + // 추첨 이벤트 조회 @GetMapping("/event/lottery") public ResponseEntity getLotteryEvent() { @@ -84,7 +95,6 @@ public ResponseEntity> getRushEvents() { .body(adminService.getRushEvents()); } - // 선착순 이벤트 참여자 조회 @GetMapping("/event/rush/{rushEventId}/participants") public ResponseEntity getRushEventParticipants( @@ -98,6 +108,17 @@ public ResponseEntity getRushEventParticip .body(adminService.getRushEventParticipants(rushEventId, size, page, option, phoneNumber)); } + // 선착순 이벤트 수정 + @PutMapping("/event/rush") + public ResponseEntity> updateRushEvent( + @RequestPart(name = "json") List rushEventListRequestDto, + @RequestPart(name = "images") List images + ) { + return ResponseEntity + .status(HttpStatus.OK) + .body(adminService.updateRushEvents(rushEventListRequestDto, images)); + } + // 추첨 이벤트 삭제 @DeleteMapping("/event/lottery") public ResponseEntity deleteLotteryEvent() { From 2b067cb09beb270e0a763965bcbce97cbc8423a8 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 22:30:58 +0900 Subject: [PATCH 201/289] =?UTF-8?q?feat:=20=EC=84=A0=ED=83=9D=EC=A7=80=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/event/RushOption.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java index 08470d02..fbea57fe 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java @@ -1,5 +1,6 @@ package JGS.CasperEvent.domain.event.entity.event; +import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventOptionRequestDto; import JGS.CasperEvent.global.entity.BaseEntity; import JGS.CasperEvent.global.enums.Position; import com.fasterxml.jackson.annotation.JsonBackReference; @@ -37,4 +38,13 @@ public RushOption(RushEvent rushEvent, String mainText, String subText, String r this.imageUrl = imageUrl; this.position = position; } + + public RushOption updateRushOption(RushEventOptionRequestDto requestDto) { + this.mainText = requestDto.getMainText(); + this.subText = requestDto.getSubText(); + this.resultMainText = requestDto.getResultMainText(); + this.resultSubText = requestDto.getResultSubText(); + this.imageUrl = requestDto.getImageUrl(); + return this; + } } From a5881f97bbe516f8bba3943d06e40ea428fda155 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 22:31:28 +0900 Subject: [PATCH 202/289] =?UTF-8?q?feat:=20RushEventRequestDto=EC=97=90=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rushEventDto/RushEventRequestDto.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventRequestDto.java index 43b61643..ed21c1b9 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventRequestDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventRequestDto.java @@ -3,6 +3,7 @@ import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.Position; import JGS.CasperEvent.global.error.exception.CustomException; +import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.ToString; @@ -12,22 +13,38 @@ @ToString @Getter +//todo 검증 항목 추가 필요 public class RushEventRequestDto { + @NotNull(message = "선착순 이벤트 아이디는 필수 항목입니다.") private Long rushEventId; + + @NotNull(message = "이벤트 시작 날짜는 필수 항목입니다.") private LocalDate eventDate; + + @NotNull(message = "이벤트 시작 시간은 필수 항목입니다.") private LocalTime startTime; + + @NotNull(message = "이벤트 종료 시간 필수 항목입니다.") private LocalTime endTime; + + @NotNull(message = "당첨자 수는 필수 항목입니다.") private int winnerCount; + + @NotNull(message = "상품 사진은 필수 항목입니다.") + private String prizeImageUrl; + + @NotNull(message = "상품 상세 정보는 필수 항목입니다.") private String prizeDescription; + private Set options; - public RushEventOptionRequestDto getLeftOption() { + public RushEventOptionRequestDto getLeftOptionRequestDto() { return options.stream() .filter(option -> option.getPosition() == Position.LEFT) .findFirst().orElseThrow(() -> new CustomException(CustomErrorCode.INVALID_RUSH_EVENT_OPTION)); } - public RushEventOptionRequestDto getRightOption() { + public RushEventOptionRequestDto getRightOptionRequestDto() { return options.stream() .filter(option -> option.getPosition() == Position.RIGHT) .findFirst().orElseThrow(() -> new CustomException(CustomErrorCode.INVALID_RUSH_EVENT_OPTION)); From 9b0c181254393e2c7983f5b0e30665c242e15960 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 22:31:50 +0900 Subject: [PATCH 203/289] =?UTF-8?q?feat:=20RushEventOptionRequestDto?= =?UTF-8?q?=EC=97=90=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20url=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/RequestDto/rushEventDto/RushEventOptionRequestDto.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventOptionRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventOptionRequestDto.java index 5ad53826..bdc49e20 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventOptionRequestDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/rushEventDto/RushEventOptionRequestDto.java @@ -13,4 +13,5 @@ public class RushEventOptionRequestDto { private String subText; private String resultMainText; private String resultSubText; + private String imageUrl; } From 799a4c68ef62e298f49640060c2d53fe3f857075 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 22:35:43 +0900 Subject: [PATCH 204/289] =?UTF-8?q?feat:=20RushEvent=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EB=A1=9C=EC=A7=81=EA=B3=BC=20=EC=84=A0?= =?UTF-8?q?=ED=83=9D=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/event/RushEvent.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java index dbdf7279..ee1bde7a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java @@ -1,6 +1,10 @@ package JGS.CasperEvent.domain.event.entity.event; +import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto; import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; +import JGS.CasperEvent.global.enums.CustomErrorCode; +import JGS.CasperEvent.global.enums.Position; +import JGS.CasperEvent.global.error.exception.CustomException; import com.fasterxml.jackson.annotation.JsonManagedReference; import jakarta.persistence.*; import lombok.Getter; @@ -43,8 +47,29 @@ public RushEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, this.prizeDescription = prizeDescription; } - public void addOption(RushOption leftOption, RushOption rightOption){ + public void addOption(RushOption leftOption, RushOption rightOption) { this.options.add(leftOption); this.options.add(rightOption); } + + public RushEvent updateRushEvent(RushEventRequestDto requestDto) { + this.startDateTime = LocalDateTime.of(requestDto.getEventDate(), requestDto.getStartTime()); + this.endDateTime = LocalDateTime.of(requestDto.getEventDate(), requestDto.getEndTime()); + this.winnerCount = requestDto.getWinnerCount(); + this.prizeDescription = requestDto.getPrizeDescription(); + this.prizeImageUrl = requestDto.getPrizeImageUrl(); + return this; + } + + public RushOption getLeftOption() { + return options.stream() + .filter(option -> option.getPosition() == Position.LEFT) + .findFirst().orElseThrow(() -> new CustomException(CustomErrorCode.INVALID_RUSH_EVENT_OPTION)); + } + + public RushOption getRightOption() { + return options.stream() + .filter(option -> option.getPosition() == Position.RIGHT) + .findFirst().orElseThrow(() -> new CustomException(CustomErrorCode.INVALID_RUSH_EVENT_OPTION)); + } } From f3044a80828fe838ec1b7ca7bc8bea031604e441 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 22:37:23 +0900 Subject: [PATCH 205/289] =?UTF-8?q?feat:=20RushEvent=20=EC=83=81=EC=84=B8?= =?UTF-8?q?=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20=ED=8F=AC=ED=95=A8=ED=95=98?= =?UTF-8?q?=EB=8A=94=20AdminRushEventResponseDto=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminRushEventResponseDto.java | 52 ++++++++----------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/AdminRushEventResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/AdminRushEventResponseDto.java index cfdda64c..459d710e 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/AdminRushEventResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/AdminRushEventResponseDto.java @@ -6,8 +6,6 @@ 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; @@ -16,35 +14,29 @@ public record AdminRushEventResponseDto(Long rushEventId, LocalDate eventDate, int winnerCount, String prizeImageUrl, String prizeDescription, LocalDateTime createdAt, LocalDateTime updatedAt, EventStatus status, Set options) { + public static AdminRushEventResponseDto of(RushEvent rushEvent){ + Set options = rushEvent.getOptions().stream() + .map(RushEventOptionResponseDto::of) + .collect(Collectors.toSet()); - public static List of(List rushEvents) { - List dtoList = new ArrayList<>(); - for (RushEvent rushEvent : rushEvents) { - Set 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; - 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; + return 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 + ); } } From 1250b85c4a6c886df4223dfcee30d929d4c50bd1 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 22:37:37 +0900 Subject: [PATCH 206/289] =?UTF-8?q?feat:=20RushEvent=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=EB=A5=BC=20=EC=88=98=EC=A0=95=ED=95=98=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 64 ++++++++++++++++--- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index e6b971cf..ae13c074 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -12,7 +12,6 @@ import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantsListResponseDto; -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; import JGS.CasperEvent.domain.event.entity.event.RushEvent; @@ -45,6 +44,7 @@ import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; +import java.util.Objects; @RequiredArgsConstructor @Service @@ -75,7 +75,7 @@ public ResponseDto postAdmin(AdminRequestDto adminRequestDto) { return ResponseDto.of("관리자 생성 성공"); } - public ImageUrlResponseDto postImage(MultipartFile image){ + public ImageUrlResponseDto postImage(MultipartFile image) { return new ImageUrlResponseDto(s3Service.upload(image)); } @@ -115,7 +115,7 @@ public LotteryEventParticipantsListResponseDto getLotteryEventParticipants(int s return new LotteryEventParticipantsListResponseDto(lotteryEventParticipantsResponseDtoList, isLastPage, lotteryParticipantsRepository.count()); } - public RushEventResponseDto createRushEvent(RushEventRequestDto rushEventRequestDto, MultipartFile prizeImg, MultipartFile leftOptionImg, MultipartFile rightOptionImg) { + public AdminRushEventResponseDto createRushEvent(RushEventRequestDto rushEventRequestDto, MultipartFile prizeImg, MultipartFile leftOptionImg, MultipartFile rightOptionImg) { if (rushEventRepository.count() >= 6) throw new TooManyRushEventException(); String prizeImgSrc = s3Service.upload(prizeImg); @@ -132,8 +132,8 @@ public RushEventResponseDto createRushEvent(RushEventRequestDto rushEventRequest rushEventRequestDto.getPrizeDescription() )); - RushEventOptionRequestDto leftOption = rushEventRequestDto.getLeftOption(); - RushEventOptionRequestDto rightOption = rushEventRequestDto.getRightOption(); + RushEventOptionRequestDto leftOption = rushEventRequestDto.getLeftOptionRequestDto(); + RushEventOptionRequestDto rightOption = rushEventRequestDto.getRightOptionRequestDto(); RushOption leftRushOption = rushOptionRepository.save(new RushOption( rushEvent, @@ -157,12 +157,16 @@ public RushEventResponseDto createRushEvent(RushEventRequestDto rushEventRequest rushEvent.addOption(leftRushOption, rightRushOption); - return RushEventResponseDto.of(rushEvent); + return AdminRushEventResponseDto.of(rushEvent); } public List getRushEvents() { List rushEvents = rushEventRepository.findAll(); - return AdminRushEventResponseDto.of(rushEvents); + List rushEventResponseDtoList = new ArrayList<>(); + for (RushEvent rushEvent : rushEvents) { + rushEventResponseDtoList.add(AdminRushEventResponseDto.of(rushEvent)); + } + return rushEventResponseDtoList; } public RushEventParticipantsListResponseDto getRushEventParticipants(long rushEventId, int size, int page, int optionId, String phoneNumber) { @@ -260,9 +264,51 @@ private LotteryEvent getCurrentLotteryEvent() { return lotteryEventList.get(0); } - public List updateRushEvents(List rushEventRequestDtoList, List images) { + public List updateRushEvents(List rushEventRequestDtoList) { LocalDateTime now = LocalDateTime.now(); - return null; + for (RushEventRequestDto rushEventRequestDto : rushEventRequestDtoList) { + RushEvent rushEvent = rushEventRepository.findByRushEventId(rushEventRequestDto.getRushEventId()); + + LocalDateTime curStartDateTime = rushEvent.getStartDateTime(); + LocalDateTime curEndDateTime = rushEvent.getEndDateTime(); + LocalDateTime startDateTime = LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getStartTime()); + LocalDateTime endDateTime = LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getEndTime()); + if (!Objects.equals(curStartDateTime, startDateTime) || !Objects.equals(curEndDateTime, endDateTime)) { + // 종료 날짜가 시작 날짜보다 뒤인지 체크 + if (endDateTime.isBefore(startDateTime)) { + throw new CustomException(CustomErrorCode.EVENT_END_TIME_BEFORE_START_TIME); + } + + if (curStartDateTime.isBefore(now) && curEndDateTime.isAfter(now)) { + // 현재 진행 중인 이벤트인 경우 + if (!curStartDateTime.equals(startDateTime)) { + throw new CustomException(CustomErrorCode.EVENT_IN_PROGRESS_CANNOT_CHANGE_START_TIME); + } + if (endDateTime.isBefore(now)) { + throw new CustomException(CustomErrorCode.EVENT_IN_PROGRESS_END_TIME_BEFORE_NOW); + } + } + + // 이벤트가 시작 전인 경우 + else if (startDateTime.isBefore(now)) { + throw new CustomException(CustomErrorCode.EVENT_BEFORE_START_TIME); + } + } + + RushOption leftOption = rushEvent.getLeftOption(); + RushOption rightOption = rushEvent.getRightOption(); + + rushEvent.updateRushEvent(rushEventRequestDto); + leftOption.updateRushOption(rushEventRequestDto.getLeftOptionRequestDto()); + rightOption.updateRushOption(rushEventRequestDto.getRightOptionRequestDto()); + } + + List rushEvents = rushEventRepository.findAll(); + List rushEventResponseDtoList = new ArrayList<>(); + for (RushEvent rushEvent : rushEvents) { + rushEventResponseDtoList.add(AdminRushEventResponseDto.of(rushEvent)); + } + return rushEventResponseDtoList; } } From 88eab8d31d4347f11f1c0ab09f5e6609edb614b0 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Tue, 13 Aug 2024 22:37:49 +0900 Subject: [PATCH 207/289] =?UTF-8?q?feat:=20RushEvent=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20API=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/controller/adminController/AdminController.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 4c29ef1d..d6483cb6 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -77,7 +77,7 @@ public ResponseEntity getLotteryEventPa // 선착순 이벤트 생성 @PostMapping("/event/rush") - public ResponseEntity createRushEvent( + public ResponseEntity createRushEvent( @RequestPart(value = "dto") RushEventRequestDto rushEventRequestDto, @RequestPart(value = "prizeImg") MultipartFile prizeImg, @RequestPart(value = "leftOptionImg") MultipartFile leftOptionImg, @@ -111,12 +111,10 @@ public ResponseEntity getRushEventParticip // 선착순 이벤트 수정 @PutMapping("/event/rush") public ResponseEntity> updateRushEvent( - @RequestPart(name = "json") List rushEventListRequestDto, - @RequestPart(name = "images") List images - ) { + @RequestBody List rushEventListRequestDto) { return ResponseEntity .status(HttpStatus.OK) - .body(adminService.updateRushEvents(rushEventListRequestDto, images)); + .body(adminService.updateRushEvents(rushEventListRequestDto)); } // 추첨 이벤트 삭제 From 86120b5bb09ff82835cb91ad539530544afd2db0 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 23:35:27 +0900 Subject: [PATCH 208/289] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=EC=97=90=EC=84=9C=20=ED=8A=B9=EC=A0=95=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=EC=9D=98=20=EB=AA=A8=EB=93=A0=20?= =?UTF-8?q?=EA=B8=B0=EB=8C=80=ED=8F=89=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/adminController/AdminController.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index d6483cb6..8c160798 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -5,12 +5,11 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.ImageUrlResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventExpectationResponseDto; 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.RushEventParticipantsListResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventResponseDto; -import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.global.response.ResponseDto; import jakarta.validation.Valid; @@ -27,7 +26,6 @@ @RequiredArgsConstructor public class AdminController { private final AdminService adminService; - private final LotteryEventRepository lotteryEventRepository; // 어드민 생성 @PostMapping("/join") @@ -132,4 +130,12 @@ public ResponseEntity updateLotteryEvent(@Request return ResponseEntity.ok(updatedLotteryEventDetailResponseDto); } + + // 추첨 이벤트 특정 사용자의 기대평 조회 + @GetMapping("/event/lottery/participants/{participantId}/expectations") + public ResponseEntity> getLotteryEventExpectations(@PathVariable("participantId") Long participantId) { + List lotteryEventExpectationResponseDtoList = adminService.getLotteryEventExpectations(participantId); + + return ResponseEntity.ok(lotteryEventExpectationResponseDtoList); + } } From e0762eadca3d6b82195764de737ed6e8bc7eeb03 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 23:36:34 +0900 Subject: [PATCH 209/289] =?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=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20?= =?UTF-8?q?=EC=8B=9C=20Setter=20=EC=9D=B4=EC=9A=A9=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EA=B3=A0=20update=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=A5=BC=20=EB=A7=8C=EB=93=A4=EC=96=B4=EC=84=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD,=20?= =?UTF-8?q?=EC=B6=94=EC=B2=A8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=ED=8A=B9=EC=A0=95=20=EC=9C=A0=EC=A0=80=EC=9D=98=20?= =?UTF-8?q?=EB=AA=A8=EB=93=A0=20=EA=B8=B0=EB=8C=80=ED=8F=89=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index ae13c074..65845f6d 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -9,16 +9,19 @@ 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.lotteryEventResponseDto.*; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantsListResponseDto; import JGS.CasperEvent.domain.event.entity.admin.Admin; +import JGS.CasperEvent.domain.event.entity.casperBot.CasperBot; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; import JGS.CasperEvent.domain.event.entity.event.RushEvent; import JGS.CasperEvent.domain.event.entity.event.RushOption; import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; import JGS.CasperEvent.domain.event.repository.AdminRepository; +import JGS.CasperEvent.domain.event.repository.CasperBotRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.RushOptionRepository; @@ -57,6 +60,7 @@ public class AdminService { private final RushParticipantsRepository rushParticipantsRepository; private final RushOptionRepository rushOptionRepository; private final S3Service s3Service; + private final CasperBotRepository casperBotRepository; public Admin verifyAdmin(AdminRequestDto adminRequestDto) { return adminRepository.findByIdAndPassword(adminRequestDto.getAdminId(), adminRequestDto.getPassword()).orElseThrow(NoSuchElementException::new); @@ -240,12 +244,7 @@ else if (newStartDateTime.isBefore(now)) { } // 필드 업데이트 - currentLotteryEvent.setStartDateTime(newStartDateTime); - currentLotteryEvent.setEndDateTime(newEndDateTime); - currentLotteryEvent.setWinnerCount(lotteryEventRequestDto.getWinnerCount()); - - // 저장 - lotteryEventRepository.save(currentLotteryEvent); + currentLotteryEvent.updateLotteryEvent(newStartDateTime, newEndDateTime, lotteryEventRequestDto.getWinnerCount()); return LotteryEventDetailResponseDto.of(currentLotteryEvent); } @@ -311,4 +310,16 @@ else if (startDateTime.isBefore(now)) { } return rushEventResponseDtoList; } + + + public List getLotteryEventExpectations(Long participantId) { + LotteryParticipants lotteryParticipant = lotteryParticipantsRepository.findById(participantId).orElseThrow( + () -> new CustomException(CustomErrorCode.USER_NOT_FOUND) + ); + + List casperBotList = casperBotRepository.findByPhoneNumber(lotteryParticipant.getBaseUser().getId()); + + return casperBotList.stream().map(LotteryEventExpectationResponseDto::of).toList(); + + } } From 6b27c3bffe1a1191c5d8f402ffd0fdd40deb8f16 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 23:37:05 +0900 Subject: [PATCH 210/289] =?UTF-8?q?feat:=20=ED=8A=B9=EC=A0=95=20phoneNumbe?= =?UTF-8?q?r=EB=A5=BC=20=EC=9D=B4=EC=9A=A9=ED=95=98=EC=97=AC=20=ED=95=B4?= =?UTF-8?q?=EB=8B=B9=20=EC=82=AC=EC=9A=A9=EC=9E=90=EA=B0=80=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=ED=95=9C=20=EB=AA=A8=EB=93=A0=20CasperBot=EC=9D=84=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20JPA=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/repository/CasperBotRepository.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java index c96afd56..ebdb75b2 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java @@ -4,6 +4,9 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface CasperBotRepository extends JpaRepository { + List findByPhoneNumber(String phoneNumber); } From f610f4044e41f10e20941059a558fb3458c25cb8 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 23:37:37 +0900 Subject: [PATCH 211/289] =?UTF-8?q?fix:=20LotteryEvent=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EC=8B=9C=20Setter=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=20=EB=B6=80=EB=B6=84=EC=9D=84=20update=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/event/LotteryEvent.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java index 49564eaf..cf4825c1 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java @@ -20,4 +20,11 @@ public LotteryEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, int public LotteryEvent() { } + + public LotteryEvent updateLotteryEvent(LocalDateTime startDateTime, LocalDateTime endDateTime, int winnerCount) { + this.startDateTime = startDateTime; + this.endDateTime = endDateTime; + this.winnerCount = winnerCount; + return this; + } } From acab9fa17ea05c56fd4337106d4ef1e6a6c9cc42 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 23:38:04 +0900 Subject: [PATCH 212/289] =?UTF-8?q?feat:=20=ED=8A=B9=EC=A0=95=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=EC=9D=98=20=EA=B8=B0=EB=8C=80=ED=8F=89?= =?UTF-8?q?=EC=9D=84=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20DTO=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventExpectationResponseDto.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventExpectationResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventExpectationResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventExpectationResponseDto.java new file mode 100644 index 00000000..2d0549c9 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventExpectationResponseDto.java @@ -0,0 +1,24 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto; + +import JGS.CasperEvent.domain.event.entity.casperBot.CasperBot; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; + +public record LotteryEventExpectationResponseDto(String expectation, LocalDate createdDate, + LocalTime createdTime) { + + public static LotteryEventExpectationResponseDto of(CasperBot casperBot) { + + LocalDateTime createdAt = casperBot.getCreatedAt(); + LocalDate createdDate = createdAt.toLocalDate(); + LocalTime createdTime = createdAt.toLocalTime(); + + return new LotteryEventExpectationResponseDto( + casperBot.getExpectation(), + createdDate, + createdTime + ); + } +} From db7b912cd83d85c8496b3654d97596dadd3c8fc5 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 23:38:24 +0900 Subject: [PATCH 213/289] =?UTF-8?q?refactor:=20=EB=B0=98=EB=B3=B5=EB=90=98?= =?UTF-8?q?=EB=8A=94=20=EB=B6=80=EB=B6=84=EC=9D=84=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=A1=9C=20=EC=B6=94=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventService/LotteryEventService.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 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 c5a3c572..9aa2af6f 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 @@ -47,17 +47,7 @@ public class LotteryEventService { public CasperBotResponseDto postCasperBot(BaseUser user, CasperBotRequestDto casperBotRequestDto) throws CustomException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { LotteryParticipants participants = registerUserIfNeed(user, casperBotRequestDto); - List lotteryEventList = lotteryEventRepository.findAll(); - - if (lotteryEventList.isEmpty()) { - throw new CustomException("현재 진행중인 lotteryEvent가 존재하지 않습니다.", CustomErrorCode.NO_LOTTERY_EVENT); - } - - if (lotteryEventList.size() > 1) { - throw new CustomException("현재 진행중인 lotteryEvent가 2개 이상입니다.", CustomErrorCode.TOO_MANY_LOTTERY_EVENT); - } - - LotteryEvent lotteryEvent = lotteryEventList.get(0); + LotteryEvent lotteryEvent = getEvent(); CasperBot casperBot = casperBotRepository.save(new CasperBot(casperBotRequestDto, user.getId())); lotteryEvent.addAppliedCount(); @@ -112,6 +102,11 @@ public LotteryParticipants registerUserIfNeed(BaseUser user, CasperBotRequestDto } public LotteryEventResponseDto getLotteryEvent() { + LotteryEvent lotteryEvent = getEvent(); + return LotteryEventResponseDto.of(lotteryEvent, LocalDateTime.now()); + } + + private LotteryEvent getEvent() { List lotteryEventList = lotteryEventRepository.findAll(); if (lotteryEventList.isEmpty()) { @@ -122,7 +117,6 @@ public LotteryEventResponseDto getLotteryEvent() { throw new CustomException("현재 진행중인 lotteryEvent가 2개 이상입니다.", CustomErrorCode.TOO_MANY_LOTTERY_EVENT); } - LotteryEvent lotteryEvent = lotteryEventList.get(0); - return LotteryEventResponseDto.of(lotteryEvent, LocalDateTime.now()); + return lotteryEventList.get(0); } } From bbee6d4d5d956f628b8871fbdcbae119a1917503 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Tue, 13 Aug 2024 23:39:01 +0900 Subject: [PATCH 214/289] =?UTF-8?q?fix:=20=EA=B8=B0=EC=A1=B4=20LotteryPart?= =?UTF-8?q?icipantsRepository=EC=9D=98=20PK=20=ED=83=80=EC=9E=85=EC=9D=84?= =?UTF-8?q?=20String=20->=20Long=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../participantsRepository/LotteryParticipantsRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java index 48c9be10..afa38bb3 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java @@ -10,7 +10,7 @@ import java.util.Optional; @Repository -public interface LotteryParticipantsRepository extends JpaRepository { +public interface LotteryParticipantsRepository extends JpaRepository { Optional findByBaseUser(BaseUser baseUser); Page findByBaseUser_Id(String id, Pageable pageable); From 9fb9a255f9b0e5be1a1ae8b4d3a627c45df98ed6 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Wed, 14 Aug 2024 00:45:30 +0900 Subject: [PATCH 215/289] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=EC=97=90=EC=84=9C=20=ED=8A=B9=EC=A0=95=20?= =?UTF-8?q?=EA=B8=B0=EB=8C=80=ED=8F=89=EC=9D=84=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=ED=95=98=EB=8A=94=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/controller/adminController/AdminController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 8c160798..1f4de33c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -138,4 +138,12 @@ public ResponseEntity> getLotteryEventE return ResponseEntity.ok(lotteryEventExpectationResponseDtoList); } + + // 추첨 이벤트 특정 기대평을 삭제 + @PatchMapping("/event/lottery/expecations/{casperId}") + public ResponseEntity deleteLotteryEventExpectation(@PathVariable("casperId") Long casperId) { + adminService.deleteLotteryEventExpectation(casperId); + + return ResponseEntity.noContent().build(); + } } From 4c9bef9013268b27b8070bf7a5f3a9d4dff8ab65 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Wed, 14 Aug 2024 00:47:20 +0900 Subject: [PATCH 216/289] =?UTF-8?q?feat:=20=ED=8A=B9=EC=A0=95=20=EA=B8=B0?= =?UTF-8?q?=EB=8C=80=ED=8F=89=20=EC=82=AD=EC=A0=9C=20=EB=B9=84=EC=A6=88?= =?UTF-8?q?=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1,?= =?UTF-8?q?=20=EA=B8=B0=EB=8C=80=ED=8F=89=20=EC=A1=B0=ED=9A=8C=ED=95=A0=20?= =?UTF-8?q?=EB=95=8C=20=EA=B8=B0=EB=8C=80=ED=8F=89=EC=9D=B4=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EA=B2=BD=EC=9A=B0=EC=99=80=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=EB=90=9C=20=EA=B2=BD=EC=9A=B0=EB=8A=94=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84,=20RushEvent=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=EC=97=90=20@Transactional=20?= =?UTF-8?q?=EC=95=A0=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=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 --- .../service/adminService/AdminService.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 65845f6d..8b2a9f34 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -44,10 +44,7 @@ import org.springframework.web.multipart.MultipartFile; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Objects; +import java.util.*; @RequiredArgsConstructor @Service @@ -263,6 +260,7 @@ private LotteryEvent getCurrentLotteryEvent() { return lotteryEventList.get(0); } + @Transactional public List updateRushEvents(List rushEventRequestDtoList) { LocalDateTime now = LocalDateTime.now(); @@ -319,7 +317,16 @@ public List getLotteryEventExpectations(Long List casperBotList = casperBotRepository.findByPhoneNumber(lotteryParticipant.getBaseUser().getId()); - return casperBotList.stream().map(LotteryEventExpectationResponseDto::of).toList(); + // 기대평을 작성하지 않은 경우(기대평이 빈 문자열인 경우, 삭제된 경우)는 제외하여 반환합니다. + return casperBotList.stream().filter(casperBot -> !casperBot.getExpectation().isEmpty() && !casperBot.isDeleted()).map(LotteryEventExpectationResponseDto::of).toList(); + } + + @Transactional + public void deleteLotteryEventExpectation(Long casperId) { + CasperBot casperBot = casperBotRepository.findById(casperId).orElseThrow( + () -> new CustomException(CustomErrorCode.CASPERBOT_NOT_FOUND) + ); + casperBot.deleteExpectation(); } } From 8e867b6db7a17c90e9b7051cb3f19489edeeaeb8 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Wed, 14 Aug 2024 00:47:44 +0900 Subject: [PATCH 217/289] =?UTF-8?q?feat:=20CasperBot=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EC=97=90=20=EA=B8=B0=EB=8C=80=ED=8F=89=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80,?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=EB=90=9C=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EC=9D=B8=EC=A7=80=20=ED=99=95=EC=9D=B8=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/casperBot/CasperBot.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java index 96582663..410387dc 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java @@ -40,4 +40,16 @@ public CasperBot(CasperBotRequestDto requestDto, String phoneNumber) { this.name = requestDto.getName(); this.expectation = requestDto.getExpectation(); } + + public CasperBot deleteExpectation() { + if (!this.expectation.isEmpty()) { + this.expectation = "삭제된 기대평입니다."; + } + + return this; + } + + public boolean isDeleted() { + return this.expectation.equals("삭제된 기대평입니다."); + } } From 72d403b28f858b44d4436c1934ae088fc8dc3406 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Wed, 14 Aug 2024 00:48:10 +0900 Subject: [PATCH 218/289] =?UTF-8?q?fix:=20=EA=B8=B0=EB=8C=80=ED=8F=89=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=ED=95=A0=20=EB=95=8C=20CasperBotId=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=EB=8F=84=20=EC=B6=94=EA=B0=80=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventExpectationResponseDto.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventExpectationResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventExpectationResponseDto.java index 2d0549c9..42f7be75 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventExpectationResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventExpectationResponseDto.java @@ -6,7 +6,7 @@ import java.time.LocalDateTime; import java.time.LocalTime; -public record LotteryEventExpectationResponseDto(String expectation, LocalDate createdDate, +public record LotteryEventExpectationResponseDto(Long casperId, String expectation, LocalDate createdDate, LocalTime createdTime) { public static LotteryEventExpectationResponseDto of(CasperBot casperBot) { @@ -16,6 +16,7 @@ public static LotteryEventExpectationResponseDto of(CasperBot casperBot) { LocalTime createdTime = createdAt.toLocalTime(); return new LotteryEventExpectationResponseDto( + casperBot.getCasperId(), casperBot.getExpectation(), createdDate, createdTime From bc2799b6b45f8c8f84c4f5a9bbfc80731074bff3 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 02:09:27 +0900 Subject: [PATCH 219/289] =?UTF-8?q?feat:=20=EC=A7=84=ED=96=89=EC=A4=91?= =?UTF-8?q?=EC=9D=B8=20=EC=84=A0=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=82=AD=EC=A0=9C=20=EC=8B=9C=EB=8F=84=20=EC=8B=9C?= =?UTF-8?q?=20=EC=98=88=EC=99=B8=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/global/enums/CustomErrorCode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index cd1b74eb..fde4cba7 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -28,7 +28,8 @@ public enum CustomErrorCode { EVENT_IN_PROGRESS_END_TIME_BEFORE_NOW("현재 진행 중인 이벤트의 종료 시간을 현재 시간보다 이전으로 설정할 수 없습니다.", 400), EVENT_BEFORE_START_TIME("이벤트 시작 시간은 현재 시간 이후로 설정해야 합니다.", 400), EVENT_END_TIME_BEFORE_START_TIME("종료 시간은 시작 시간 이후로 설정해야 합니다.", 400), - INVALID_RUSH_EVENT_OPTION("밸런스 게임 선택지가 유효하지 않습니다."); + INVALID_RUSH_EVENT_OPTION("밸런스 게임 선택지가 유효하지 않습니다."), + EVENT_IN_PROGRESS_CANNOT_DELETE("진행중인 이벤트를 삭제할 수 없습니다.", 409); From 7aa9bd004b6c13066cfcd1b1706f0cf25a5cdfc3 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 02:09:38 +0900 Subject: [PATCH 220/289] =?UTF-8?q?feat:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminController/AdminController.java | 10 +++++++++- .../event/service/adminService/AdminService.java | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index d6483cb6..94ec3072 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -9,7 +9,6 @@ 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.RushEventParticipantsListResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventResponseDto; import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.global.response.ResponseDto; @@ -19,6 +18,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import software.amazon.awssdk.http.HttpStatusCode; import java.util.List; @@ -117,6 +117,14 @@ public ResponseEntity> updateRushEvent( .body(adminService.updateRushEvents(rushEventListRequestDto)); } + // 선착순 이벤트 삭제 + @DeleteMapping("/event/rush/{rushEventId}") + public ResponseEntity deleteRushEvent(@PathVariable Long rushEventId){ + return ResponseEntity + .status(HttpStatusCode.OK) + .body(adminService.deleteRushEvent(rushEventId)); + } + // 추첨 이벤트 삭제 @DeleteMapping("/event/lottery") public ResponseEntity deleteLotteryEvent() { diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index ae13c074..f7961302 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -311,4 +311,18 @@ else if (startDateTime.isBefore(now)) { } return rushEventResponseDtoList; } + + @Transactional + public ResponseDto deleteRushEvent(Long rushEventId){ + RushEvent rushEvent = rushEventRepository.findById(rushEventId).orElseThrow(() -> new CustomException(CustomErrorCode.NO_RUSH_EVENT)); + + LocalDateTime now = LocalDateTime.now(); + LocalDateTime startDateTime = rushEvent.getStartDateTime(); + LocalDateTime endDateTime = rushEvent.getEndDateTime(); + + if(now.isAfter(startDateTime) && now.isBefore(endDateTime)) + throw new CustomException(CustomErrorCode.EVENT_IN_PROGRESS_CANNOT_DELETE); + rushEventRepository.delete(rushEvent); + return ResponseDto.of("요청에 성공하였습니다."); + } } From 1c57d8b9c63d2d9412a28acdec96df81ca3212d3 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 02:25:53 +0900 Subject: [PATCH 221/289] =?UTF-8?q?feat:=20Option=EC=9D=84=20Set=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20AdminRushEve?= =?UTF-8?q?ntOptionResponseDto=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminRushEventOptionResponseDto.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/AdminRushEventOptionResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/AdminRushEventOptionResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/AdminRushEventOptionResponseDto.java new file mode 100644 index 00000000..bdac054c --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/AdminRushEventOptionResponseDto.java @@ -0,0 +1,15 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; + +import JGS.CasperEvent.domain.event.entity.event.RushEvent; + +import java.util.HashSet; +import java.util.Set; + +public record AdminRushEventOptionResponseDto(Set options) { + public static AdminRushEventOptionResponseDto of(RushEvent rushEvent){ + Set optionResponseDtoList = new HashSet<>(); + optionResponseDtoList.add(RushEventOptionResponseDto.of(rushEvent.getLeftOption())); + optionResponseDtoList.add(RushEventOptionResponseDto.of(rushEvent.getRightOption())); + return new AdminRushEventOptionResponseDto(optionResponseDtoList); + } +} From b5276741a46fe553fafbd7f595a66bc1c6d48778 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 02:26:39 +0900 Subject: [PATCH 222/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=EC=9D=98=20=EC=84=A0=ED=83=9D?= =?UTF-8?q?=EC=A7=80=EB=A5=BC=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 2f89eebf..a126ff5a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -5,10 +5,8 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventOptionRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.ImageUrlResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; -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.lotteryEventResponseDto.*; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventOptionResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantsListResponseDto; @@ -309,19 +307,26 @@ else if (startDateTime.isBefore(now)) { } @Transactional - public ResponseDto deleteRushEvent(Long rushEventId){ + public ResponseDto deleteRushEvent(Long rushEventId) { RushEvent rushEvent = rushEventRepository.findById(rushEventId).orElseThrow(() -> new CustomException(CustomErrorCode.NO_RUSH_EVENT)); LocalDateTime now = LocalDateTime.now(); LocalDateTime startDateTime = rushEvent.getStartDateTime(); LocalDateTime endDateTime = rushEvent.getEndDateTime(); - if(now.isAfter(startDateTime) && now.isBefore(endDateTime)) + if (now.isAfter(startDateTime) && now.isBefore(endDateTime)) throw new CustomException(CustomErrorCode.EVENT_IN_PROGRESS_CANNOT_DELETE); rushEventRepository.delete(rushEvent); return ResponseDto.of("요청에 성공하였습니다."); } + public AdminRushEventOptionResponseDto getRushEventOptions(Long rushEventId) { + return AdminRushEventOptionResponseDto.of( + rushEventRepository.findById(rushEventId).orElseThrow( + () -> new CustomException(CustomErrorCode.NO_RUSH_EVENT) + ) + ); + } public List getLotteryEventExpectations(Long participantId) { LotteryParticipants lotteryParticipant = lotteryParticipantsRepository.findById(participantId).orElseThrow( From 3f673d75760481871b0f0c19610da4f05c2433b5 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 02:26:43 +0900 Subject: [PATCH 223/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=EC=9D=98=20=EC=84=A0=ED=83=9D?= =?UTF-8?q?=EC=A7=80=EB=A5=BC=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20API?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/adminController/AdminController.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 05b69511..c0bc2489 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -5,8 +5,10 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.ImageUrlResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventExpectationResponseDto; 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.AdminRushEventOptionResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantsListResponseDto; import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; @@ -18,7 +20,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import software.amazon.awssdk.http.HttpStatusCode; import java.util.List; @@ -121,10 +122,18 @@ public ResponseEntity> updateRushEvent( @DeleteMapping("/event/rush/{rushEventId}") public ResponseEntity deleteRushEvent(@PathVariable Long rushEventId){ return ResponseEntity - .status(HttpStatusCode.OK) + .status(HttpStatus.OK) .body(adminService.deleteRushEvent(rushEventId)); } + // 선착순 이벤트 선택지 조회 + @GetMapping("/event/rush/{rushEventId}/options") + public ResponseEntity getRushEventOptions(@PathVariable Long rushEventId) { + return ResponseEntity + .status(HttpStatus.OK) + .body(adminService.getRushEventOptions(rushEventId)); + } + // 추첨 이벤트 삭제 @DeleteMapping("/event/lottery") public ResponseEntity deleteLotteryEvent() { From e6ee9e89d73d281b34accb809d7f19a01bc2548d Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 11:21:19 +0900 Subject: [PATCH 224/289] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=B2=A8=EB=B6=80=20=EC=B5=9C=EB=8C=80=2010MB=EB=A1=9C=20?= =?UTF-8?q?=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/src/main/resources/application-prod.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Server/src/main/resources/application-prod.yml b/Server/src/main/resources/application-prod.yml index ebe677d7..c1da7f6f 100644 --- a/Server/src/main/resources/application-prod.yml +++ b/Server/src/main/resources/application-prod.yml @@ -26,7 +26,9 @@ spring: s3: bucket: ${S3_IMAGE_SERVER} region: ap-northeast-2 - + servlet: + multipart: + max-file-size: 10MB client: url: ${CLIENT_URL} From 3d50fc649fd49e15cd6f8b79b7a1a5c90102967b Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 11:48:55 +0900 Subject: [PATCH 225/289] =?UTF-8?q?fix:=20=EC=A4=91=EB=B3=B5=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/adminService/AdminService.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 1ee84e00..a126ff5a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -328,20 +328,6 @@ public AdminRushEventOptionResponseDto getRushEventOptions(Long rushEventId) { ); } - @Transactional - public ResponseDto deleteRushEvent(Long rushEventId){ - RushEvent rushEvent = rushEventRepository.findById(rushEventId).orElseThrow(() -> new CustomException(CustomErrorCode.NO_RUSH_EVENT)); - - LocalDateTime now = LocalDateTime.now(); - LocalDateTime startDateTime = rushEvent.getStartDateTime(); - LocalDateTime endDateTime = rushEvent.getEndDateTime(); - - if(now.isAfter(startDateTime) && now.isBefore(endDateTime)) - throw new CustomException(CustomErrorCode.EVENT_IN_PROGRESS_CANNOT_DELETE); - rushEventRepository.delete(rushEvent); - return ResponseDto.of("요청에 성공하였습니다."); - } - public List getLotteryEventExpectations(Long participantId) { LotteryParticipants lotteryParticipant = lotteryParticipantsRepository.findById(participantId).orElseThrow( () -> new CustomException(CustomErrorCode.USER_NOT_FOUND) From bfb435a9a91773ca2dc1fd93430f35580fe69291 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 11:51:05 +0900 Subject: [PATCH 226/289] =?UTF-8?q?fix:=20=EC=A4=91=EB=B3=B5=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/adminService/AdminService.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 1ee84e00..a126ff5a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -328,20 +328,6 @@ public AdminRushEventOptionResponseDto getRushEventOptions(Long rushEventId) { ); } - @Transactional - public ResponseDto deleteRushEvent(Long rushEventId){ - RushEvent rushEvent = rushEventRepository.findById(rushEventId).orElseThrow(() -> new CustomException(CustomErrorCode.NO_RUSH_EVENT)); - - LocalDateTime now = LocalDateTime.now(); - LocalDateTime startDateTime = rushEvent.getStartDateTime(); - LocalDateTime endDateTime = rushEvent.getEndDateTime(); - - if(now.isAfter(startDateTime) && now.isBefore(endDateTime)) - throw new CustomException(CustomErrorCode.EVENT_IN_PROGRESS_CANNOT_DELETE); - rushEventRepository.delete(rushEvent); - return ResponseDto.of("요청에 성공하였습니다."); - } - public List getLotteryEventExpectations(Long participantId) { LotteryParticipants lotteryParticipant = lotteryParticipantsRepository.findById(participantId).orElseThrow( () -> new CustomException(CustomErrorCode.USER_NOT_FOUND) From 1496d84ff0e8e6aee28051081987f20d005b2956 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Wed, 14 Aug 2024 12:08:41 +0900 Subject: [PATCH 227/289] =?UTF-8?q?fix:=20LotteryEventRequestDto=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lotteryEventDto/LotteryEventRequestDto.java | 8 ++++---- .../domain/event/service/adminService/AdminService.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/LotteryEventRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/LotteryEventRequestDto.java index c04b978e..c8823502 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/LotteryEventRequestDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/LotteryEventRequestDto.java @@ -10,16 +10,16 @@ public class LotteryEventRequestDto { @NotNull(message = "이벤트 시작 날짜를 지정하세요.") - private LocalDate eventStartDate; + private LocalDate startDate; @NotNull(message = "이벤트 시작 시간을 지정하세요.") - private LocalTime eventStartTime; + private LocalTime startTime; @NotNull(message = "이벤트 종료 날짜를 지정하세요.") - private LocalDate eventEndDate; + private LocalDate endDate; @NotNull(message = "이벤트 시작 시간을 지정하세요.") - private LocalTime eventEndTime; + private LocalTime endTime; @NotNull(message = "당첨인원 수를 지정하세요.") private int winnerCount; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index a126ff5a..5eadcea8 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -81,8 +81,8 @@ public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lottery if (lotteryEventRepository.count() >= 1) throw new TooManyLotteryEventException(); LotteryEvent lotteryEvent = lotteryEventRepository.save(new LotteryEvent( - LocalDateTime.of(lotteryEventRequestDto.getEventStartDate(), lotteryEventRequestDto.getEventStartTime()), - LocalDateTime.of(lotteryEventRequestDto.getEventEndDate(), lotteryEventRequestDto.getEventEndTime()), + LocalDateTime.of(lotteryEventRequestDto.getStartDate(), lotteryEventRequestDto.getStartTime()), + LocalDateTime.of(lotteryEventRequestDto.getEndDate(), lotteryEventRequestDto.getEndTime()), lotteryEventRequestDto.getWinnerCount() )); @@ -214,8 +214,8 @@ public LotteryEventDetailResponseDto updateLotteryEvent(LotteryEventRequestDto l LotteryEvent currentLotteryEvent = getCurrentLotteryEvent(); LocalDateTime now = LocalDateTime.now(); - LocalDateTime newStartDateTime = LocalDateTime.of(lotteryEventRequestDto.getEventStartDate(), lotteryEventRequestDto.getEventStartTime()); - LocalDateTime newEndDateTime = LocalDateTime.of(lotteryEventRequestDto.getEventEndDate(), lotteryEventRequestDto.getEventEndTime()); + LocalDateTime newStartDateTime = LocalDateTime.of(lotteryEventRequestDto.getStartDate(), lotteryEventRequestDto.getStartTime()); + LocalDateTime newEndDateTime = LocalDateTime.of(lotteryEventRequestDto.getEndDate(), lotteryEventRequestDto.getEndTime()); // 종료 날짜가 시작 날짜보다 뒤인지 체크 if (newEndDateTime.isBefore(newStartDateTime)) { From 8c69c0df2a88f37963511a68f28102825ffd687d Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Wed, 14 Aug 2024 14:16:00 +0900 Subject: [PATCH 228/289] =?UTF-8?q?fix:=20url=20=EC=98=A4=ED=83=80=20?= =?UTF-8?q?=EC=8B=A4=EC=88=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/controller/adminController/AdminController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 518088ec..85ecb2b2 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -160,7 +160,7 @@ public ResponseEntity> getLotteryEventE } // 추첨 이벤트 특정 기대평을 삭제 - @PatchMapping("/event/lottery/expecations/{casperId}") + @PatchMapping("/event/lottery/expectations/{casperId}") public ResponseEntity deleteLotteryEventExpectation(@PathVariable("casperId") Long casperId) { adminService.deleteLotteryEventExpectation(casperId); From c3032b9786e24e34bdb993f6fb6cc2c635484d1d Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 15:07:36 +0900 Subject: [PATCH 229/289] =?UTF-8?q?feat:=20Repository=20=EB=8B=B9=EC=B2=A8?= =?UTF-8?q?=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20=EC=BF=BC=EB=A6=AC=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RushParticipantsRepository.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java index 138802b7..4743dc63 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java @@ -13,7 +13,9 @@ @Repository public interface RushParticipantsRepository extends JpaRepository { boolean existsByRushEvent_RushEventIdAndBaseUser_Id(Long eventId, String userId); + long countByRushEvent_RushEventIdAndOptionId(Long eventId, int optionId); + @Query("SELECT COUNT(rp) + 1 FROM RushParticipants rp " + "WHERE rp.rushEvent.rushEventId = :eventId " + "AND rp.optionId = :optionId " + @@ -23,7 +25,9 @@ public interface RushParticipantsRepository extends JpaRepository getOptionIdByUserId(@Param("userId") String userId); @@ -35,4 +39,32 @@ long findUserRankByEventIdAndUserIdAndOptionId(@Param("eventId") Long eventId, Page findByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(Long rushEventId, int optionId, String baseUser_id, Pageable pageable); + + @Query("SELECT rp FROM RushParticipants rp " + + "WHERE rp.rushEvent.rushEventId = :eventId " + + "AND rp.optionId = :optionId " + + "ORDER BY rp.id ASC ") + Page findWinnerByEventIdAndOptionId( + @Param("eventId") Long eventId, @Param("optionId") int optionId, Pageable pageable); + + @Query("SELECT rp FROM RushParticipants rp " + + "WHERE rp.rushEvent.rushEventId = :eventId " + + "AND rp.optionId = :optionId " + + "AND rp.baseUser.id = :phoneNumber " + + "ORDER BY rp.id ASC ") + Page findWinnerByEventIdAndOptionIdAndPhoneNumber( + @Param("eventId") Long eventId, @Param("optionId") int optionId, @Param("phoneNumber") String phoneNumber, Pageable pageable + ); + + @Query("SELECT rp FROM RushParticipants rp " + + "WHERE rp.rushEvent.rushEventId = :eventId " + + "ORDER BY rp.id ASC ") + Page findWinnerByEventId(@Param("eventId") Long eventId, @Param("winnerCount") Pageable pageable); + + + @Query("SELECT rp FROM RushParticipants rp " + + "WHERE rp.rushEvent.rushEventId = :eventId " + + "AND rp.baseUser.id = :phoneNumber " + + "ORDER BY rp.id ASC ") + Page findByWinnerByEventIdAndPhoneNumber(@Param("eventId") Long eventId, @Param("phoneNumber") String phoneNumber, Pageable pageable); } From fa93d0d8553a3e43078bd4ff6168fc8ee68151ea Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 15:08:11 +0900 Subject: [PATCH 230/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=84=B8=ED=8C=85=20=EC=8B=9C=20?= =?UTF-8?q?=EB=8B=B9=EC=B2=A8=EC=9E=90=20315=EB=AA=85=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/service/eventService/RushEventService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java index 02dd4fd3..f1ec704b 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java @@ -174,7 +174,7 @@ public void setTodayEventToRedis() { RushEvent rushEvent = new RushEvent( startDateTime.plusDays(i), // 이벤트 시작 날짜 endDateTime.plusDays(i), // 이벤트 종료 날짜 - 0, // 우승자 수 (winnerCount) + 315, // 우승자 수 (winnerCount) "http://example.com/prize" + (i + 1) + ".jpg", // 상 이미지 URL "Prize Description " + (i + 1) // 상 설명 ); From 9d88ea053a1dde095145e1124dc01a445045e256 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 15:08:37 +0900 Subject: [PATCH 231/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/event/RushEvent.java | 2 + .../service/adminService/AdminService.java | 64 ++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java index ee1bde7a..0da7678c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.annotation.JsonManagedReference; import jakarta.persistence.*; import lombok.Getter; +import lombok.ToString; import java.time.LocalDateTime; import java.util.HashSet; @@ -15,6 +16,7 @@ @Entity @Getter +@ToString public class RushEvent extends BaseEvent { private String prizeImageUrl; private String prizeDescription; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index a126ff5a..7a927770 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -34,6 +34,7 @@ import JGS.CasperEvent.global.service.S3Service; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -43,6 +44,8 @@ import java.time.LocalDateTime; import java.util.*; +import static JGS.CasperEvent.global.util.RepositoryErrorHandler.findByIdOrElseThrow; + @RequiredArgsConstructor @Service public class AdminService { @@ -100,7 +103,7 @@ public LotteryEventParticipantsListResponseDto getLotteryEventParticipants(int s Page lotteryParticipantsPage = null; if (phoneNumber.isEmpty()) lotteryParticipantsPage = lotteryParticipantsRepository.findAll(pageable); - else lotteryParticipantsRepository.findByBaseUser_Id(phoneNumber, pageable); + else lotteryParticipantsPage = lotteryParticipantsRepository.findByBaseUser_Id(phoneNumber, pageable); List lotteryEventParticipantsResponseDtoList = new ArrayList<>(); @@ -200,9 +203,59 @@ public RushEventParticipantsListResponseDto getRushEventParticipants(long rushEv } Boolean isLastPage = !rushParticipantsPage.hasNext(); + // todo 전체 참여자 아닌 옵션별 참여자로 수정하기 return new RushEventParticipantsListResponseDto(rushEventParticipantResponseDtoList, isLastPage, rushParticipantsRepository.count()); } + public RushEventParticipantsListResponseDto getRushEventWinners(long rushEventId, int size, int page, String phoneNumber) { + Page rushParticipantsPage = null; + + RushEvent rushEvent = findByIdOrElseThrow(rushEventRepository, rushEventId, CustomErrorCode.NO_RUSH_EVENT); + int winnerCount = rushEvent.getWinnerCount(); + Pageable winnerPage = PageRequest.of(0, winnerCount); + + long leftSelect = rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(rushEventId, 1); + long rightSelect = rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(rushEventId, 2); + + boolean isPhoneNumberEmpty = phoneNumber.isEmpty(); + + int winnerOptionId; + if (leftSelect > rightSelect) winnerOptionId = 1; + else if (leftSelect < rightSelect) winnerOptionId = 2; + else winnerOptionId = 0; + + if (!isPhoneNumberEmpty && winnerOptionId != 0) { + // 전화번호와 유효한 옵션 ID가 있는 경우 + rushParticipantsPage = rushParticipantsRepository.findWinnerByEventIdAndOptionIdAndPhoneNumber(rushEventId, winnerOptionId, phoneNumber, winnerPage); + } else if (isPhoneNumberEmpty && winnerOptionId == 0) { + // 전화번호가 비어있고 두 선택지가 동점인 경우 + rushParticipantsPage = rushParticipantsRepository.findWinnerByEventId(rushEventId, winnerPage); + } else if (winnerOptionId != 0) { + // 유효한 옵션 ID가 있지만 전화번호는 비어있는 경우 + rushParticipantsPage = rushParticipantsRepository.findWinnerByEventIdAndOptionId(rushEventId, winnerOptionId, winnerPage); + } else { + // 두 선택지가 동점이고 전화번호가 주어진 경우 + rushParticipantsPage = rushParticipantsRepository.findByWinnerByEventIdAndPhoneNumber(rushEventId, phoneNumber, winnerPage); + } + + List rushParticipantsList = rushParticipantsPage.getContent(); + rushParticipantsPage = paginateList(rushParticipantsList, page, size); + + List rushEventParticipantResponseDtoList = new ArrayList<>(); + for (RushParticipants rushParticipant : rushParticipantsPage) { + String userId = rushParticipant.getBaseUser().getId(); + int userChoice = rushParticipant.getOptionId(); + long rank = rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(rushEventId, userId, userChoice); + rushEventParticipantResponseDtoList.add( + RushEventParticipantResponseDto.of(rushParticipant, rank) + ); + } + + Boolean isLastPage = !rushParticipantsPage.hasNext(); + long totalParticipants = rushParticipantsList.size(); + return new RushEventParticipantsListResponseDto(rushEventParticipantResponseDtoList, isLastPage, totalParticipants); + } + @Transactional public void deleteLotteryEvent() { LotteryEvent currentLotteryEvent = getCurrentLotteryEvent(); @@ -347,4 +400,13 @@ public void deleteLotteryEventExpectation(Long casperId) { casperBot.deleteExpectation(); } + + public static Page paginateList(List list, int page, int size) { + int start = Math.min(page * size, list.size()); + int end = Math.min(start + size, list.size()); + + List paginatedList = list.subList(start, end); + + return new PageImpl<>(paginatedList, PageRequest.of(page, size), list.size()); + } } From 84a4aa7a654a54b6c18e73c6e1ca66f54b714470 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 15:08:42 +0900 Subject: [PATCH 232/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminController/AdminController.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 518088ec..ff623567 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -20,7 +20,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import software.amazon.awssdk.http.HttpStatusCode; import java.util.List; @@ -41,12 +40,10 @@ public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto // 이미지 업로드 @PostMapping("/image") - public ResponseEntity postImage( - @RequestPart(value = "image") MultipartFile image){ + public ResponseEntity postImage(@RequestPart(value = "image") MultipartFile image) { return ResponseEntity .status(HttpStatus.CREATED) .body(adminService.postImage(image)); - } // 추첨 이벤트 조회 @@ -110,10 +107,23 @@ public ResponseEntity getRushEventParticip .body(adminService.getRushEventParticipants(rushEventId, size, page, option, phoneNumber)); } + // 선착순 이벤트 당첨자 조회 + @GetMapping("/event/rush/{rushEventId}/winner") + public ResponseEntity getRushEventWinners( + @PathVariable("rushEventId") Long rushEventId, + @RequestParam(name = "size", required = false, defaultValue = "10") int size, + @RequestParam(name = "page", required = false, defaultValue = "0") int page, + @RequestParam(name = "number", required = false, defaultValue = "") String phoneNumber) { + return ResponseEntity + .status(HttpStatus.OK) + .body(adminService.getRushEventWinners(rushEventId, size, page, phoneNumber)); + } + // 선착순 이벤트 수정 @PutMapping("/event/rush") public ResponseEntity> updateRushEvent( @RequestBody List rushEventListRequestDto) { + return ResponseEntity .status(HttpStatus.OK) .body(adminService.updateRushEvents(rushEventListRequestDto)); @@ -121,7 +131,7 @@ public ResponseEntity> updateRushEvent( // 선착순 이벤트 삭제 @DeleteMapping("/event/rush/{rushEventId}") - public ResponseEntity deleteRushEvent(@PathVariable Long rushEventId){ + public ResponseEntity deleteRushEvent(@PathVariable Long rushEventId) { return ResponseEntity .status(HttpStatus.OK) .body(adminService.deleteRushEvent(rushEventId)); From 3babc62ff017d4a132d80eda9dc07ee2419e478c Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 17:36:04 +0900 Subject: [PATCH 233/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=B0=B8=EC=97=AC=EC=9E=90=20?= =?UTF-8?q?=EC=B9=B4=EC=9A=B4=ED=8A=B8=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../participantsRepository/RushParticipantsRepository.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java index 4743dc63..81f272a2 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java @@ -67,4 +67,11 @@ Page findWinnerByEventIdAndOptionIdAndPhoneNumber( "AND rp.baseUser.id = :phoneNumber " + "ORDER BY rp.id ASC ") Page findByWinnerByEventIdAndPhoneNumber(@Param("eventId") Long eventId, @Param("phoneNumber") String phoneNumber, Pageable pageable); + + long countByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(long rushEventId, int optionId, String id); + + long countByRushEvent_RushEventId(long rushEventId); + + long countByRushEvent_RushEventIdAndBaseUser_Id(long rushEventId, String phoneNumber); + } From 35fce9a43b20c673a31d6364faeea10b834d7492 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 17:36:21 +0900 Subject: [PATCH 234/289] =?UTF-8?q?chore:=20=ED=86=A0=ED=81=B0=20=EC=83=9D?= =?UTF-8?q?=EB=AA=85=EC=A3=BC=EA=B8=B0=205=EB=B6=84=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=8B=A8=EC=B6=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/JGS/CasperEvent/global/jwt/util/JwtProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/util/JwtProvider.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/util/JwtProvider.java index 8797f4f3..c2df22f7 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/util/JwtProvider.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/util/JwtProvider.java @@ -40,7 +40,7 @@ public Claims getClaims(String token) { private Date getExpireDateAccessToken() { - long expireTimeMils = 1000L * 60 * 60 * 24 * 365; + long expireTimeMils = 1000L * 60 * 5; return new Date(System.currentTimeMillis() + expireTimeMils); } From 4e5a87923bf9cf780e613ed3899169e94020dc1f Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 17:38:03 +0900 Subject: [PATCH 235/289] =?UTF-8?q?feat:=20=EC=A1=B0=EA=B1=B4=EC=97=90=20?= =?UTF-8?q?=EB=A7=9E=EB=8A=94=20=EC=B0=B8=EC=97=AC=EC=9E=90=20=EC=88=98?= =?UTF-8?q?=EB=A5=BC=20=EA=B3=84=EC=82=B0=ED=95=B4=EC=84=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=84=B4=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/service/adminService/AdminService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 7a927770..06a09542 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -177,21 +177,27 @@ public RushEventParticipantsListResponseDto getRushEventParticipants(long rushEv boolean isPhoneNumberEmpty = phoneNumber.isEmpty(); boolean isOptionIdValid = optionId == 1 || optionId == 2; + long count; if (!isPhoneNumberEmpty && isOptionIdValid) { // 전화번호와 유효한 옵션 ID가 있는 경우 rushParticipantsPage = rushParticipantsRepository.findByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(rushEventId, optionId, phoneNumber, pageable); + count = rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(rushEventId, optionId, phoneNumber); } else if (isPhoneNumberEmpty && !isOptionIdValid) { // 전화번호가 비어있고 유효하지 않은 옵션 ID가 있는 경우 rushParticipantsPage = rushParticipantsRepository.findByRushEvent_RushEventId(rushEventId, pageable); + count = rushParticipantsRepository.countByRushEvent_RushEventId(rushEventId); } else if (isOptionIdValid) { // 유효한 옵션 ID가 있지만 전화번호는 비어있는 경우 rushParticipantsPage = rushParticipantsRepository.findByRushEvent_RushEventIdAndOptionId(rushEventId, optionId, pageable); + count = rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(rushEventId, optionId); } else { // 유효하지 않은 옵션 ID와 전화번호가 주어진 경우 rushParticipantsPage = rushParticipantsRepository.findByRushEvent_RushEventIdAndBaseUser_Id(rushEventId, phoneNumber, pageable); + count = rushParticipantsRepository.countByRushEvent_RushEventIdAndBaseUser_Id(rushEventId, phoneNumber); } + List rushEventParticipantResponseDtoList = new ArrayList<>(); for (RushParticipants rushParticipant : rushParticipantsPage) { String userId = rushParticipant.getBaseUser().getId(); @@ -204,7 +210,7 @@ public RushEventParticipantsListResponseDto getRushEventParticipants(long rushEv Boolean isLastPage = !rushParticipantsPage.hasNext(); // todo 전체 참여자 아닌 옵션별 참여자로 수정하기 - return new RushEventParticipantsListResponseDto(rushEventParticipantResponseDtoList, isLastPage, rushParticipantsRepository.count()); + return new RushEventParticipantsListResponseDto(rushEventParticipantResponseDtoList, isLastPage, count); } public RushEventParticipantsListResponseDto getRushEventWinners(long rushEventId, int size, int page, String phoneNumber) { From 796607d67ac8c3d7107e0499b911c4c408407ad1 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 17:55:32 +0900 Subject: [PATCH 236/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=B0=B8=EC=97=AC=EC=9E=90=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=B0=98=ED=99=98=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RushEventParticipantResponseDto.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java index 5dd6362e..13a5ef0f 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java @@ -2,18 +2,20 @@ import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; public record RushEventParticipantResponseDto(Long id, String phoneNumber, - int balanceGameChoice, LocalDateTime createdAt, LocalDateTime updatedAt, + int balanceGameChoice, LocalDate createdDate, LocalTime createTime, Long rank) { public static RushEventParticipantResponseDto of(RushParticipants rushParticipants, Long rank){ return new RushEventParticipantResponseDto( rushParticipants.getId(), rushParticipants.getBaseUser().getId(), rushParticipants.getOptionId(), - rushParticipants.getCreatedAt(), - rushParticipants.getUpdatedAt(), + rushParticipants.getCreatedAt().toLocalDate(), + rushParticipants.getCreatedAt().toLocalTime(), rank ); } From db315bd15430c5d9606c3fcc52d9e766f9ef8b80 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 14 Aug 2024 17:55:42 +0900 Subject: [PATCH 237/289] =?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=B0=B8=EC=97=AC=EC=9E=90=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=B0=98=ED=99=98=20=ED=83=80=EC=9E=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventParticipantsResponseDto.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java index ca79a5eb..4de9c490 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java @@ -2,12 +2,14 @@ import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; public record LotteryEventParticipantsResponseDto( Long id, String phoneNumber, int linkClickedCounts, int expectation, int appliedCount, - LocalDateTime createdAt, LocalDateTime updatedAt) { + LocalDate createdDate, LocalTime createdTime) { public static LotteryEventParticipantsResponseDto of(LotteryParticipants participant) { return new LotteryEventParticipantsResponseDto( @@ -16,8 +18,9 @@ public static LotteryEventParticipantsResponseDto of(LotteryParticipants partici participant.getLinkClickedCount(), participant.getExpectations(), participant.getAppliedCount(), - participant.getBaseUser().getCreatedAt(), - participant.getBaseUser().getUpdatedAt() + participant.getBaseUser().getCreatedAt().toLocalDate(), + participant.getBaseUser().getCreatedAt().toLocalTime() ); } + } From 3a958103c28a99eb29be960dfd32e55684a5cdc3 Mon Sep 17 00:00:00 2001 From: nnijgnus <76596376+k000927@users.noreply.github.com> Date: Wed, 14 Aug 2024 18:15:54 +0900 Subject: [PATCH 238/289] Update RushEventParticipantResponseDto.java --- .../rushEventResponseDto/RushEventParticipantResponseDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java index 13a5ef0f..7eb080cb 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java @@ -7,7 +7,7 @@ import java.time.LocalTime; public record RushEventParticipantResponseDto(Long id, String phoneNumber, - int balanceGameChoice, LocalDate createdDate, LocalTime createTime, + int balanceGameChoice, LocalDate createdDate, LocalTime createdTime, Long rank) { public static RushEventParticipantResponseDto of(RushParticipants rushParticipants, Long rank){ return new RushEventParticipantResponseDto( From 213ad22624bf1f1aa58170a31daff58eba08cbce Mon Sep 17 00:00:00 2001 From: nnijgnus <76596376+k000927@users.noreply.github.com> Date: Wed, 14 Aug 2024 18:52:41 +0900 Subject: [PATCH 239/289] Update JwtProvider.java --- .../java/JGS/CasperEvent/global/jwt/util/JwtProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/util/JwtProvider.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/util/JwtProvider.java index c2df22f7..69745bb0 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/util/JwtProvider.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/util/JwtProvider.java @@ -40,8 +40,8 @@ public Claims getClaims(String token) { private Date getExpireDateAccessToken() { - long expireTimeMils = 1000L * 60 * 5; + long expireTimeMils = 1000L * 60 * 60 * 24 * 365; return new Date(System.currentTimeMillis() + expireTimeMils); } -} \ No newline at end of file +} From db036799e2be06bd7ebdd642257836c7a7289fe8 Mon Sep 17 00:00:00 2001 From: nnijgnus <76596376+k000927@users.noreply.github.com> Date: Thu, 15 Aug 2024 02:12:44 +0900 Subject: [PATCH 240/289] =?UTF-8?q?fix:=20=EC=96=B4=EB=93=9C=EB=AF=BC=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20CORS=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/JGS/CasperEvent/global/config/WebConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Server/src/main/java/JGS/CasperEvent/global/config/WebConfig.java b/Server/src/main/java/JGS/CasperEvent/global/config/WebConfig.java index 534352fc..1dd6cdb4 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/config/WebConfig.java +++ b/Server/src/main/java/JGS/CasperEvent/global/config/WebConfig.java @@ -37,6 +37,7 @@ public UrlBasedCorsConfigurationSource corsConfigurationSource() { config.setAllowCredentials(true); config.addAllowedOrigin("http://localhost:5173"); config.addAllowedOrigin("https://d3phfzvzx3wm4l.cloudfront.net/"); + config.addAllowedOrigin("https://d2oxrno1u2ah9j.cloudfront.net/"); config.addAllowedOrigin("https://hybrid-jgs.shop"); config.addAllowedHeader("*"); config.addAllowedMethod("*"); From 809a89124300683a2d1064be37afede79b827a88 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 02:31:47 +0900 Subject: [PATCH 241/289] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/participants/LotteryWinners.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java new file mode 100644 index 00000000..9b63cfcc --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java @@ -0,0 +1,32 @@ +package JGS.CasperEvent.domain.event.entity.participants; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; + +import java.time.LocalDateTime; + +@Entity +public class LotteryWinners { + @Id + private long id; + private String phoneNumber; + private int linkClickedCount; + private int expectation; + private int appliedCount; + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + + public LotteryWinners(LotteryParticipants lotteryParticipants) { + this.id = lotteryParticipants.getId(); + this.phoneNumber = lotteryParticipants.getBaseUser().getId(); + this.linkClickedCount = lotteryParticipants.getLinkClickedCount(); + this.expectation = lotteryParticipants.getExpectations(); + this.appliedCount = lotteryParticipants.getAppliedCount(); + this.createdAt = lotteryParticipants.getCreatedAt(); + this.updatedAt = lotteryParticipants.getUpdatedAt(); + } + + public LotteryWinners() { + + } +} From d67ddd725199068f5de172eb82a33e659d209f31 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 02:31:55 +0900 Subject: [PATCH 242/289] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryWinnerRepository.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java new file mode 100644 index 00000000..247b90c9 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java @@ -0,0 +1,10 @@ +package JGS.CasperEvent.domain.event.repository.participantsRepository; + +import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; +import JGS.CasperEvent.domain.event.entity.participants.LotteryWinners; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface LotteryWinnerRepository extends JpaRepository { +} From 48e5e5b55e10413c48d7d9f56b283d354b383357 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 02:32:25 +0900 Subject: [PATCH 243/289] =?UTF-8?q?feat:=20LotteryParticipants=EA=B0=80=20?= =?UTF-8?q?BaseEntity=EB=A5=BC=20=EC=83=81=EC=86=8D=EB=B0=9B=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/entity/participants/LotteryParticipants.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java index 39037862..6f2ec115 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java @@ -1,5 +1,6 @@ package JGS.CasperEvent.domain.event.entity.participants; +import JGS.CasperEvent.global.entity.BaseEntity; import JGS.CasperEvent.global.entity.BaseUser; import com.fasterxml.jackson.annotation.JsonBackReference; import jakarta.persistence.*; @@ -7,7 +8,7 @@ @Getter @Entity -public class LotteryParticipants { +public class LotteryParticipants extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -33,7 +34,7 @@ public LotteryParticipants() { } public void expectationAdded() { - if(expectations == 0) expectations++; + if (expectations == 0) expectations++; appliedCount = Math.min(10, 1 + expectations + linkClickedCount); } From 761c694d53223914044bd24b188f0aba1873108d Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 02:32:43 +0900 Subject: [PATCH 244/289] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=20=EC=B6=94?= =?UTF-8?q?=EC=B2=A8=EC=9D=B4=20=EC=99=84=EB=A3=8C=EB=90=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=EB=A5=BC=20=EB=8B=A4=EC=8B=9C=20=EC=B6=94?= =?UTF-8?q?=EC=B2=A8=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=8B=9C=EB=8F=84?= =?UTF-8?q?=ED=95=A0=20=EB=95=8C=20=EC=98=88=EC=99=B8=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/global/enums/CustomErrorCode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index fde4cba7..78e760c9 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -29,7 +29,8 @@ public enum CustomErrorCode { EVENT_BEFORE_START_TIME("이벤트 시작 시간은 현재 시간 이후로 설정해야 합니다.", 400), EVENT_END_TIME_BEFORE_START_TIME("종료 시간은 시작 시간 이후로 설정해야 합니다.", 400), INVALID_RUSH_EVENT_OPTION("밸런스 게임 선택지가 유효하지 않습니다."), - EVENT_IN_PROGRESS_CANNOT_DELETE("진행중인 이벤트를 삭제할 수 없습니다.", 409); + EVENT_IN_PROGRESS_CANNOT_DELETE("진행중인 이벤트를 삭제할 수 없습니다.", 409), + LOTTERY_EVENT_ALREADY_DRAWN("추첨 이벤트의 당첨자가 이미 추첨되었습니다.", 409),; From cdfee846379ce53f3b254bced383242659080b7a Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 02:33:05 +0900 Subject: [PATCH 245/289] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=A8=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=9E=91=EC=84=B1,=20=ED=98=84=EC=9E=AC?= =?UTF-8?q?=EB=8A=94=20=EA=B0=80=EC=A7=9C=20=EC=95=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=EC=A6=98=20=EB=8F=99=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index f19f81bb..ed502ef3 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -16,6 +16,7 @@ import JGS.CasperEvent.domain.event.entity.event.RushEvent; import JGS.CasperEvent.domain.event.entity.event.RushOption; import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; +import JGS.CasperEvent.domain.event.entity.participants.LotteryWinners; import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; import JGS.CasperEvent.domain.event.repository.AdminRepository; import JGS.CasperEvent.domain.event.repository.CasperBotRepository; @@ -23,6 +24,7 @@ import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.RushOptionRepository; import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryParticipantsRepository; +import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryWinnerRepository; import JGS.CasperEvent.domain.event.repository.participantsRepository.RushParticipantsRepository; import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.Position; @@ -58,6 +60,7 @@ public class AdminService { private final RushOptionRepository rushOptionRepository; private final S3Service s3Service; private final CasperBotRepository casperBotRepository; + private final LotteryWinnerRepository lotteryWinnerRepository; public Admin verifyAdmin(AdminRequestDto adminRequestDto) { return adminRepository.findByIdAndPassword(adminRequestDto.getAdminId(), adminRequestDto.getPassword()).orElseThrow(NoSuchElementException::new); @@ -316,6 +319,24 @@ private LotteryEvent getCurrentLotteryEvent() { return lotteryEventList.get(0); } + @Transactional + public ResponseDto pickWinners() { + if(lotteryWinnerRepository.count() > 1) throw new CustomException(CustomErrorCode.LOTTERY_EVENT_ALREADY_DRAWN); + LotteryEvent lotteryEvent = getCurrentLotteryEvent(); + + int winnerCount = lotteryEvent.getWinnerCount(); + + Pageable pageable = PageRequest.of(0, winnerCount); + + //todo 당첨자 추첨 알고리즘 변경해야함 + Page lotteryWinners = lotteryParticipantsRepository.findAll(pageable); + for (LotteryParticipants lotteryWinner : lotteryWinners) { + lotteryWinnerRepository.save(new LotteryWinners(lotteryWinner)); + } + + return new ResponseDto("추첨이 완료되었습니다."); + } + @Transactional public List updateRushEvents(List rushEventRequestDtoList) { LocalDateTime now = LocalDateTime.now(); From 5faacd5ff4b449073872f083bd1263a7e1c6ae02 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 02:33:21 +0900 Subject: [PATCH 246/289] =?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=EB=8B=B9=EC=B2=A8=EC=9E=90=20=EC=B6=94?= =?UTF-8?q?=EC=B2=A8=20api=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/adminController/AdminController.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index dba71514..0df1f00e 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -144,7 +144,7 @@ public ResponseEntity getRushEventOptions(@Path .status(HttpStatus.OK) .body(adminService.getRushEventOptions(rushEventId)); } - + // 추첨 이벤트 삭제 @DeleteMapping("/event/lottery") public ResponseEntity deleteLotteryEvent() { @@ -176,4 +176,12 @@ public ResponseEntity deleteLotteryEventExpectation(@PathVariable("casperI return ResponseEntity.noContent().build(); } + + // 추첨 이벤트 당첨자 추첨 + @PostMapping("/event/lottery/winner") + public ResponseEntity pickWinners(){ + return ResponseEntity + .status(HttpStatus.CREATED) + .body(adminService.pickWinners()); + } } From b1fe8b6cf40df80277b24d1c4bc6c176833b58a5 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 02:33:56 +0900 Subject: [PATCH 247/289] =?UTF-8?q?chore:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20import=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventParticipantsResponseDto.java | 1 - .../rushEventResponseDto/RushEventParticipantResponseDto.java | 1 - .../participantsRepository/LotteryWinnerRepository.java | 1 - 3 files changed, 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java index 4de9c490..35acc0ab 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventParticipantsResponseDto.java @@ -3,7 +3,6 @@ import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.LocalTime; public record LotteryEventParticipantsResponseDto( diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java index 7eb080cb..6d40224a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventParticipantResponseDto.java @@ -3,7 +3,6 @@ import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.LocalTime; public record RushEventParticipantResponseDto(Long id, String phoneNumber, diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java index 247b90c9..6956709a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java @@ -1,6 +1,5 @@ package JGS.CasperEvent.domain.event.repository.participantsRepository; -import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import JGS.CasperEvent.domain.event.entity.participants.LotteryWinners; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; From 2a04133d436677058a71adf8cd6f260f6beb863e Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 15:55:24 +0900 Subject: [PATCH 248/289] =?UTF-8?q?chore:=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=EC=97=90=20=EB=9E=AD=ED=82=B9=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/entity/participants/LotteryWinners.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java index 9b63cfcc..1a3f98cc 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java @@ -1,14 +1,22 @@ package JGS.CasperEvent.domain.event.entity.participants; import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import lombok.Getter; import java.time.LocalDateTime; @Entity +@Getter public class LotteryWinners { - @Id private long id; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long ranking; + private String phoneNumber; private int linkClickedCount; private int expectation; From 7a381cf2793144598d8569098176195254f1e3ec Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 15:55:46 +0900 Subject: [PATCH 249/289] =?UTF-8?q?chore:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=EC=9A=A9=20dto=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventWinnerResponseDto.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/LotteryEventWinnerResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/LotteryEventWinnerResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/LotteryEventWinnerResponseDto.java new file mode 100644 index 00000000..25bcd113 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/LotteryEventWinnerResponseDto.java @@ -0,0 +1,25 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; + +import JGS.CasperEvent.domain.event.entity.participants.LotteryWinners; + +import java.time.LocalDate; +import java.time.LocalTime; + +public record LotteryEventWinnerResponseDto( + Long id, String phoneNumber, int linkClickedCounts, + int expectation, int appliedCount, long ranking, + LocalDate createdDate, LocalTime createdTime) { + + public static LotteryEventWinnerResponseDto of(LotteryWinners lotteryWinner) { + return new LotteryEventWinnerResponseDto( + lotteryWinner.getId(), + lotteryWinner.getPhoneNumber(), + lotteryWinner.getLinkClickedCount(), + lotteryWinner.getExpectation(), + lotteryWinner.getAppliedCount(), + lotteryWinner.getRanking(), + lotteryWinner.getCreatedAt().toLocalDate(), + lotteryWinner.getCreatedAt().toLocalTime() + ); + } +} \ No newline at end of file From 6bd1468983d2622916e5261aed289a3a69c96a65 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 15:55:56 +0900 Subject: [PATCH 250/289] =?UTF-8?q?chore:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EB=B0=98=ED=99=98=EC=9A=A9=20dto=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventWinnerListResponseDto.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/LotteryEventWinnerListResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/LotteryEventWinnerListResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/LotteryEventWinnerListResponseDto.java new file mode 100644 index 00000000..83826efa --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/LotteryEventWinnerListResponseDto.java @@ -0,0 +1,7 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto; + +import java.util.List; + +public record LotteryEventWinnerListResponseDto(List participantsList, + Boolean isLastPage, long totalParticipants) { +} \ No newline at end of file From b2c54581c2c7de8d1fa19cb97509e2a6880e7bff Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 15:56:42 +0900 Subject: [PATCH 251/289] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=EC=9E=90?= =?UTF-8?q?=EA=B0=80=20=EC=B6=94=EC=B2=A8=EB=90=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=95=98=EC=9D=84=20=EB=95=8C,=20=EB=8B=B9=EC=B2=A8=EC=9E=90?= =?UTF-8?q?=EB=A5=BC=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EC=BB=A4=EC=8A=A4=ED=85=80=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/global/enums/CustomErrorCode.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index 78e760c9..7ca81da5 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -30,7 +30,9 @@ public enum CustomErrorCode { EVENT_END_TIME_BEFORE_START_TIME("종료 시간은 시작 시간 이후로 설정해야 합니다.", 400), INVALID_RUSH_EVENT_OPTION("밸런스 게임 선택지가 유효하지 않습니다."), EVENT_IN_PROGRESS_CANNOT_DELETE("진행중인 이벤트를 삭제할 수 없습니다.", 409), - LOTTERY_EVENT_ALREADY_DRAWN("추첨 이벤트의 당첨자가 이미 추첨되었습니다.", 409),; + LOTTERY_EVENT_ALREADY_DRAWN("추첨 이벤트의 당첨자가 이미 추첨되었습니다.", 409), + LOTTERY_EVENT_NOT_DRAWN("추첨 이벤트가 아직 추첨되지 않았습니다.", 404); + From e35860ad5701173fd492fb04d97d235675cf1f56 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 16:05:35 +0900 Subject: [PATCH 252/289] =?UTF-8?q?feat:=20=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EC=85=98=20=EC=A0=81=EC=9A=A9=ED=95=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../participantsRepository/LotteryWinnerRepository.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java index 6956709a..72ba907c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java @@ -1,9 +1,12 @@ package JGS.CasperEvent.domain.event.repository.participantsRepository; import JGS.CasperEvent.domain.event.entity.participants.LotteryWinners; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface LotteryWinnerRepository extends JpaRepository { + Page findByPhoneNumber(String phoneNumber, Pageable pageable); } From bfcfd8fc24b12013ece329a5617919d6f497ec18 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 16:05:47 +0900 Subject: [PATCH 253/289] =?UTF-8?q?feat:=20=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EC=85=98=20=EC=A0=81=EC=9A=A9=ED=95=9C=20?= =?UTF-8?q?=EB=8B=B9=EC=B2=A8=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index ed502ef3..eb0c46c3 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -6,10 +6,7 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.ImageUrlResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.*; -import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventOptionResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantsListResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.*; import JGS.CasperEvent.domain.event.entity.admin.Admin; import JGS.CasperEvent.domain.event.entity.casperBot.CasperBot; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; @@ -320,7 +317,7 @@ private LotteryEvent getCurrentLotteryEvent() { } @Transactional - public ResponseDto pickWinners() { + public ResponseDto pickLotteryEventWinners() { if(lotteryWinnerRepository.count() > 1) throw new CustomException(CustomErrorCode.LOTTERY_EVENT_ALREADY_DRAWN); LotteryEvent lotteryEvent = getCurrentLotteryEvent(); @@ -337,6 +334,25 @@ public ResponseDto pickWinners() { return new ResponseDto("추첨이 완료되었습니다."); } + public LotteryEventWinnerListResponseDto getLotteryEventWinners(int size, int page, String phoneNumber){ + Pageable pageable = PageRequest.of(page, size); + if(lotteryWinnerRepository.count() == 0) throw new CustomException(CustomErrorCode.LOTTERY_EVENT_NOT_DRAWN); + + Page lotteryWinnersPage = null; + if (phoneNumber.isEmpty()) lotteryWinnersPage = lotteryWinnerRepository.findAll(pageable); + else lotteryWinnersPage = lotteryWinnerRepository.findByPhoneNumber(phoneNumber, pageable); + + List lotteryEventWinnerResponseDto = new ArrayList<>(); + + for (LotteryWinners lotteryWinners : lotteryWinnersPage) { + lotteryEventWinnerResponseDto.add( + LotteryEventWinnerResponseDto.of(lotteryWinners) + ); + } + Boolean isLastPage = !lotteryWinnersPage.hasNext(); + return new LotteryEventWinnerListResponseDto(lotteryEventWinnerResponseDto, isLastPage, lotteryWinnerRepository.count()); + } + @Transactional public List updateRushEvents(List rushEventRequestDtoList) { LocalDateTime now = LocalDateTime.now(); From 5e522a8841abd2246a5da6472ba67c8bc39ed229 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 16:05:51 +0900 Subject: [PATCH 254/289] =?UTF-8?q?feat:=20=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EC=85=98=20=EC=A0=81=EC=9A=A9=ED=95=9C=20?= =?UTF-8?q?=EB=8B=B9=EC=B2=A8=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20api=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminController/AdminController.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 0df1f00e..8d65a24b 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -10,6 +10,7 @@ import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsListResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventOptionResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.LotteryEventWinnerListResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantsListResponseDto; import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; import JGS.CasperEvent.domain.event.service.adminService.AdminService; @@ -28,7 +29,6 @@ @RequiredArgsConstructor public class AdminController { private final AdminService adminService; - private final LotteryEventRepository lotteryEventRepository; // 어드민 생성 @PostMapping("/join") @@ -179,9 +179,20 @@ public ResponseEntity deleteLotteryEventExpectation(@PathVariable("casperI // 추첨 이벤트 당첨자 추첨 @PostMapping("/event/lottery/winner") - public ResponseEntity pickWinners(){ + public ResponseEntity pickLotteryEventWinners() { return ResponseEntity .status(HttpStatus.CREATED) - .body(adminService.pickWinners()); + .body(adminService.pickLotteryEventWinners()); + } + + // 추첨 이벤트 당첨자 조회 + @GetMapping("/event/lottery/winner") + public ResponseEntity getWinners( + @RequestParam(name = "size", required = false, defaultValue = "10") int size, + @RequestParam(name = "page", required = false, defaultValue = "0") int page, + @RequestParam(name = "number", required = false, defaultValue = "") String phoneNumber) { + return ResponseEntity + .status(HttpStatus.OK) + .body(adminService.getLotteryEventWinners(size, page, phoneNumber)); } } From 263c005b07166b62fde694e04597ba6daee73d37 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 18:06:56 +0900 Subject: [PATCH 255/289] =?UTF-8?q?feat:=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B6=80=EB=B6=84=EC=9D=BC=EC=B9=98=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=BF=BC=EB=A6=AC=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryParticipantsRepository.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java index afa38bb3..465f155c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java @@ -2,9 +2,11 @@ import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import JGS.CasperEvent.global.entity.BaseUser; +import io.lettuce.core.dynamic.annotation.Param; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import java.util.Optional; @@ -13,6 +15,10 @@ public interface LotteryParticipantsRepository extends JpaRepository { Optional findByBaseUser(BaseUser baseUser); - Page findByBaseUser_Id(String id, Pageable pageable); + @Query("SELECT p FROM LotteryParticipants p WHERE p.baseUser.id LIKE %:id%") + Page findByBaseUser_Id(@Param("id") String id, Pageable pageable); + + @Query("SELECT COUNT(p) FROM LotteryParticipants p WHERE p.baseUser.id LIKE %:id%") + long countByBaseUser_Id(@Param("id") String id); } From 0c8cd616c234bbf1250ae30bba57039dc8a7ef19 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 18:07:26 +0900 Subject: [PATCH 256/289] =?UTF-8?q?feat:=20=EC=98=B5=EC=85=98=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20=EC=B9=B4=EC=9A=B4=ED=8A=B8=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index eb0c46c3..cb5d6ae1 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -102,8 +102,14 @@ public LotteryEventParticipantsListResponseDto getLotteryEventParticipants(int s Pageable pageable = PageRequest.of(page, size); Page lotteryParticipantsPage = null; - if (phoneNumber.isEmpty()) lotteryParticipantsPage = lotteryParticipantsRepository.findAll(pageable); - else lotteryParticipantsPage = lotteryParticipantsRepository.findByBaseUser_Id(phoneNumber, pageable); + long count; + if (phoneNumber.isEmpty()) { + lotteryParticipantsPage = lotteryParticipantsRepository.findAll(pageable); + count = lotteryParticipantsRepository.count(); + } else { + lotteryParticipantsPage = lotteryParticipantsRepository.findByBaseUser_Id(phoneNumber, pageable); + count = lotteryParticipantsRepository.countByBaseUser_Id(phoneNumber); + } List lotteryEventParticipantsResponseDtoList = new ArrayList<>(); @@ -113,7 +119,7 @@ public LotteryEventParticipantsListResponseDto getLotteryEventParticipants(int s ); } Boolean isLastPage = !lotteryParticipantsPage.hasNext(); - return new LotteryEventParticipantsListResponseDto(lotteryEventParticipantsResponseDtoList, isLastPage, lotteryParticipantsRepository.count()); + return new LotteryEventParticipantsListResponseDto(lotteryEventParticipantsResponseDtoList, isLastPage, count); } public AdminRushEventResponseDto createRushEvent(RushEventRequestDto rushEventRequestDto, MultipartFile prizeImg, MultipartFile leftOptionImg, MultipartFile rightOptionImg) { @@ -318,7 +324,7 @@ private LotteryEvent getCurrentLotteryEvent() { @Transactional public ResponseDto pickLotteryEventWinners() { - if(lotteryWinnerRepository.count() > 1) throw new CustomException(CustomErrorCode.LOTTERY_EVENT_ALREADY_DRAWN); + if (lotteryWinnerRepository.count() > 1) throw new CustomException(CustomErrorCode.LOTTERY_EVENT_ALREADY_DRAWN); LotteryEvent lotteryEvent = getCurrentLotteryEvent(); int winnerCount = lotteryEvent.getWinnerCount(); @@ -334,9 +340,9 @@ public ResponseDto pickLotteryEventWinners() { return new ResponseDto("추첨이 완료되었습니다."); } - public LotteryEventWinnerListResponseDto getLotteryEventWinners(int size, int page, String phoneNumber){ + public LotteryEventWinnerListResponseDto getLotteryEventWinners(int size, int page, String phoneNumber) { Pageable pageable = PageRequest.of(page, size); - if(lotteryWinnerRepository.count() == 0) throw new CustomException(CustomErrorCode.LOTTERY_EVENT_NOT_DRAWN); + if (lotteryWinnerRepository.count() == 0) throw new CustomException(CustomErrorCode.LOTTERY_EVENT_NOT_DRAWN); Page lotteryWinnersPage = null; if (phoneNumber.isEmpty()) lotteryWinnersPage = lotteryWinnerRepository.findAll(pageable); From f32a4b5baaf577992fa737cb34abb16ec2535405 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 21:21:54 +0900 Subject: [PATCH 257/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EA=B2=80=EC=83=89=EC=8B=9C=20LIKE=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RushParticipantsRepository.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java index 81f272a2..e5b7e37a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java @@ -33,11 +33,13 @@ long findUserRankByEventIdAndUserIdAndOptionId(@Param("eventId") Long eventId, Page findByRushEvent_RushEventId(Long rushEventId, Pageable pageable); - Page findByRushEvent_RushEventIdAndBaseUser_Id(Long rushEventId, String baseUser_id, Pageable pageable); + @Query("SELECT p FROM RushParticipants p WHERE p.rushEvent.rushEventId = :rushEventId AND p.baseUser.id LIKE :baseUserId%") + Page findByRushEvent_RushEventIdAndBaseUser_Id(@Param("rushEventId") Long rushEventId, @Param("baseUserId") String baseUserId, Pageable pageable); Page findByRushEvent_RushEventIdAndOptionId(Long rushEventId, int optionId, Pageable pageable); - Page findByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(Long rushEventId, int optionId, String baseUser_id, Pageable pageable); + @Query("SELECT p FROM RushParticipants p WHERE p.rushEvent.rushEventId = :rushEventId AND p.optionId = :optionId AND p.baseUser.id LIKE :baseUserId%") + Page findByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(@Param("rushEventId") Long rushEventId, @Param("optionId") int optionId, @Param("baseUserId") String baseUserId, Pageable pageable); @Query("SELECT rp FROM RushParticipants rp " + @@ -50,7 +52,7 @@ Page findWinnerByEventIdAndOptionId( @Query("SELECT rp FROM RushParticipants rp " + "WHERE rp.rushEvent.rushEventId = :eventId " + "AND rp.optionId = :optionId " + - "AND rp.baseUser.id = :phoneNumber " + + "AND rp.baseUser.id LIKE :phoneNumber% " + "ORDER BY rp.id ASC ") Page findWinnerByEventIdAndOptionIdAndPhoneNumber( @Param("eventId") Long eventId, @Param("optionId") int optionId, @Param("phoneNumber") String phoneNumber, Pageable pageable @@ -64,14 +66,15 @@ Page findWinnerByEventIdAndOptionIdAndPhoneNumber( @Query("SELECT rp FROM RushParticipants rp " + "WHERE rp.rushEvent.rushEventId = :eventId " + - "AND rp.baseUser.id = :phoneNumber " + + "AND rp.baseUser.id LIKE :phoneNumber% " + "ORDER BY rp.id ASC ") Page findByWinnerByEventIdAndPhoneNumber(@Param("eventId") Long eventId, @Param("phoneNumber") String phoneNumber, Pageable pageable); - long countByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(long rushEventId, int optionId, String id); + @Query("SELECT COUNT(p) FROM RushParticipants p WHERE p.rushEvent.rushEventId = :rushEventId AND p.optionId = :optionId AND p.baseUser.id LIKE :baseUserId%") + long countByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(@Param("rushEventId") Long rushEventId, @Param("optionId") int optionId, @Param("baseUserId") String baseUserId); long countByRushEvent_RushEventId(long rushEventId); - long countByRushEvent_RushEventIdAndBaseUser_Id(long rushEventId, String phoneNumber); - -} + @Query("SELECT COUNT(p) FROM RushParticipants p WHERE p.rushEvent.rushEventId = :rushEventId AND p.baseUser.id LIKE :baseUserId%") + long countByRushEvent_RushEventIdAndBaseUser_Id(@Param("rushEventId") Long rushEventId, @Param("baseUserId") String baseUserId); +} \ No newline at end of file From 7671bfb259479ed9dca11590f795d47307cafa1b Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 21:22:10 +0900 Subject: [PATCH 258/289] =?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=A0=84=ED=99=94=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=EC=8B=9C=20LIKE=20=EC=9D=B4=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../participantsRepository/LotteryWinnerRepository.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java index 72ba907c..4165984f 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java @@ -1,12 +1,17 @@ package JGS.CasperEvent.domain.event.repository.participantsRepository; import JGS.CasperEvent.domain.event.entity.participants.LotteryWinners; +import io.lettuce.core.dynamic.annotation.Param; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @Repository public interface LotteryWinnerRepository extends JpaRepository { - Page findByPhoneNumber(String phoneNumber, Pageable pageable); -} + @Query("SELECT w FROM LotteryWinners w WHERE w.phoneNumber LIKE %:phoneNumber%") + Page findByPhoneNumber(@Param("phoneNumber") String phoneNumber, Pageable pageable); + + @Query("SELECT COUNT(w) FROM LotteryWinners w WHERE w.phoneNumber LIKE %:phoneNumber%") + long countByPhoneNumber(@Param("phoneNumber") String phoneNumber);} From d684a8c170e5ab02e0f4d6022b9d8c48803c13de Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 21:22:42 +0900 Subject: [PATCH 259/289] =?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=EB=8B=B9=EC=B2=A8=EC=9E=90=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=EC=8B=9C=20=EC=B9=B4=EC=9A=B4=ED=8A=B8=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/adminService/AdminService.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index cb5d6ae1..6ea49128 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -215,7 +215,6 @@ public RushEventParticipantsListResponseDto getRushEventParticipants(long rushEv } Boolean isLastPage = !rushParticipantsPage.hasNext(); - // todo 전체 참여자 아닌 옵션별 참여자로 수정하기 return new RushEventParticipantsListResponseDto(rushEventParticipantResponseDtoList, isLastPage, count); } @@ -345,8 +344,14 @@ public LotteryEventWinnerListResponseDto getLotteryEventWinners(int size, int pa if (lotteryWinnerRepository.count() == 0) throw new CustomException(CustomErrorCode.LOTTERY_EVENT_NOT_DRAWN); Page lotteryWinnersPage = null; - if (phoneNumber.isEmpty()) lotteryWinnersPage = lotteryWinnerRepository.findAll(pageable); - else lotteryWinnersPage = lotteryWinnerRepository.findByPhoneNumber(phoneNumber, pageable); + long count; + if (phoneNumber.isEmpty()) { + lotteryWinnersPage = lotteryWinnerRepository.findAll(pageable); + count = lotteryWinnerRepository.count(); + } else { + lotteryWinnersPage = lotteryWinnerRepository.findByPhoneNumber(phoneNumber, pageable); + count = lotteryWinnerRepository.countByPhoneNumber(phoneNumber); + } List lotteryEventWinnerResponseDto = new ArrayList<>(); @@ -356,7 +361,7 @@ public LotteryEventWinnerListResponseDto getLotteryEventWinners(int size, int pa ); } Boolean isLastPage = !lotteryWinnersPage.hasNext(); - return new LotteryEventWinnerListResponseDto(lotteryEventWinnerResponseDto, isLastPage, lotteryWinnerRepository.count()); + return new LotteryEventWinnerListResponseDto(lotteryEventWinnerResponseDto, isLastPage, count); } @Transactional From d22b9240977dcd30f80cf37bd86aa06a7a5cb9b1 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 21:22:59 +0900 Subject: [PATCH 260/289] =?UTF-8?q?chore:=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?import=EB=AC=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/controller/adminController/AdminController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 8d65a24b..9392d61d 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -12,7 +12,6 @@ import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.LotteryEventWinnerListResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantsListResponseDto; -import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.global.response.ResponseDto; import jakarta.validation.Valid; From d73da6a9ab639e2f4aa2caa8214c2d8198d3a2e6 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 21:23:51 +0900 Subject: [PATCH 261/289] =?UTF-8?q?feat:=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EA=B2=80=EC=83=89=20=EB=A1=9C=EC=A7=81=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 --- .../participantsRepository/LotteryParticipantsRepository.java | 4 ++-- .../participantsRepository/LotteryWinnerRepository.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java index 465f155c..b2a2327c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java @@ -15,10 +15,10 @@ public interface LotteryParticipantsRepository extends JpaRepository { Optional findByBaseUser(BaseUser baseUser); - @Query("SELECT p FROM LotteryParticipants p WHERE p.baseUser.id LIKE %:id%") + @Query("SELECT p FROM LotteryParticipants p WHERE p.baseUser.id LIKE :id%") Page findByBaseUser_Id(@Param("id") String id, Pageable pageable); - @Query("SELECT COUNT(p) FROM LotteryParticipants p WHERE p.baseUser.id LIKE %:id%") + @Query("SELECT COUNT(p) FROM LotteryParticipants p WHERE p.baseUser.id LIKE :id%") long countByBaseUser_Id(@Param("id") String id); } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java index 4165984f..e1738855 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryWinnerRepository.java @@ -10,8 +10,8 @@ @Repository public interface LotteryWinnerRepository extends JpaRepository { - @Query("SELECT w FROM LotteryWinners w WHERE w.phoneNumber LIKE %:phoneNumber%") + @Query("SELECT w FROM LotteryWinners w WHERE w.phoneNumber LIKE :phoneNumber%") Page findByPhoneNumber(@Param("phoneNumber") String phoneNumber, Pageable pageable); - @Query("SELECT COUNT(w) FROM LotteryWinners w WHERE w.phoneNumber LIKE %:phoneNumber%") + @Query("SELECT COUNT(w) FROM LotteryWinners w WHERE w.phoneNumber LIKE :phoneNumber%") long countByPhoneNumber(@Param("phoneNumber") String phoneNumber);} From 3a78ca8aa338c61445492748661e07fe6c09c125 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 22:35:29 +0900 Subject: [PATCH 262/289] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=ED=99=98=EA=B2=BD=20WebMvcTest=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventControllerTest.java | 56 +++++++++++++++++-- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java index 5f4459fb..23783489 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java @@ -1,29 +1,73 @@ package JGS.CasperEvent.domain.event.controller.eventController; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; +import JGS.CasperEvent.domain.event.service.adminService.AdminService; +import JGS.CasperEvent.domain.event.service.eventService.LotteryEventService; +import JGS.CasperEvent.domain.event.service.redisService.RedisService; +import JGS.CasperEvent.global.entity.BaseUser; +import JGS.CasperEvent.global.enums.Role; +import JGS.CasperEvent.global.jwt.service.UserService; +import JGS.CasperEvent.global.jwt.util.JwtProvider; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; import org.springframework.http.MediaType; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; + import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -@SpringBootTest -@AutoConfigureMockMvc -@ActiveProfiles("local") +@WebMvcTest(LotteryEventController.class) +@Import(JwtProvider.class) public class LotteryEventControllerTest { @Autowired private MockMvc mockMvc; + @MockBean + private LotteryEventService lotteryEventService; + @MockBean + private UserService userService; + @MockBean + private AdminService adminService; + @MockBean + private RedisService redisService; + + private String phoneNumber; + private String accessToken; + + @BeforeEach + void setUp() throws Exception { + this.phoneNumber = "010-0000-0000"; + + // userService 모킹 + given(userService.verifyUser(any())).willReturn(new BaseUser(this.phoneNumber, Role.USER)); + + // 엑세스 토큰 설정 + this.accessToken = getToken(this.phoneNumber); + + LotteryEventResponseDto lotteryEventResponseDto = new LotteryEventResponseDto( + LocalDateTime.now(), + LocalDateTime.of(2024, 8, 1, 0, 0, 0), + LocalDateTime.of(2024, 8, 31, 0, 0, 0), + ChronoUnit.DAYS.between(LocalDateTime.of(2024, 8, 1, 0, 0, 0), LocalDateTime.of(2024, 8, 31, 0, 0, 0)) + ); + given(lotteryEventService.getLotteryEvent()).willReturn(lotteryEventResponseDto); + } + String getToken(String phoneNumber) throws Exception { String requestBody = String.format(""" { From 9224f519c6eccc3a7f6b884a264a1e3a65d4c8bb Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Thu, 15 Aug 2024 22:43:00 +0900 Subject: [PATCH 263/289] =?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=EA=B8=B0=EB=8C=80=ED=8F=89=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C=20=ED=8E=98=EC=9D=B4=EC=A7=80=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EC=A0=81=EC=9A=A9,=20=EC=B6=94=EC=B2=A8?= =?UTF-8?q?=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EA=B8=B0=EB=8C=80=ED=8F=89=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/adminController/AdminController.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 9392d61d..8f8479a0 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -4,10 +4,7 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.ImageUrlResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventExpectationResponseDto; -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.lotteryEventResponseDto.*; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventOptionResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.LotteryEventWinnerListResponseDto; @@ -162,8 +159,10 @@ public ResponseEntity updateLotteryEvent(@Request // 추첨 이벤트 특정 사용자의 기대평 조회 @GetMapping("/event/lottery/participants/{participantId}/expectations") - public ResponseEntity> getLotteryEventExpectations(@PathVariable("participantId") Long participantId) { - List lotteryEventExpectationResponseDtoList = adminService.getLotteryEventExpectations(participantId); + public ResponseEntity getLotteryEventExpectations(@PathVariable("participantId") Long participantId, + @RequestParam(name = "page", required = false, defaultValue = "0") int page, + @RequestParam(name = "size", required = false, defaultValue = "10") int size) { + LotteryEventExpectationsResponseDto lotteryEventExpectationResponseDtoList = adminService.getLotteryEventExpectations(page, size, participantId); return ResponseEntity.ok(lotteryEventExpectationResponseDtoList); } From cf690d09f5dae6247d05f68e77f5a7f6f0635266 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Thu, 15 Aug 2024 22:56:12 +0900 Subject: [PATCH 264/289] =?UTF-8?q?fix:=20=EB=B3=91=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 66 +++++++++++++++++-- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 6ea49128..6297f402 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -36,12 +36,14 @@ import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import java.time.LocalDateTime; import java.util.*; +import java.util.stream.Collectors; import static JGS.CasperEvent.global.util.RepositoryErrorHandler.findByIdOrElseThrow; @@ -58,6 +60,7 @@ public class AdminService { private final S3Service s3Service; private final CasperBotRepository casperBotRepository; private final LotteryWinnerRepository lotteryWinnerRepository; + private final RedisTemplate casperBotRedisTemplate; public Admin verifyAdmin(AdminRequestDto adminRequestDto) { return adminRepository.findByIdAndPassword(adminRequestDto.getAdminId(), adminRequestDto.getPassword()).orElseThrow(NoSuchElementException::new); @@ -435,15 +438,30 @@ public AdminRushEventOptionResponseDto getRushEventOptions(Long rushEventId) { ); } - public List getLotteryEventExpectations(Long participantId) { + public LotteryEventExpectationsResponseDto getLotteryEventExpectations(int page, int size, Long participantId) { LotteryParticipants lotteryParticipant = lotteryParticipantsRepository.findById(participantId).orElseThrow( () -> new CustomException(CustomErrorCode.USER_NOT_FOUND) ); - List casperBotList = casperBotRepository.findByPhoneNumber(lotteryParticipant.getBaseUser().getId()); - // 기대평을 작성하지 않은 경우(기대평이 빈 문자열인 경우, 삭제된 경우)는 제외하여 반환합니다. - return casperBotList.stream().filter(casperBot -> !casperBot.getExpectation().isEmpty() && !casperBot.isDeleted()).map(LotteryEventExpectationResponseDto::of).toList(); + Pageable pageable = PageRequest.of(page, size); + Page casperBotPage = casperBotRepository.findByPhoneNumberAndActiveExpectations(lotteryParticipant.getBaseUser().getId(), pageable); + + // DTO로 변환합니다. + List lotteryEventExpectationResponseDtoList = casperBotPage.getContent().stream() + .map(casperBot -> new LotteryEventExpectationResponseDto( + casperBot.getCasperId(), + casperBot.getExpectation(), + casperBot.getCreatedAt().toLocalDate(), + casperBot.getCreatedAt().toLocalTime() + )) + .collect(Collectors.toList()); + + // 마지막 페이지 여부 계산 + boolean isLastPage = casperBotPage.isLast(); + + // 결과를 반환합니다. + return new LotteryEventExpectationsResponseDto(lotteryEventExpectationResponseDtoList, isLastPage, casperBotPage.getTotalElements()); } @Transactional @@ -452,7 +470,47 @@ public void deleteLotteryEventExpectation(Long casperId) { () -> new CustomException(CustomErrorCode.CASPERBOT_NOT_FOUND) ); + // todo: 전체 설정에서 가져오도록 변경 + final String LIST_KEY = "recentData"; + + // 긍정적인 문구 리스트 + List positiveMessages = List.of("사랑해 캐스퍼", "캐스퍼 최고!", "캐스퍼와 함께해요!", "캐스퍼 짱!", "캐스퍼는 나의 친구!"); + + // 랜덤으로 긍정적인 문구 선택 + String randomPositiveMessage = positiveMessages.get(new Random().nextInt(positiveMessages.size())); + + // isDeleted = true 로 업데이트 casperBot.deleteExpectation(); + + // Redis에서 모든 데이터를 가져옵니다. + List allData = casperBotRedisTemplate.opsForList().range(LIST_KEY, 0, -1); + + if (allData != null) { + // 해당하는 CasperBotId의 데이터를 업데이트합니다. + List updatedData = allData.stream() + .map(data -> { + if (casperId.equals(data.casperId())) { + return new CasperBotResponseDto( + data.casperId(), + data.eyeShape(), + data.eyePosition(), + data.mouthShape(), + data.color(), + data.sticker(), + data.name(), + randomPositiveMessage // 랜덤으로 선택된 긍정적인 문구로 기대평 필드 변경 + ); + } + return data; + }) + .collect(Collectors.toList()); + + // Redis에서 현재 리스트를 삭제합니다. + casperBotRedisTemplate.delete(LIST_KEY); + + // 업데이트된 리스트를 Redis에 다시 추가합니다. + casperBotRedisTemplate.opsForList().leftPushAll(LIST_KEY, updatedData); + } } public static Page paginateList(List list, int page, int size) { From ff7f400e6e1eb6e6d532cd39360d9d55f547b502 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Thu, 15 Aug 2024 22:47:51 +0900 Subject: [PATCH 265/289] =?UTF-8?q?feat:=20=EA=B8=B0=EB=8C=80=ED=8F=89?= =?UTF-8?q?=EC=9D=B4=20=EC=82=AD=EC=A0=9C=EB=90=90=EC=9D=8C=EC=9D=84=20?= =?UTF-8?q?=EB=82=98=ED=83=80=EB=82=B4=EB=8A=94=20isDeleted=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/casperBot/CasperBot.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java index 410387dc..8bc7c5fe 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java @@ -25,6 +25,7 @@ public class CasperBot extends BaseEntity { private int sticker; private String name; private String expectation; + private boolean isDeleted; public CasperBot() { @@ -41,15 +42,7 @@ public CasperBot(CasperBotRequestDto requestDto, String phoneNumber) { this.expectation = requestDto.getExpectation(); } - public CasperBot deleteExpectation() { - if (!this.expectation.isEmpty()) { - this.expectation = "삭제된 기대평입니다."; - } - - return this; - } - - public boolean isDeleted() { - return this.expectation.equals("삭제된 기대평입니다."); + public void deleteExpectation() { + this.isDeleted = true; } } From c5d6d6db588ca5aa3cc425e30d4d571d1490c338 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Thu, 15 Aug 2024 22:48:27 +0900 Subject: [PATCH 266/289] =?UTF-8?q?feat:=20=EA=B8=B0=EB=8C=80=ED=8F=89?= =?UTF-8?q?=EC=9D=B4=20=EC=97=86=EA=B1=B0=EB=82=98,=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=EB=90=9C=20=EA=B8=B0=EB=8C=80=ED=8F=89=EC=9D=80=20=EC=A0=9C?= =?UTF-8?q?=EC=99=B8=ED=95=98=EA=B3=A0=20=EC=A1=B0=ED=9A=8C=ED=95=98?= =?UTF-8?q?=EB=8A=94=20JPQL=20=EC=BF=BC=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/repository/CasperBotRepository.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java index ebdb75b2..de81cb13 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java @@ -1,12 +1,17 @@ package JGS.CasperEvent.domain.event.repository; import JGS.CasperEvent.domain.event.entity.casperBot.CasperBot; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; @Repository public interface CasperBotRepository extends JpaRepository { - List findByPhoneNumber(String phoneNumber); + @Query("SELECT c FROM CasperBot c WHERE c.phoneNumber = :phoneNumber AND c.isDeleted = false AND c.expectation <> ''") + Page findByPhoneNumberAndActiveExpectations(@Param("phoneNumber") String phoneNumber, Pageable pageable); } From 978eba3017cd9da1dd1385e5b8f71113dbf3a7dd Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Thu, 15 Aug 2024 22:48:44 +0900 Subject: [PATCH 267/289] =?UTF-8?q?feat:=20=EC=A0=84=EC=B2=B4=20=EA=B8=B0?= =?UTF-8?q?=EB=8C=80=ED=8F=89=EC=9D=84=20=EB=B0=98=ED=99=98=ED=95=98?= =?UTF-8?q?=EB=8A=94=20DTO=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventExpectationsResponseDto.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventExpectationsResponseDto.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventExpectationsResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventExpectationsResponseDto.java new file mode 100644 index 00000000..264370ae --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/lotteryEventResponseDto/LotteryEventExpectationsResponseDto.java @@ -0,0 +1,7 @@ +package JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto; + +import java.util.List; + +public record LotteryEventExpectationsResponseDto(List expectations, + Boolean isLastPage, long totalExpectations) { +} From 631ab87d92cb91a6dfea11ad94584e1f655305c2 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Fri, 16 Aug 2024 00:06:25 +0900 Subject: [PATCH 268/289] =?UTF-8?q?feat:=20rusEventId,=20userId=EB=A5=BC?= =?UTF-8?q?=20=EC=9D=B4=EC=9A=A9=ED=95=98=EC=97=AC=20=ED=95=B4=EB=8B=B9=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=EC=9D=98=20=EB=93=B1=EC=88=98=EB=A5=BC=20?= =?UTF-8?q?=EA=B3=84=EC=82=B0=ED=95=98=EB=8A=94=20JPQL=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RushParticipantsRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java index e5b7e37a..e3904ef2 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java @@ -26,6 +26,14 @@ long findUserRankByEventIdAndUserIdAndOptionId(@Param("eventId") Long eventId, @Param("userId") String userId, @Param("optionId") int optionId); + @Query("SELECT COUNT(rp) + 1 FROM RushParticipants rp " + + "WHERE rp.rushEvent.rushEventId = :eventId " + + "AND rp.id < (SELECT rp2.id FROM RushParticipants rp2 " + + "WHERE rp2.rushEvent.rushEventId = :eventId " + + "AND rp2.baseUser.id = :userId)") + long findUserRankByEventIdAndUserId(@Param("eventId") Long eventId, + @Param("userId") String userId); + long countAllByOptionId(int optionId); @Query("SELECT rp.optionId FROM RushParticipants rp WHERE rp.baseUser.id = :userId") From 63be3f697a3e62f9b0114587396e8e8d1e42978c Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Fri, 16 Aug 2024 00:07:11 +0900 Subject: [PATCH 269/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=EC=97=90=EC=84=9C=20=EB=8B=B9?= =?UTF-8?q?=EC=B2=A8=EC=9E=90=EB=A5=BC=20=EC=84=A0=EB=B3=84=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventService/RushEventService.java | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java index f1ec704b..5b7b7197 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java @@ -67,7 +67,7 @@ public RushEventListResponseDto getAllRushEvents() { totalStartDate, totalEndDate, activePeriod - ); + ); } // 응모 여부 조회 @@ -109,24 +109,45 @@ public RushEventRateResponseDto getRushEventRate(BaseUser user) { // 해당 요청은 무조건 응모한 유저일 때만 요청 가능하다고 가정 @Transactional public RushEventResultResponseDto getRushEventResult(BaseUser user) { - Long todayEventId = getTodayRushEvent().rushEventId(); + RushEventResponseDto todayRushEvent = getTodayRushEvent(); // 최종 선택 비율을 조회 // TODO: 레디스에 캐시 RushEventRateResponseDto rushEventRateResponseDto = getRushEventRate(user); + long leftOption = rushEventRateResponseDto.leftOption(); + long rightOption = rushEventRateResponseDto.rightOption(); + + // 동점인 경우 + if (leftOption == rightOption) { + // 전체 참여자에서 등수 계산하기 + long rank = rushParticipantsRepository.findUserRankByEventIdAndUserId(todayRushEvent.rushEventId(), user.getId()); - // 해당 이벤트의 당첨자 수를 가져옴 - int winnerCount = rushEventRepository.findByRushEventId(todayEventId).getWinnerCount(); + // 각 옵션 선택지를 더하여 전체 참여자 수 구하기 + long totalParticipants = rushEventRateResponseDto.leftOption() + rushEventRateResponseDto.rightOption(); + // 당첨 여부 + boolean isWinner = rank <= todayRushEvent.winnerCount(); + + return new RushEventResultResponseDto(rushEventRateResponseDto, rank, totalParticipants, isWinner); + } + + // 해당 유저가 선택한 옵션을 가져옴 int optionId = rushEventRateResponseDto.optionId(); + long totalParticipants = (optionId == 1 ? leftOption : rightOption); + // eventId, userId, optionId 를 이용하여 해당 유저가 응모한 선택지에서 등수를 가져옴 - long rank = rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(todayEventId, user.getId(), optionId); + long rank = rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(todayRushEvent.rushEventId(), user.getId(), optionId); + + // 해당 유저가 선택한 옵션이 패배한 경우 + if ((optionId == 1 && leftOption < rightOption) || (optionId == 2 && leftOption > rightOption)) { + return new RushEventResultResponseDto(rushEventRateResponseDto, rank, totalParticipants, false); + } - // 해당 선택지를 선택한 모든 유저 수를 가져옴 - long totalParticipants = rushParticipantsRepository.countAllByOptionId(optionId); + // 당첨 여부 + boolean isWinner = rank <= todayRushEvent.winnerCount(); - return new RushEventResultResponseDto(rushEventRateResponseDto, rank, totalParticipants, winnerCount); + return new RushEventResultResponseDto(rushEventRateResponseDto, rank, totalParticipants, isWinner); } @Transactional @@ -174,7 +195,7 @@ public void setTodayEventToRedis() { RushEvent rushEvent = new RushEvent( startDateTime.plusDays(i), // 이벤트 시작 날짜 endDateTime.plusDays(i), // 이벤트 종료 날짜 - 315, // 우승자 수 (winnerCount) + 3, // 우승자 수 (winnerCount) "http://example.com/prize" + (i + 1) + ".jpg", // 상 이미지 URL "Prize Description " + (i + 1) // 상 설명 ); From c2e7fcbdc17bf2bcbbcba9e5477aa70dd1077710 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Fri, 16 Aug 2024 00:07:44 +0900 Subject: [PATCH 270/289] =?UTF-8?q?feat:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EA=B2=B0=EA=B3=BC=20DTO=EC=97=90?= =?UTF-8?q?=20=ED=95=B4=EB=8B=B9=20=EC=9C=A0=EC=A0=80=EC=9D=98=20=EB=8B=B9?= =?UTF-8?q?=EC=B2=A8=20=EC=97=AC=EB=B6=80=20=ED=95=84=EB=93=9C=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 --- .../rushEventResponseDto/RushEventResultResponseDto.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventResultResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventResultResponseDto.java index 8d65ce19..acba931f 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventResultResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventResultResponseDto.java @@ -10,13 +10,13 @@ public class RushEventResultResponseDto { private final long rightOption; private final long rank; private final long totalParticipants; - private final long winnerCount; + private final boolean isWinner; - public RushEventResultResponseDto(RushEventRateResponseDto rushEventRateResponseDto, long rank, long totalParticipants, long winnerCount) { + public RushEventResultResponseDto(RushEventRateResponseDto rushEventRateResponseDto, long rank, long totalParticipants, boolean isWinner) { this.leftOption = rushEventRateResponseDto.leftOption(); this.rightOption = rushEventRateResponseDto.rightOption(); this.rank = rank; this.totalParticipants = totalParticipants; - this.winnerCount = winnerCount; + this.isWinner = isWinner; } } From 4775fc8d86246104691ab1f09343e31ea654380b Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 01:53:20 +0900 Subject: [PATCH 271/289] =?UTF-8?q?test:=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=20API=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventController.java | 4 +- .../LotteryEventControllerTest.java | 234 ++---------------- 2 files changed, 21 insertions(+), 217 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 416ad5fa..d2e6b4e5 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 @@ -34,13 +34,15 @@ public LotteryEventController(LotteryEventService lotteryEventService, RedisServ this.lotteryEventService = lotteryEventService; this.redisService = redisService; } - // 추첨 이벤트 조회 API -> 가짜 API + + // 추첨 이벤트 조회 API @GetMapping public ResponseEntity getLotteryEvent(){ return ResponseEntity .status(HttpStatus.OK) .body(lotteryEventService.getLotteryEvent()); } + // 캐스퍼 봇 생성 API @PostMapping("/casperBot") public ResponseEntity postCasperBot( diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java index 23783489..9460c8c4 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java @@ -46,8 +46,8 @@ public class LotteryEventControllerTest { @MockBean private RedisService redisService; - private String phoneNumber; - private String accessToken; + public String phoneNumber; + public String accessToken; @BeforeEach void setUp() throws Exception { @@ -59,8 +59,9 @@ void setUp() throws Exception { // 엑세스 토큰 설정 this.accessToken = getToken(this.phoneNumber); + // 추첨 이벤트 조회 LotteryEventResponseDto lotteryEventResponseDto = new LotteryEventResponseDto( - LocalDateTime.now(), + LocalDateTime.of(2024, 8, 15, 0, 0, 0), LocalDateTime.of(2024, 8, 1, 0, 0, 0), LocalDateTime.of(2024, 8, 31, 0, 0, 0), ChronoUnit.DAYS.between(LocalDateTime.of(2024, 8, 1, 0, 0, 0), LocalDateTime.of(2024, 8, 31, 0, 0, 0)) @@ -87,221 +88,22 @@ String getToken(String phoneNumber) throws Exception { return "Bearer " + jsonString.substring(start, end); } + @Test + @DisplayName("추첨 이벤트 조회 API 성공 테스트") + void getLotteryEventAndServerTime() throws Exception { + //given + String token = this.accessToken; - @Nested - @DisplayName("캐스퍼 봇 생성 테스트") - class CasperBotTest { - //TODO: Expecation이 없을때, 있을때 값 증가 테스트 - //TODO: DB에 없는 사용자 테스트 작성 - @Test - @DisplayName("캐스퍼 봇 생성 성공 테스트") - public void createCasperBotSuccessTest() throws Exception { - //given - String accessToken = getToken("010-0000-0000"); + //when + ResultActions perform = mockMvc.perform(get("/event/lottery") + .contentType(MediaType.APPLICATION_JSON)); - String casperBotRequest = """ - { - "eyeShape": "2", - "eyePosition": "1", - "mouthShape": "4", - "color": "2", - "sticker": "4", - "name": "myCasperBot", - "expectation": "myExpectation" - } - """; + //then + perform.andExpect(status().isOk()) + .andExpect(jsonPath("$.serverDateTime").value("2024-08-15T00:00:00")) + .andExpect(jsonPath("$.eventStartDate").value("2024-08-01T00:00:00")) + .andExpect(jsonPath("$.eventEndDate").value("2024-08-31T00:00:00")) + .andDo(print()); - //when - ResultActions perform = mockMvc.perform(post("/event/lottery/casperBot") - .contentType(MediaType.APPLICATION_JSON) - .content(casperBotRequest) - .header("Authorization", accessToken)); - - //then - perform - .andExpect(status().isCreated()) - .andExpect(jsonPath("$.eyeShape").value(2)) - .andExpect(jsonPath("$.eyePosition").value(1)) - .andExpect(jsonPath("$.mouthShape").value(4)) - .andExpect(jsonPath("$.color").value(2)) - .andExpect(jsonPath("$.sticker").value(4)) - .andExpect(jsonPath("$.name").value("myCasperBot")) - .andExpect(jsonPath("$.expectation").value("myExpectation")) - .andDo(print()); - } - - @Test - @DisplayName("캐스퍼 봇 생성 실패 테스트 - 필수 필드 없음") - void createCasperBotFailureTest_RequiredFieldNotExist() throws Exception { - String accessToken = getToken("010-0000-0000"); - //given - String casperBotRequest = """ - { - "eye_shape": "2", - "eye_position": "1", - "mouth_shape": "4", - "color": "2", - "sticker": "4", - "expectation": "myExpectation" - } - """; - - - //when - ResultActions perform = mockMvc.perform(post("/event/lottery/casperBot") - .contentType(MediaType.APPLICATION_JSON) - .content(casperBotRequest) - .header("Authorization", accessToken)); - - //then - perform.andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.errorCode").value("INVALID_PARAMETER")) - .andDo(print()); - - } - - @Test - @DisplayName("캐스퍼 봇 생성 실패 테스트 - 잘못된 값") - void createCasperBotSuccessTest_WrongValue() throws Exception { - //given - String accessToken = getToken("010-0000-0000"); - String casperBotRequest = """ - { - "eyeShape": "15", - "eyePosition": "1", - "mouthShape": "4", - "color": "2", - "sticker": "4", - "name": "myCasperBot", - "expectation": "myExpectation" - }"""; - - //when - ResultActions perform = mockMvc.perform(post("/event/lottery/casperBot") - .contentType(MediaType.APPLICATION_JSON) - .content(casperBotRequest) - .header("Authorization", accessToken)); - - //then - perform.andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.errorCode").value("INVALID_PARAMETER")) - .andDo(print()); - } - - @Test - @DisplayName("캐스퍼 봇 생성 실패 테스트 - 인증 토큰 없음") - void createCasperBotSuccessTest_CookieNotPresent() throws Exception { - //given - String casperBotRequest = """ - { - "eyeShape": "1", - "eyePosition": "1", - "mouthShape": "4", - "color": "2", - "sticker": "4", - "name": "myCasperBot", - "expectation": "myExpectation" - } - """; - - //when - ResultActions perform = mockMvc.perform(post("/event/lottery/casperBot") - .contentType(MediaType.APPLICATION_JSON) - .content(casperBotRequest)); - - //then - perform.andExpect(status().isUnauthorized()) - .andDo(print()); - - } - } - - @Nested - @DisplayName("캐스퍼 봇 응모 조회") - class CasperBotAppliedTest { - @Test - @DisplayName("캐스퍼 봇 응모 여부 조회 성공 - 유저가 존재할 경우") - void userHasAppliedCasperBotSuccessTest_PresentUser() throws Exception { - String accessToken = getToken("010-0000-0000"); - - String casperBotRequest = """ - { - "eyeShape": "2", - "eyePosition": "1", - "mouthShape": "4", - "color": "2", - "sticker": "4", - "name": "myCasperBot", - "expectation": "myExpectation" - } - """; - //when - mockMvc.perform(post("/event/lottery/casperBot") - .contentType(MediaType.APPLICATION_JSON) - .content(casperBotRequest) - .header("Authorization", accessToken)); - - //when - ResultActions perform = mockMvc.perform(get("/event/lottery/applied") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", accessToken)); - - //then - perform.andExpect(status().isOk()) - .andDo(print()); - - } - - @Test - @DisplayName("캐스퍼 봇 응모 여부 조회 성공 - 유저가 존재하지 않는 경우") - void userHasAppliedCasperBotSuccessTest_NotPresentUser() throws Exception { - //given - String accessToken = getToken("010-1234-1234"); - - //when - ResultActions perform = mockMvc.perform(get("/event/lottery/applied") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", accessToken)); - //then - perform.andExpect(status().isNotFound()) - .andExpect(jsonPath("$.errorCode").value("USER_NOT_FOUND")) - .andExpect(jsonPath("$.message").value("응모하지 않은 사용자입니다.")) - .andDo(print()); - - } - - @Test - @DisplayName("캐스퍼 봇 응모 여부 조회 실패 - 토큰이 없는 경우") - void userHasAppliedCasperBotFailureTest_NotPresentCookie() throws Exception { - //when - ResultActions perform = mockMvc.perform(get("/event/lottery/applied") - .contentType(MediaType.APPLICATION_JSON)); - //then - perform.andExpect(status().isUnauthorized()) - .andExpect(jsonPath("$.errorCode").value("JWT_MISSING")) - .andExpect(jsonPath("$.message").value("인증 토큰이 존재하지 않습니다.")) - .andDo(print()); - - } - } - - @Nested - @DisplayName("캐스퍼 봇 조회 테스트") - class CasperBotResponseDtoTest { - @Test - @DisplayName("캐스퍼 봇 조회 테스트 성공 - Redis") - void GetCasperBotSuccessTest_redis() throws Exception { - for (int i = 0; i < 100; i++) { - ResultActions perform = mockMvc.perform(get("/event/lottery/caspers")); - - //then - perform.andExpect(status().isOk()) - .andExpect(result -> { - String responseBody = result.getResponse().getContentAsString(); - assertFalse(responseBody.isEmpty(), "Response body should not be empty"); - }); - - } - } } } \ No newline at end of file From 196176f7cd5043d17001430f50d3a87461759aae Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 12:22:15 +0900 Subject: [PATCH 272/289] =?UTF-8?q?feat:=20byte[]=20->=20String=20?= =?UTF-8?q?=EC=9D=B8=EC=BD=94=EB=94=A9,=20String=20->=20byte[]=20=EB=94=94?= =?UTF-8?q?=EC=BD=94=EB=94=A9=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CasperEvent/global/util/Base62Utils.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java b/Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java index bd63e1d3..20e5a886 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java +++ b/Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java @@ -22,4 +22,23 @@ public static long decode(String str){ } return result; } + + public static String encode(byte[] data) { + StringBuilder sb = new StringBuilder(); + for (byte b : data) { + int value = b & 0xFF; + sb.append(encode(value)); + } + return sb.toString(); + } + + public static byte[] decodeToBytes(String str) { + int length = str.length() / 2; + byte[] data = new byte[length]; + for (int i = 0; i < length; i++) { + String part = str.substring(i * 2, i * 2 + 2); + data[i] = (byte) decode(part); + } + return data; + } } From 77710931ecf3619f901ce580252d11525050aed5 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 12:22:36 +0900 Subject: [PATCH 273/289] =?UTF-8?q?feat:=20AES=20=EC=95=94=ED=98=B8?= =?UTF-8?q?=ED=99=94=20=EC=8B=9C=20Base62=20=EC=9D=B4=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/JGS/CasperEvent/global/util/AESUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java b/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java index 1fc26b96..4722d2ac 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java +++ b/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java @@ -17,13 +17,13 @@ public static String encrypt(String plainText, SecretKey key) throws NoSuchPaddi Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] encryptedBytes = cipher.doFinal(plainText.getBytes()); - return Base64.getEncoder().encodeToString(encryptedBytes); + return Base62Utils.encode(encryptedBytes); } public static String decrypt(String encryptedText, SecretKey key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, key); - byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(encryptedText)); + byte[] decryptedBytes = cipher.doFinal(Base62Utils.decodeToBytes(encryptedText)); return new String(decryptedBytes); } From d4a6dd85775a07fcbc36e2abc4fbb059b1b2a077 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 15:49:22 +0900 Subject: [PATCH 274/289] =?UTF-8?q?feat:=20AES=20=EC=95=94=ED=98=B8?= =?UTF-8?q?=ED=99=94=20=EC=8B=9C=20UrlSafe=ED=95=9C=20Base64=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/JGS/CasperEvent/global/util/AESUtils.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java b/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java index 4722d2ac..e6bbec9d 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java +++ b/Server/src/main/java/JGS/CasperEvent/global/util/AESUtils.java @@ -17,15 +17,13 @@ public static String encrypt(String plainText, SecretKey key) throws NoSuchPaddi Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] encryptedBytes = cipher.doFinal(plainText.getBytes()); - return Base62Utils.encode(encryptedBytes); + return Base64.getUrlEncoder().encodeToString(encryptedBytes); } public static String decrypt(String encryptedText, SecretKey key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, key); - byte[] decryptedBytes = cipher.doFinal(Base62Utils.decodeToBytes(encryptedText)); + byte[] decryptedBytes = cipher.doFinal(Base64.getUrlDecoder().decode(encryptedText)); return new String(decryptedBytes); } - - } From 48b64d0bb19e045c63611d8ec2fa433bdf4b985a Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 15:49:34 +0900 Subject: [PATCH 275/289] =?UTF-8?q?chore:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=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 --- .../CasperEvent/global/util/Base62Utils.java | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java b/Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java index 20e5a886..a32e7839 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java +++ b/Server/src/main/java/JGS/CasperEvent/global/util/Base62Utils.java @@ -15,30 +15,11 @@ public static String encode(long number) { return sb.reverse().toString(); } - public static long decode(String str){ + public static long decode(String str) { long result = 0; for (int i = 0; i < str.length(); i++) { result = result * 62 + BASE62_CHARS.indexOf(str.charAt(i)); } return result; } - - public static String encode(byte[] data) { - StringBuilder sb = new StringBuilder(); - for (byte b : data) { - int value = b & 0xFF; - sb.append(encode(value)); - } - return sb.toString(); - } - - public static byte[] decodeToBytes(String str) { - int length = str.length() / 2; - byte[] data = new byte[length]; - for (int i = 0; i < length; i++) { - String part = str.substring(i * 2, i * 2 + 2); - data[i] = (byte) decode(part); - } - return data; - } } From 1d000a3fbfa951e2e592db31dc9194aab0056a4c Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 15:51:26 +0900 Subject: [PATCH 276/289] =?UTF-8?q?chore:=20BaseUser=EC=97=90=20EqualsAndH?= =?UTF-8?q?ashCode=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/JGS/CasperEvent/global/entity/BaseUser.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java b/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java index 09f06708..96c31e65 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java +++ b/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java @@ -5,10 +5,12 @@ import JGS.CasperEvent.global.enums.Role; import com.fasterxml.jackson.annotation.JsonManagedReference; import jakarta.persistence.*; +import lombok.EqualsAndHashCode; import lombok.Getter; @Getter @Entity +@EqualsAndHashCode @Inheritance(strategy = InheritanceType.JOINED) public class BaseUser extends BaseEntity { @Id From 450ab5624dee06dc44d7e9a713e7a4b48aeca0fb Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 15:51:42 +0900 Subject: [PATCH 277/289] =?UTF-8?q?chore:=20CasperBotRequestDto=EC=97=90?= =?UTF-8?q?=20EqualsAndHashCode=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/RequestDto/lotteryEventDto/CasperBotRequestDto.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/CasperBotRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/CasperBotRequestDto.java index d2780df1..9a85979d 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/CasperBotRequestDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/lotteryEventDto/CasperBotRequestDto.java @@ -3,9 +3,13 @@ import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; +import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.Getter; @Getter +@Builder +@EqualsAndHashCode public class CasperBotRequestDto { @NotNull(message = "눈 모양 값은 필수 필드입니다.") From db72b3ef7c2a4f257a0efe852d0537014116683c Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 15:52:48 +0900 Subject: [PATCH 278/289] =?UTF-8?q?test:=20=EC=BA=90=EC=8A=A4=ED=8D=BC=20?= =?UTF-8?q?=EB=B4=87=20=EC=83=9D=EC=84=B1=20=EC=84=B1=EA=B3=B5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventControllerTest.java | 105 +++++++++++++----- 1 file changed, 80 insertions(+), 25 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java index 9460c8c4..e81cd4d7 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java @@ -1,6 +1,9 @@ package JGS.CasperEvent.domain.event.controller.eventController; +import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.CasperBotRequestDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.CasperBotResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; +import JGS.CasperEvent.domain.event.entity.casperBot.CasperBot; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.domain.event.service.eventService.LotteryEventService; import JGS.CasperEvent.domain.event.service.redisService.RedisService; @@ -8,9 +11,9 @@ import JGS.CasperEvent.global.enums.Role; import JGS.CasperEvent.global.jwt.service.UserService; import JGS.CasperEvent.global.jwt.util.JwtProvider; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -20,11 +23,17 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import java.lang.runtime.ObjectMethods; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -36,6 +45,8 @@ public class LotteryEventControllerTest { @Autowired private MockMvc mockMvc; + @Autowired + ObjectMapper objectMapper; @MockBean private LotteryEventService lotteryEventService; @@ -46,15 +57,20 @@ public class LotteryEventControllerTest { @MockBean private RedisService redisService; - public String phoneNumber; - public String accessToken; + private BaseUser user; + private String phoneNumber; + private String accessToken; + private CasperBot casperBot; + private CasperBotRequestDto casperBotRequest; + private CasperBotResponseDto casperBotResponse; + @BeforeEach void setUp() throws Exception { this.phoneNumber = "010-0000-0000"; - + user = new BaseUser(this.phoneNumber, Role.USER); // userService 모킹 - given(userService.verifyUser(any())).willReturn(new BaseUser(this.phoneNumber, Role.USER)); + given(userService.verifyUser(any())).willReturn(user); // 엑세스 토큰 설정 this.accessToken = getToken(this.phoneNumber); @@ -66,9 +82,67 @@ void setUp() throws Exception { LocalDateTime.of(2024, 8, 31, 0, 0, 0), ChronoUnit.DAYS.between(LocalDateTime.of(2024, 8, 1, 0, 0, 0), LocalDateTime.of(2024, 8, 31, 0, 0, 0)) ); + given(lotteryEventService.getLotteryEvent()).willReturn(lotteryEventResponseDto); } + @Test + @DisplayName("추첨 이벤트 조회 API 성공 테스트") + void getLotteryEventAndServerTime() throws Exception { + //given + + //when + ResultActions perform = mockMvc.perform(get("/event/lottery") + .contentType(MediaType.APPLICATION_JSON)); + + //then + perform.andExpect(status().isOk()) + .andExpect(jsonPath("$.serverDateTime").value("2024-08-15T00:00:00")) + .andExpect(jsonPath("$.eventStartDate").value("2024-08-01T00:00:00")) + .andExpect(jsonPath("$.eventEndDate").value("2024-08-31T00:00:00")) + .andDo(print()); + + } + + @Test + @DisplayName("캐스퍼 봇 생성 API 성공 테스트") + void postCasperBot() throws Exception { + //given + casperBotRequest = CasperBotRequestDto.builder() + .eyeShape(0) + .eyePosition(0) + .mouthShape(0) + .color(0) + .sticker(0) + .name("name") + .expectation("expectation") + .referralId("QEszP1K8IqcapUHAVwikXA==").build(); + + CasperBot casperBot = new CasperBot(casperBotRequest, "010-0000-0000"); + String requestBody = objectMapper.writeValueAsString(casperBotRequest); + + given(lotteryEventService.postCasperBot(user, casperBotRequest)) + .willReturn(CasperBotResponseDto.of(casperBot)); + + //when + ResultActions perform = mockMvc.perform(post("/event/lottery/casperBot") + .header("Authorization", accessToken) + .contentType(MediaType.APPLICATION_JSON) + .content(requestBody)); + + //then + perform.andExpect(status().isCreated()) + .andExpect(jsonPath("$.eyeShape").value(0)) + .andExpect(jsonPath("$.eyePosition").value(0)) + .andExpect(jsonPath("$.mouthShape").value(0)) + .andExpect(jsonPath("$.color").value(0)) + .andExpect(jsonPath("$.sticker").value(0)) + .andExpect(jsonPath("$.name").value("name")) + .andExpect(jsonPath("$.expectation").value("expectation")) + .andDo(print()); +// .andExpect(); + } + String getToken(String phoneNumber) throws Exception { String requestBody = String.format(""" { @@ -87,23 +161,4 @@ String getToken(String phoneNumber) throws Exception { return "Bearer " + jsonString.substring(start, end); } - - @Test - @DisplayName("추첨 이벤트 조회 API 성공 테스트") - void getLotteryEventAndServerTime() throws Exception { - //given - String token = this.accessToken; - - //when - ResultActions perform = mockMvc.perform(get("/event/lottery") - .contentType(MediaType.APPLICATION_JSON)); - - //then - perform.andExpect(status().isOk()) - .andExpect(jsonPath("$.serverDateTime").value("2024-08-15T00:00:00")) - .andExpect(jsonPath("$.eventStartDate").value("2024-08-01T00:00:00")) - .andExpect(jsonPath("$.eventEndDate").value("2024-08-31T00:00:00")) - .andDo(print()); - - } } \ No newline at end of file From c98350d87bc4d7e8123b3cd2d92d94c809b62c25 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 16:03:22 +0900 Subject: [PATCH 279/289] =?UTF-8?q?test:=20=EC=9D=91=EB=AA=A8=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EC=A1=B0=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventControllerTest.java | 67 ++++++++++++++----- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java index e81cd4d7..6b64fb72 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java @@ -3,7 +3,9 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.CasperBotRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.CasperBotResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryParticipantResponseDto; import JGS.CasperEvent.domain.event.entity.casperBot.CasperBot; +import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.domain.event.service.eventService.LotteryEventService; import JGS.CasperEvent.domain.event.service.redisService.RedisService; @@ -63,12 +65,17 @@ public class LotteryEventControllerTest { private CasperBot casperBot; private CasperBotRequestDto casperBotRequest; private CasperBotResponseDto casperBotResponse; - + private LotteryParticipants lotteryParticipants; + private LotteryEventResponseDto lotteryEventResponseDto; @BeforeEach void setUp() throws Exception { this.phoneNumber = "010-0000-0000"; + + // 베이스 유저 생성 user = new BaseUser(this.phoneNumber, Role.USER); + // 추첨 이벤트 참여자 + lotteryParticipants = new LotteryParticipants(user); // userService 모킹 given(userService.verifyUser(any())).willReturn(user); @@ -76,20 +83,33 @@ void setUp() throws Exception { this.accessToken = getToken(this.phoneNumber); // 추첨 이벤트 조회 - LotteryEventResponseDto lotteryEventResponseDto = new LotteryEventResponseDto( + lotteryEventResponseDto = new LotteryEventResponseDto( LocalDateTime.of(2024, 8, 15, 0, 0, 0), LocalDateTime.of(2024, 8, 1, 0, 0, 0), LocalDateTime.of(2024, 8, 31, 0, 0, 0), ChronoUnit.DAYS.between(LocalDateTime.of(2024, 8, 1, 0, 0, 0), LocalDateTime.of(2024, 8, 31, 0, 0, 0)) ); - given(lotteryEventService.getLotteryEvent()).willReturn(lotteryEventResponseDto); + casperBotRequest = CasperBotRequestDto.builder() + .eyeShape(0) + .eyePosition(0) + .mouthShape(0) + .color(0) + .sticker(0) + .name("name") + .expectation("expectation") + .referralId("QEszP1K8IqcapUHAVwikXA==").build(); + + casperBot = new CasperBot(casperBotRequest, "010-0000-0000"); + + casperBotResponse = CasperBotResponseDto.of(casperBot); } @Test @DisplayName("추첨 이벤트 조회 API 성공 테스트") void getLotteryEventAndServerTime() throws Exception { //given + given(lotteryEventService.getLotteryEvent()).willReturn(lotteryEventResponseDto); //when ResultActions perform = mockMvc.perform(get("/event/lottery") @@ -101,26 +121,13 @@ void getLotteryEventAndServerTime() throws Exception { .andExpect(jsonPath("$.eventStartDate").value("2024-08-01T00:00:00")) .andExpect(jsonPath("$.eventEndDate").value("2024-08-31T00:00:00")) .andDo(print()); - } @Test @DisplayName("캐스퍼 봇 생성 API 성공 테스트") void postCasperBot() throws Exception { //given - casperBotRequest = CasperBotRequestDto.builder() - .eyeShape(0) - .eyePosition(0) - .mouthShape(0) - .color(0) - .sticker(0) - .name("name") - .expectation("expectation") - .referralId("QEszP1K8IqcapUHAVwikXA==").build(); - - CasperBot casperBot = new CasperBot(casperBotRequest, "010-0000-0000"); String requestBody = objectMapper.writeValueAsString(casperBotRequest); - given(lotteryEventService.postCasperBot(user, casperBotRequest)) .willReturn(CasperBotResponseDto.of(casperBot)); @@ -140,7 +147,33 @@ void postCasperBot() throws Exception { .andExpect(jsonPath("$.name").value("name")) .andExpect(jsonPath("$.expectation").value("expectation")) .andDo(print()); -// .andExpect(); + } + + @Test + @DisplayName("응모 여부 조회 성공 테스트") + void GetLotteryParticipantsSuccessTest() throws Exception { + //given + given(lotteryEventService.getLotteryParticipant(user)) + .willReturn(LotteryParticipantResponseDto.of(lotteryParticipants, casperBotResponse)); + + //when + ResultActions perform = mockMvc.perform(get("/event/lottery/applied") + .header("Authorization", accessToken) + .contentType(MediaType.APPLICATION_JSON)); + + //then + perform.andExpect(status().isOk()) + .andExpect(jsonPath("$.linkClickedCount").value(0)) + .andExpect(jsonPath("$.expectations").value(0)) + .andExpect(jsonPath("$.appliedCount").value(1)) + .andExpect(jsonPath("$.casperBot.eyeShape").value(0)) + .andExpect(jsonPath("$.casperBot.eyePosition").value(0)) + .andExpect(jsonPath("$.casperBot.mouthShape").value(0)) + .andExpect(jsonPath("$.casperBot.color").value(0)) + .andExpect(jsonPath("$.casperBot.sticker").value(0)) + .andExpect(jsonPath("$.casperBot.name").value("name")) + .andExpect(jsonPath("$.casperBot.expectation").value("expectation")) + .andDo(print()); } String getToken(String phoneNumber) throws Exception { From 670f556cc98e270003198c2755e49fb88d4bd64b Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 16:10:39 +0900 Subject: [PATCH 280/289] =?UTF-8?q?test:=20=EC=B5=9C=EA=B7=BC=20100?= =?UTF-8?q?=EA=B0=9C=20=EC=BA=90=EC=8A=A4=ED=8D=BC=20=EB=B4=87=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventControllerTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java index 6b64fb72..16149697 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java @@ -33,6 +33,8 @@ import java.security.NoSuchAlgorithmException; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -176,6 +178,29 @@ void GetLotteryParticipantsSuccessTest() throws Exception { .andDo(print()); } + @Test + @DisplayName("최근 100개 캐스퍼 봇 조회 성공 테스트") + void getCasperBotsSuccessTest() throws Exception { + //given + List recentData = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + recentData.add(casperBotResponse); + } + given(redisService.getRecentData()) + .willReturn(recentData); + + //when + ResultActions perform = mockMvc.perform(get("/event/lottery/caspers") + .header("Authorization", accessToken) + .contentType(MediaType.APPLICATION_JSON)); + + //then + perform.andExpect(status().isOk()) + .andExpect(jsonPath("$.length()").value(100)) + .andDo(print()); + + } + String getToken(String phoneNumber) throws Exception { String requestBody = String.format(""" { From 8f7ee37b1865fff6d72a8c09d0c77e123de0c39f Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 16:12:38 +0900 Subject: [PATCH 281/289] =?UTF-8?q?chore:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventController/LotteryEventController.java | 8 -------- 1 file changed, 8 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 d2e6b4e5..8223063a 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 @@ -69,12 +69,4 @@ public ResponseEntity> getCasperBots() { return ResponseEntity.status(HttpStatus.OK) .body(redisService.getRecentData()); } - - // 캐스퍼 봇 조회 API - @GetMapping("/{casperId}") - public ResponseEntity getCasperBot(@PathVariable String casperId) { - return ResponseEntity - .status(HttpStatus.OK) - .body(lotteryEventService.getCasperBot(Long.parseLong(casperId))); - } } From 1ec3fef7dd491fdb24fc07d8aebe38ca73b894c2 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 16:13:52 +0900 Subject: [PATCH 282/289] =?UTF-8?q?chore:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/JGS/CasperEvent/global/entity/BaseUser.java | 2 +- .../eventController/LotteryEventControllerTest.java | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java b/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java index 96c31e65..038655cb 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java +++ b/Server/src/main/java/JGS/CasperEvent/global/entity/BaseUser.java @@ -10,7 +10,7 @@ @Getter @Entity -@EqualsAndHashCode +@EqualsAndHashCode(callSuper = false) @Inheritance(strategy = InheritanceType.JOINED) public class BaseUser extends BaseEntity { @Id diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java index 16149697..4cf07d8e 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java @@ -25,19 +25,12 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; -import javax.crypto.BadPaddingException; -import javax.crypto.IllegalBlockSizeException; -import javax.crypto.NoSuchPaddingException; -import java.lang.runtime.ObjectMethods; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; From 8116c4e4362954ee8fee908d8cbb3e93587c442c Mon Sep 17 00:00:00 2001 From: nnijgnus <76596376+k000927@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:24:00 +0900 Subject: [PATCH 283/289] =?UTF-8?q?fix:=20=EC=B6=94=EC=B2=9C=EC=9D=B8=20?= =?UTF-8?q?=EC=95=84=EC=9D=B4=EB=94=94=20=ED=99=95=EC=9D=B8=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/service/eventService/LotteryEventService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9aa2af6f..dfa9bb17 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 @@ -86,7 +86,7 @@ public LotteryParticipants registerUserIfNeed(BaseUser user, CasperBotRequestDto lotteryParticipantsRepository.save(participant); } - if (!casperBotRequestDto.getReferralId().isEmpty()) { + if (casperBotRequestDto.getReferralId() != null) { String referralId = AESUtils.decrypt(casperBotRequestDto.getReferralId(), secretKey); Optional referralParticipant = lotteryParticipantsRepository.findByBaseUser( From c3c94055e5a8c97b9f8bdfb8d16e3638e3ca7b9b Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 17:53:20 +0900 Subject: [PATCH 284/289] =?UTF-8?q?feat:=20=EA=B0=80=EC=A4=91=EC=B9=98=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=20=EB=9E=9C=EB=8D=A4=20=EC=95=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=EC=A6=98=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 6297f402..686ecc55 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -331,12 +331,32 @@ public ResponseDto pickLotteryEventWinners() { int winnerCount = lotteryEvent.getWinnerCount(); - Pageable pageable = PageRequest.of(0, winnerCount); + List lotteryParticipants = lotteryParticipantsRepository.findAll(); + Set lotteryEventWinners = new HashSet<>(); + + int totalWeight; + Random random = new Random(); + while (lotteryEventWinners.size() < winnerCount) { + totalWeight = 0; + for (LotteryParticipants lotteryParticipant : lotteryParticipants) { + totalWeight += lotteryParticipant.getAppliedCount(); + } + + int randomValue = random.nextInt(totalWeight) + 1; + + int cumulativeSum = 0; + for (LotteryParticipants lotteryParticipant : lotteryParticipants) { + cumulativeSum += lotteryParticipant.getAppliedCount(); + if(randomValue <= cumulativeSum){ + lotteryEventWinners.add(lotteryParticipant); + lotteryParticipants.remove(lotteryParticipant); + break; + } + } + } - //todo 당첨자 추첨 알고리즘 변경해야함 - Page lotteryWinners = lotteryParticipantsRepository.findAll(pageable); - for (LotteryParticipants lotteryWinner : lotteryWinners) { - lotteryWinnerRepository.save(new LotteryWinners(lotteryWinner)); + for (LotteryParticipants lotteryEventWinner : lotteryEventWinners) { + lotteryWinnerRepository.save(new LotteryWinners(lotteryEventWinner)); } return new ResponseDto("추첨이 완료되었습니다."); From da949c39550385447f7cda60d99318f877cdf696 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 17:53:45 +0900 Subject: [PATCH 285/289] =?UTF-8?q?feat:=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=9A=A9=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EC=82=AD=EC=A0=9C=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/service/adminService/AdminService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 686ecc55..47800f8f 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -362,6 +362,11 @@ public ResponseDto pickLotteryEventWinners() { return new ResponseDto("추첨이 완료되었습니다."); } + public ResponseDto deleteLotteryEventWinners(){ + lotteryWinnerRepository.deleteAll(); + return new ResponseDto("당첨자 명단을 삭제했습니다."); + } + public LotteryEventWinnerListResponseDto getLotteryEventWinners(int size, int page, String phoneNumber) { Pageable pageable = PageRequest.of(page, size); if (lotteryWinnerRepository.count() == 0) throw new CustomException(CustomErrorCode.LOTTERY_EVENT_NOT_DRAWN); From 6dbf7693b1b5752b6148cfbf626c765a3af58cd4 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Fri, 16 Aug 2024 17:53:49 +0900 Subject: [PATCH 286/289] =?UTF-8?q?feat:=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=9A=A9=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EC=82=AD=EC=A0=9C=20api=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/adminController/AdminController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index 8f8479a0..8a09bc77 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -183,12 +183,21 @@ public ResponseEntity pickLotteryEventWinners() { .body(adminService.pickLotteryEventWinners()); } + // 추첨 이벤트 당첨자 삭제 + @DeleteMapping("/event/lottery/winner") + public ResponseEntity deleteLotteryEventWinners(){ + return ResponseEntity + .status(HttpStatus.OK) + .body(adminService.deleteLotteryEventWinners()); + } + // 추첨 이벤트 당첨자 조회 @GetMapping("/event/lottery/winner") public ResponseEntity getWinners( @RequestParam(name = "size", required = false, defaultValue = "10") int size, @RequestParam(name = "page", required = false, defaultValue = "0") int page, @RequestParam(name = "number", required = false, defaultValue = "") String phoneNumber) { + return ResponseEntity .status(HttpStatus.OK) .body(adminService.getLotteryEventWinners(size, page, phoneNumber)); From ca6a97305764c8d959d674bcc125ab5dd8ff3be5 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Fri, 16 Aug 2024 18:18:22 +0900 Subject: [PATCH 287/289] =?UTF-8?q?fix:=20RushEventControllerTest=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B0=94=EB=80=90=20DTO=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/eventController/RushEventControllerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventControllerTest.java index 1ae656c3..cc2ab2ff 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/RushEventControllerTest.java @@ -114,7 +114,7 @@ void setUp() throws Exception { rushEventRateResponseDto, 1, 1000, - 315 + true ); given(rushEventService.getRushEventResult(any())).willReturn(rushEventResultResponseDto); @@ -248,7 +248,7 @@ public void getRushEventResultTest() throws Exception { .andExpect(jsonPath("$.rightOption").value(1000)) .andExpect(jsonPath("$.rank").value(1)) .andExpect(jsonPath("$.totalParticipants").value(1000)) - .andExpect(jsonPath("$.winnerCount").value(315)) + .andExpect(jsonPath("$.winner").value(true)) .andDo(print()); } From 0e67b6df8716e5e2991dc520496e6eecfd0176af Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Fri, 16 Aug 2024 18:19:12 +0900 Subject: [PATCH 288/289] =?UTF-8?q?feat:=20RushEventService=20=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=A4=91=EB=B3=B5=EC=9C=BC=EB=A1=9C=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=EC=B2=98=EB=A6=AC=ED=95=98=EB=8A=94=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/eventService/RushEventService.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java index 5b7b7197..aba48962 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/RushEventService.java @@ -35,12 +35,7 @@ public class RushEventService { @Transactional public RushEventListResponseDto getAllRushEvents() { // 오늘의 선착순 이벤트 꺼내오기 - RushEventResponseDto todayEvent = rushEventRedisTemplate.opsForValue().get("todayEvent"); - - // 오늘의 선착순 이벤트가 redis에 등록되지 않은 경우 - if (todayEvent == null) { - throw new CustomException("오늘의 선착순 이벤트가 redis에 등록되지 않았습니다.", CustomErrorCode.TODAY_RUSH_EVENT_NOT_FOUND); - } + RushEventResponseDto todayEvent = getTodayRushEvent(); // DB에서 모든 RushEvent 가져오기 List rushEventList = rushEventRepository.findAll(); @@ -161,7 +156,7 @@ public RushEventResponseDto getTodayRushEvent(LocalDate today) { } if (rushEventList.size() > 1) { - throw new CustomException("선착순 이벤트가 존재하지않습니다.", CustomErrorCode.MULTIPLE_RUSH_EVENTS_FOUND); + throw new CustomException("선착순 이벤트가 2개 이상 존재합니다.", CustomErrorCode.MULTIPLE_RUSH_EVENTS_FOUND); } return RushEventResponseDto.of(rushEventList.get(0)); @@ -237,16 +232,11 @@ public void setTodayEventToRedis() { rushEventRedisTemplate.opsForValue().set("todayEvent", RushEventResponseDto.of(rushEvents.get(2))); } - // 오늘의 이벤트 옵션 정보를 반환 public MainRushEventOptionsResponseDto getTodayRushEventOptions() { RushEventResponseDto todayEvent = getTodayRushEvent(); Set options = todayEvent.options(); - if (options.size() != 2) { - throw new CustomException("해당 이벤트의 선택지가 2개가 아닙니다.", CustomErrorCode.INVALID_RUSH_EVENT_OPTIONS_COUNT); - } - RushEventOptionResponseDto leftOption = options.stream() .filter(option -> option.position() == Position.LEFT) .findFirst() From 204ee41115489be68f065db1d39e232bf4eba076 Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Fri, 16 Aug 2024 18:19:35 +0900 Subject: [PATCH 289/289] =?UTF-8?q?feat:=20RushEventService=20=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=EC=96=B4=20=EB=AA=A8=EB=93=A0=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventService/RushEventServiceTest.java | 546 +++++++++++++++++- 1 file changed, 543 insertions(+), 3 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/eventService/RushEventServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/eventService/RushEventServiceTest.java index 0c481816..2b60c572 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/eventService/RushEventServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/eventService/RushEventServiceTest.java @@ -1,44 +1,584 @@ package JGS.CasperEvent.domain.event.service.eventService; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.*; +import JGS.CasperEvent.domain.event.entity.event.RushEvent; +import JGS.CasperEvent.domain.event.entity.event.RushOption; +import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; +import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.RushOptionRepository; +import JGS.CasperEvent.domain.event.repository.participantsRepository.RushParticipantsRepository; +import JGS.CasperEvent.global.entity.BaseUser; +import JGS.CasperEvent.global.enums.CustomErrorCode; +import JGS.CasperEvent.global.enums.Position; +import JGS.CasperEvent.global.error.exception.CustomException; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; -@SpringBootTest +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import static org.mockito.BDDMockito.*; +import static org.junit.jupiter.api.Assertions.*; + + +@ExtendWith(MockitoExtension.class) class RushEventServiceTest { + @Mock + private RushEventRepository rushEventRepository; + @Mock + private RushParticipantsRepository rushParticipantsRepository; + @Mock + private RedisTemplate rushEventRedisTemplate; + @Mock + private RushOptionRepository rushOptionRepository; + + @Mock + private ValueOperations valueOperations; + + @InjectMocks + RushEventService rushEventService; + @Test + @DisplayName("모든 RushEvent 조회") void getAllRushEvents() { + // given + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + new HashSet<>() + ); + + List rushEventList = List.of( + new RushEvent(), + new RushEvent() + ); + + List mainRushEventResponseDtoList = rushEventList.stream() + .map(MainRushEventResponseDto::of).toList(); + + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + given(valueOperations.get("todayEvent")).willReturn(todayEvent); + given(rushEventRepository.findAll()).willReturn(rushEventList); + + // when + RushEventListResponseDto allRushEvents = rushEventService.getAllRushEvents(); + + // then + assertNotNull(allRushEvents); + assertEquals(2, allRushEvents.getEvents().size()); + assertEquals(allRushEvents.getTodayEventId(), 1); } @Test + @DisplayName("해당 유저가 선착순 이벤트 응모했는지 여부 테스트") void isExists() { + // given + BaseUser user = new BaseUser(); + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + new HashSet<>() + ); + + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + given(rushEventRedisTemplate.opsForValue().get("todayEvent")).willReturn(todayEvent); + given(rushParticipantsRepository.existsByRushEvent_RushEventIdAndBaseUser_Id(1L, user.getId())).willReturn(true); + + // when + boolean exists = rushEventService.isExists(user.getId()); + + // then + assertTrue(exists); } @Test + @DisplayName("선착순 이벤트 응모 테스트") void apply() { + // given + BaseUser user = new BaseUser(); + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + new HashSet<>() + ); + + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + given(rushEventRedisTemplate.opsForValue().get("todayEvent")).willReturn(todayEvent); + given(rushParticipantsRepository.existsByRushEvent_RushEventIdAndBaseUser_Id(1L, user.getId())).willReturn(false); + RushEvent rushEvent = new RushEvent(); + given(rushEventRepository.findById(1L)).willReturn(Optional.of(rushEvent)); + + // when + rushEventService.apply(user, 1); + + // then + verify(rushParticipantsRepository).save(any(RushParticipants.class)); + } + + @Test + @DisplayName("선착순 이벤트 응모 테스트 (이미 응모한 유저인 경우)") + void apply2() { + // given + BaseUser user = new BaseUser(); + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + new HashSet<>() + ); + + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + given(rushEventRedisTemplate.opsForValue().get("todayEvent")).willReturn(todayEvent); + given(rushParticipantsRepository.existsByRushEvent_RushEventIdAndBaseUser_Id(1L, user.getId())).willReturn(true); + + // when & then + CustomException exception = assertThrows(CustomException.class, () -> + rushEventService.apply(user, 1) + ); + + assertEquals(CustomErrorCode.CONFLICT, exception.getErrorCode()); + assertEquals("이미 응모한 회원입니다.", exception.getMessage()); } + @Test + @DisplayName("선착순 이벤트 비율 조회 테스트") void getRushEventRate() { + // given + BaseUser user = new BaseUser(); + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + new HashSet<>() + ); + + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + given(rushEventRedisTemplate.opsForValue().get("todayEvent")).willReturn(todayEvent); + given(rushParticipantsRepository.getOptionIdByUserId(user.getId())).willReturn(Optional.of(1)); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 1)).willReturn(100L); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 2)).willReturn(200L); + + // when + RushEventRateResponseDto result = rushEventService.getRushEventRate(user); + + // then + assertNotNull(result); + assertEquals(1, result.optionId()); + assertEquals(100, result.leftOption()); + assertEquals(200, result.rightOption()); } @Test + @DisplayName("선착순 이벤트 결과 조회 테스트 (동점이 아니고 당첨인 경우)") void getRushEventResult() { + // given + BaseUser user = new BaseUser(); + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + new HashSet<>() + ); + + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + given(rushEventRedisTemplate.opsForValue().get("todayEvent")).willReturn(todayEvent); + given(rushParticipantsRepository.getOptionIdByUserId(user.getId())).willReturn(Optional.of(1)); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 1)).willReturn(700L); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 2)).willReturn(500L); + given(rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(1L, user.getId(), 1)).willReturn(300L); + + // when + RushEventResultResponseDto result = rushEventService.getRushEventResult(user); + + // then + assertNotNull(result); + assertEquals(700, result.getLeftOption()); + assertEquals(500, result.getRightOption()); + assertEquals(700, result.getTotalParticipants()); + assertEquals(300, result.getRank()); + assertTrue(result.isWinner()); + } + + @Test + @DisplayName("선착순 이벤트 결과 조회 테스트 (동점이 아니고 내가 선택한 옵션이 진 경우)") + void getRushEventResult2() { + // given + BaseUser user = new BaseUser(); + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + new HashSet<>() + ); + + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + given(rushEventRedisTemplate.opsForValue().get("todayEvent")).willReturn(todayEvent); + given(rushParticipantsRepository.getOptionIdByUserId(user.getId())).willReturn(Optional.of(2)); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 1)).willReturn(700L); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 2)).willReturn(500L); + given(rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(1L, user.getId(), 2)).willReturn(300L); + + // when + RushEventResultResponseDto result = rushEventService.getRushEventResult(user); + + // then + assertNotNull(result); + assertEquals(700, result.getLeftOption()); + assertEquals(500, result.getRightOption()); + assertEquals(500, result.getTotalParticipants()); + assertEquals(300, result.getRank()); + assertFalse(result.isWinner()); + } + + @Test + @DisplayName("선착순 이벤트 결과 조회 테스트 (동점이 아니고 내가 선택한 옵션이 이겼는데 등수에 미치지 못한 경우)") + void getRushEventResult3() { + // given + BaseUser user = new BaseUser(); + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + new HashSet<>() + ); + + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + given(rushEventRedisTemplate.opsForValue().get("todayEvent")).willReturn(todayEvent); + given(rushParticipantsRepository.getOptionIdByUserId(user.getId())).willReturn(Optional.of(1)); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 1)).willReturn(700L); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 2)).willReturn(500L); + given(rushParticipantsRepository.findUserRankByEventIdAndUserIdAndOptionId(1L, user.getId(), 1)).willReturn(400L); + + // when + RushEventResultResponseDto result = rushEventService.getRushEventResult(user); + + // then + assertNotNull(result); + assertEquals(700, result.getLeftOption()); + assertEquals(500, result.getRightOption()); + assertEquals(700, result.getTotalParticipants()); + assertEquals(400, result.getRank()); + assertFalse(result.isWinner()); + } + + @Test + @DisplayName("선착순 이벤트 결과 조회 테스트 (동점인데 당첨된 경우)") + void getRushEventResult4() { + // given + BaseUser user = new BaseUser(); + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + new HashSet<>() + ); + + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + given(rushEventRedisTemplate.opsForValue().get("todayEvent")).willReturn(todayEvent); + given(rushParticipantsRepository.getOptionIdByUserId(user.getId())).willReturn(Optional.of(1)); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 1)).willReturn(500L); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 2)).willReturn(500L); + given(rushParticipantsRepository.findUserRankByEventIdAndUserId(1L, user.getId())).willReturn(300L); + // when + RushEventResultResponseDto result = rushEventService.getRushEventResult(user); + + // then + assertNotNull(result); + assertEquals(500, result.getLeftOption()); + assertEquals(500, result.getRightOption()); + assertEquals(1000, result.getTotalParticipants()); + assertEquals(300, result.getRank()); + assertTrue(result.isWinner()); } @Test + @DisplayName("선착순 이벤트 결과 조회 테스트 (동점인데 등수에 미치지 못한 경우)") + void getRushEventResult5() { + // given + BaseUser user = new BaseUser(); + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + new HashSet<>() + ); + + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + given(rushEventRedisTemplate.opsForValue().get("todayEvent")).willReturn(todayEvent); + given(rushParticipantsRepository.getOptionIdByUserId(user.getId())).willReturn(Optional.of(1)); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 1)).willReturn(500L); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 2)).willReturn(500L); + given(rushParticipantsRepository.findUserRankByEventIdAndUserId(1L, user.getId())).willReturn(400L); + // when + RushEventResultResponseDto result = rushEventService.getRushEventResult(user); + + // then + assertNotNull(result); + assertEquals(500, result.getLeftOption()); + assertEquals(500, result.getRightOption()); + assertEquals(1000, result.getTotalParticipants()); + assertEquals(400, result.getRank()); + assertFalse(result.isWinner()); + } + + @Test + @DisplayName("오늘의 선착순 이벤트 DB에서 가져오기 테스트") void getTodayRushEvent() { + // given + LocalDate today = LocalDate.now(); + RushEvent rushEvent = new RushEvent(); + given(rushEventRepository.findByEventDate(today)).willReturn(List.of(rushEvent)); + + // when + RushEventResponseDto result = rushEventService.getTodayRushEvent(today); + + // then + assertNotNull(result); + assertEquals(rushEvent.getRushEventId(), result.rushEventId()); + } + + @Test + @DisplayName("오늘의 선착순 이벤트 DB에서 가져오기 테스트 (Redis에 선착순 이벤트가 없는 경우)") + void getTodayRushEvent2() { + // given + LocalDate today = LocalDate.now(); + given(rushEventRepository.findByEventDate(today)).willReturn(List.of()); + + // when & then + CustomException exception = assertThrows(CustomException.class, () -> + rushEventService.getTodayRushEvent(today) + ); + + assertEquals(CustomErrorCode.NO_RUSH_EVENT, exception.getErrorCode()); + assertEquals("선착순 이벤트가 존재하지않습니다.", exception.getMessage()); + } + + @Test + @DisplayName("오늘의 선착순 이벤트 DB에서 가져오기 테스트 (Redis에 선착순 이벤트가 2개 이상인 경우)") + void getTodayRushEvent3() { + // given + LocalDate today = LocalDate.now(); + RushEvent rushEvent1 = new RushEvent(); + RushEvent rushEvent2 = new RushEvent(); + given(rushEventRepository.findByEventDate(today)).willReturn(List.of( + rushEvent1, rushEvent2 + )); + + // when & then + CustomException exception = assertThrows(CustomException.class, () -> + rushEventService.getTodayRushEvent(today) + ); + + assertEquals(CustomErrorCode.MULTIPLE_RUSH_EVENTS_FOUND, exception.getErrorCode()); + assertEquals("선착순 이벤트가 2개 이상 존재합니다.", exception.getMessage()); } @Test void setTodayEventToRedis() { + // given + RushEvent rushEvent = new RushEvent(); + RushOption rushOption = new RushOption(); + given(rushEventRepository.save(any(RushEvent.class))).willReturn(rushEvent); + given(rushOptionRepository.save(any(RushOption.class))).willReturn(rushOption); + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + + // when + rushEventService.setTodayEventToRedis(); + + // then + verify(rushParticipantsRepository).deleteAllInBatch(); + verify(rushOptionRepository).deleteAllInBatch(); + verify(rushEventRepository).deleteAllInBatch(); + verify(rushEventRedisTemplate.opsForValue()).set(eq("todayEvent"), any(RushEventResponseDto.class)); } @Test void getTodayRushEventOptions() { + // given + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + Set.of( + new RushEventOptionResponseDto(1L, "leftMainText", "leftSubText", "resultMainText", "resultSubText", "leftImageUrl", Position.LEFT, LocalDateTime.now(), LocalDateTime.now()), + new RushEventOptionResponseDto(2L, "rightMainText", "rightSubText", "resultMainText", "resultSubText", "rightImageUrl", Position.RIGHT, LocalDateTime.now(), LocalDateTime.now()) + ) + ); + + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + given(rushEventRedisTemplate.opsForValue().get("todayEvent")).willReturn(todayEvent); + + // when + MainRushEventOptionsResponseDto result = rushEventService.getTodayRushEventOptions(); + + // then + assertNotNull(result); + assertEquals("leftMainText", result.leftOption().mainText()); + assertEquals("rightMainText", result.rightOption().mainText()); } @Test + @DisplayName("선택지 결과 조회 (옵션 개수가 2개인 경우)") void getRushEventOptionResult() { + // given + int optionId = 1; + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + Set.of( + new RushEventOptionResponseDto(1L, "leftMainText", "leftSubText", "resultMainText", "resultSubText", "leftImageUrl", Position.LEFT, LocalDateTime.now(), LocalDateTime.now()), + new RushEventOptionResponseDto(2L, "rightMainText", "rightSubText", "resultMainText", "resultSubText", "rightImageUrl", Position.RIGHT, LocalDateTime.now(), LocalDateTime.now()) + ) + ); + + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + given(rushEventRedisTemplate.opsForValue().get("todayEvent")).willReturn(todayEvent); + + // when + ResultRushEventOptionResponseDto result = rushEventService.getRushEventOptionResult(optionId); + + // then + assertNotNull(result); + assertEquals("leftMainText", result.mainText()); + } + + @Test + @DisplayName("선택지 결과 조회 (옵션 개수가 3개 이상인 경우)") + void getRushEventOptionResult2() { + // given + int optionId = 1; + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + Set.of( + new RushEventOptionResponseDto(1L, "leftMainText", "leftSubText", "resultMainText", "resultSubText", "leftImageUrl", Position.LEFT, LocalDateTime.now(), LocalDateTime.now()), + new RushEventOptionResponseDto(2L, "rightMainText", "rightSubText", "resultMainText", "resultSubText", "rightImageUrl", Position.RIGHT, LocalDateTime.now(), LocalDateTime.now()), + new RushEventOptionResponseDto(3L, "rightMainText", "rightSubText", "resultMainText", "resultSubText", "rightImageUrl", Position.RIGHT, LocalDateTime.now(), LocalDateTime.now()) + ) + ); + + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + given(rushEventRedisTemplate.opsForValue().get("todayEvent")).willReturn(todayEvent); + + // when & then + CustomException exception = assertThrows(CustomException.class, () -> + rushEventService.getRushEventOptionResult(optionId) + ); + + assertEquals(CustomErrorCode.INVALID_RUSH_EVENT_OPTIONS_COUNT, exception.getErrorCode()); + assertEquals("해당 이벤트의 선택지가 2개가 아닙니다.", exception.getMessage()); + } + + @Test + @DisplayName("선택지 결과 조회 (사용자가 선택한 선택지가 1 또는 2가 아닌 경우)") + void getRushEventOptionResult3() { + // given + int optionId = 3; + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + Set.of( + new RushEventOptionResponseDto(1L, "leftMainText", "leftSubText", "resultMainText", "resultSubText", "leftImageUrl", Position.LEFT, LocalDateTime.now(), LocalDateTime.now()), + new RushEventOptionResponseDto(2L, "rightMainText", "rightSubText", "resultMainText", "resultSubText", "rightImageUrl", Position.RIGHT, LocalDateTime.now(), LocalDateTime.now()) + ) + ); + + // when & then + CustomException exception = assertThrows(CustomException.class, () -> + rushEventService.getRushEventOptionResult(optionId) + ); + + assertEquals(CustomErrorCode.INVALID_RUSH_EVENT_OPTION_ID, exception.getErrorCode()); + assertEquals("optionId는 1 또는 2여야 합니다.", exception.getMessage()); + } + + @Test + @DisplayName("선택지 결과 조회 (사용자가 선택한 옵션이 DB에 없는 경우)") + void getRushEventOptionResult4() { + // given + int optionId = 1; + RushEventResponseDto todayEvent = new RushEventResponseDto( + 1L, + LocalDateTime.now(), + LocalDateTime.now().plusDays(1), + 315, + "image-url", + "prize-description", + Set.of( + new RushEventOptionResponseDto(2L, "rightMainText", "rightSubText", "resultMainText", "resultSubText", "rightImageUrl", Position.RIGHT, LocalDateTime.now(), LocalDateTime.now()), + new RushEventOptionResponseDto(3L, "rightMainText", "rightSubText", "resultMainText", "resultSubText", "rightImageUrl", Position.RIGHT, LocalDateTime.now(), LocalDateTime.now()) + ) + ); + + given(rushEventRedisTemplate.opsForValue()).willReturn(valueOperations); + given(rushEventRedisTemplate.opsForValue().get("todayEvent")).willReturn(todayEvent); + + // when & then + CustomException exception = assertThrows(CustomException.class, () -> + rushEventService.getRushEventOptionResult(optionId) + ); + + assertEquals(CustomErrorCode.NO_RUSH_EVENT_OPTION, exception.getErrorCode()); + assertEquals("사용자가 선택한 선택지가 존재하지 않습니다.", exception.getMessage()); } -} \ No newline at end of file +}