Skip to content

Commit

Permalink
[TDC-45] 리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
yerimkoko committed Jan 29, 2024
1 parent ca34eff commit a212dfd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Long> 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<Long> stickerList) {
StickerAction stickerAction = stickerActionRepository.getReactionByStickerGroupAndTargetIdAndAccountId(stickerGroup, request.getTargetId(), request.getAccountId());

if (request.getStickerIds().isEmpty()) {
Expand All @@ -62,9 +52,8 @@ public void upsertSticker(AddReactionRequest request, StickerGroup stickerGroup)
@Transactional(readOnly = true)
public List<TargetStickerReactionResponse> getStickerReactionResponse(StickerGroup stickerGroup,
String accountId,
Set<String> targetIds) {

List<Sticker> stickers = stickerRepository.getStickerByStickerGroup(stickerGroup);
Set<String> targetIds,
List<Sticker> stickers) {

Map<StickerActionCountKey, Long> stickerCountKeyLongMap = getStickerCountKey(stickerGroup, targetIds, stickers);

Expand Down Expand Up @@ -107,9 +96,6 @@ private Map<String, StickerAction> getTargetIdActedByMe(Set<String> targetIds,
List<StickerAction> stickerActions = stickerActionRepository.getStickerActionByMe(accountId, targetIds, stickerGroup);
return stickerActions.stream()
.collect(Collectors.toMap(StickerAction::getTargetId, stickerAction -> stickerAction));

}



}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,16 +18,20 @@ public class StickerFacadeService {

private final StickerService stickerService;


public void upsertSticker(AddReactionRequest request, @NotNull StickerGroup stickerGroup) {
stickerActionService.upsertSticker(request, stickerGroup);
Set<Long> stickerIds = stickerService.getStickerListByStickerIdAndGroup(request.getStickerIds(), stickerGroup);
stickerActionService.upsertSticker(request, stickerGroup, stickerIds);
}

public List<StickerInfoResponse> getStickerList(@NotNull StickerGroup stickerGroup) {
return stickerService.getStickerList(stickerGroup);
}

public List<TargetStickerReactionResponse> getTargetStickerReactionResponse(@NotNull StickerGroup stickerGroup, String accountId, Set<String> targetIds) {
return stickerActionService.getStickerReactionResponse(stickerGroup, accountId, targetIds);
List<Sticker> stickers = stickerService.getStickersByStickerGroup(stickerGroup);
return stickerActionService.getStickerReactionResponse(stickerGroup, accountId, targetIds, stickers);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
Expand All @@ -25,4 +26,18 @@ public List<StickerInfoResponse> getStickerList(StickerGroup group) {
.collect(Collectors.toList());
}

@Transactional(readOnly = true)
public List<Sticker> getStickersByStickerGroup(StickerGroup stickerGroup) {
return stickerRepository.getStickerByStickerGroup(stickerGroup);
}

@Transactional(readOnly = true)
public Set<Long> getStickerListByStickerIdAndGroup(Set<Long> stickerIds, StickerGroup stickerGroup) {

Set<Long> stickerList = stickerRepository.getStickerByIdsAndStickerGroup(stickerIds, stickerGroup);
if (stickerList.isEmpty()) {
throw new IllegalArgumentException(String.format("요청하신 스티커(%s)를 사용할 수 없습니다.", stickerIds));
}
return stickerList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit a212dfd

Please sign in to comment.