From a212dfd2e96b1286a11d4a997d0c1a27bb7c5623 Mon Sep 17 00:00:00 2001 From: yerimkoko Date: Mon, 29 Jan 2024 20:38:09 +0900 Subject: [PATCH] =?UTF-8?q?[TDC-45]=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/sticker/StickerActionService.java | 20 +++---------------- .../service/sticker/StickerFacadeService.java | 9 +++++++-- .../service/sticker/StickerService.java | 15 ++++++++++++++ .../sticker/StickerActionServiceTest.java | 2 +- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/threedollar-application/src/main/java/com/threedollar/service/sticker/StickerActionService.java b/threedollar-application/src/main/java/com/threedollar/service/sticker/StickerActionService.java index 8bf1c42..7a2ef51 100644 --- a/threedollar-application/src/main/java/com/threedollar/service/sticker/StickerActionService.java +++ b/threedollar-application/src/main/java/com/threedollar/service/sticker/StickerActionService.java @@ -3,7 +3,6 @@ import com.threedollar.domain.sticker.Sticker; import com.threedollar.domain.sticker.StickerGroup; -import com.threedollar.domain.sticker.repository.StickerRepository; import com.threedollar.domain.stickeraction.StickerAction; import com.threedollar.domain.stickeraction.StickerActionCountKey; import com.threedollar.domain.stickeraction.repository.StickerActionCountRepository; @@ -27,19 +26,10 @@ public class StickerActionService { private final StickerActionRepository stickerActionRepository; - private final StickerRepository stickerRepository; - private final StickerActionCountRepository stickerCountRepository; - @Transactional - public void upsertSticker(AddReactionRequest request, StickerGroup stickerGroup) { - - Set stickerList = stickerRepository.getStickerByIdsAndStickerGroup(request.getStickerIds(), stickerGroup); - if (stickerList.isEmpty()) { - throw new IllegalArgumentException(String.format("요청하신 스티커(%s)를 사용할 수 없습니다.", request.getStickerIds())); - } - + public void upsertSticker(AddReactionRequest request, StickerGroup stickerGroup, Set stickerList) { StickerAction stickerAction = stickerActionRepository.getReactionByStickerGroupAndTargetIdAndAccountId(stickerGroup, request.getTargetId(), request.getAccountId()); if (request.getStickerIds().isEmpty()) { @@ -62,9 +52,8 @@ public void upsertSticker(AddReactionRequest request, StickerGroup stickerGroup) @Transactional(readOnly = true) public List getStickerReactionResponse(StickerGroup stickerGroup, String accountId, - Set targetIds) { - - List stickers = stickerRepository.getStickerByStickerGroup(stickerGroup); + Set targetIds, + List stickers) { Map stickerCountKeyLongMap = getStickerCountKey(stickerGroup, targetIds, stickers); @@ -107,9 +96,6 @@ private Map getTargetIdActedByMe(Set targetIds, List stickerActions = stickerActionRepository.getStickerActionByMe(accountId, targetIds, stickerGroup); return stickerActions.stream() .collect(Collectors.toMap(StickerAction::getTargetId, stickerAction -> stickerAction)); - } - - } diff --git a/threedollar-application/src/main/java/com/threedollar/service/sticker/StickerFacadeService.java b/threedollar-application/src/main/java/com/threedollar/service/sticker/StickerFacadeService.java index 8a49dbc..2d69ee3 100644 --- a/threedollar-application/src/main/java/com/threedollar/service/sticker/StickerFacadeService.java +++ b/threedollar-application/src/main/java/com/threedollar/service/sticker/StickerFacadeService.java @@ -1,5 +1,6 @@ package com.threedollar.service.sticker; +import com.threedollar.domain.sticker.Sticker; import com.threedollar.domain.sticker.StickerGroup; import com.threedollar.service.sticker.dto.response.StickerInfoResponse; import com.threedollar.service.sticker.dto.response.TargetStickerReactionResponse; @@ -17,8 +18,10 @@ public class StickerFacadeService { private final StickerService stickerService; + public void upsertSticker(AddReactionRequest request, @NotNull StickerGroup stickerGroup) { - stickerActionService.upsertSticker(request, stickerGroup); + Set stickerIds = stickerService.getStickerListByStickerIdAndGroup(request.getStickerIds(), stickerGroup); + stickerActionService.upsertSticker(request, stickerGroup, stickerIds); } public List getStickerList(@NotNull StickerGroup stickerGroup) { @@ -26,7 +29,9 @@ public List getStickerList(@NotNull StickerGroup stickerGro } public List getTargetStickerReactionResponse(@NotNull StickerGroup stickerGroup, String accountId, Set targetIds) { - return stickerActionService.getStickerReactionResponse(stickerGroup, accountId, targetIds); + List stickers = stickerService.getStickersByStickerGroup(stickerGroup); + return stickerActionService.getStickerReactionResponse(stickerGroup, accountId, targetIds, stickers); } + } diff --git a/threedollar-application/src/main/java/com/threedollar/service/sticker/StickerService.java b/threedollar-application/src/main/java/com/threedollar/service/sticker/StickerService.java index 154e488..5bb50a9 100644 --- a/threedollar-application/src/main/java/com/threedollar/service/sticker/StickerService.java +++ b/threedollar-application/src/main/java/com/threedollar/service/sticker/StickerService.java @@ -9,6 +9,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; @Service @@ -25,4 +26,18 @@ public List getStickerList(StickerGroup group) { .collect(Collectors.toList()); } + @Transactional(readOnly = true) + public List getStickersByStickerGroup(StickerGroup stickerGroup) { + return stickerRepository.getStickerByStickerGroup(stickerGroup); + } + + @Transactional(readOnly = true) + public Set getStickerListByStickerIdAndGroup(Set stickerIds, StickerGroup stickerGroup) { + + Set stickerList = stickerRepository.getStickerByIdsAndStickerGroup(stickerIds, stickerGroup); + if (stickerList.isEmpty()) { + throw new IllegalArgumentException(String.format("요청하신 스티커(%s)를 사용할 수 없습니다.", stickerIds)); + } + return stickerList; + } } diff --git a/threedollar-application/src/test/java/com/threedollar/service/sticker/StickerActionServiceTest.java b/threedollar-application/src/test/java/com/threedollar/service/sticker/StickerActionServiceTest.java index 9dbfbfa..b6e913e 100644 --- a/threedollar-application/src/test/java/com/threedollar/service/sticker/StickerActionServiceTest.java +++ b/threedollar-application/src/test/java/com/threedollar/service/sticker/StickerActionServiceTest.java @@ -39,7 +39,7 @@ void cleanUp() { AddReactionRequest request = getRequest(sticker); // when - stickerActionService.upsertSticker(request, sticker.getStickerGroup()); + stickerActionService.upsertSticker(request, sticker.getStickerGroup(), request.getStickerIds()); // then StickerAction stickerAction = getStickerAction(request, sticker.getStickerGroup());