From 809a89124300683a2d1064be37afede79b827a88 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Thu, 15 Aug 2024 02:31:47 +0900 Subject: [PATCH 1/7] =?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 2/7] =?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 3/7] =?UTF-8?q?feat:=20LotteryParticipants=EA=B0=80=20Base?= =?UTF-8?q?Entity=EB=A5=BC=20=EC=83=81=EC=86=8D=EB=B0=9B=EB=8F=84=EB=A1=9D?= =?UTF-8?q?=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 4/7] =?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 5/7] =?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 6/7] =?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 7/7] =?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;