From 9224f519c6eccc3a7f6b884a264a1e3a65d4c8bb Mon Sep 17 00:00:00 2001 From: wjddn2165 Date: Thu, 15 Aug 2024 22:43:00 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=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 2/5] =?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 3/5] =?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 4/5] =?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 5/5] =?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) { +}