From 8e63b541c78f08c6c2b910ad53527914c7dd7911 Mon Sep 17 00:00:00 2001 From: Jung Jongmin Date: Thu, 19 Aug 2021 10:10:38 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Feat:=20special=20=EC=B9=B4=EB=93=9C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alacard/controller/AlaCardController.java | 8 +++++ .../alacard/repository/AlaCardRepository.java | 3 ++ .../member/service/MemberCardService.java | 2 ++ .../member/service/MemberCardServiceImpl.java | 34 +++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/src/main/java/com/meme/ala/domain/alacard/controller/AlaCardController.java b/src/main/java/com/meme/ala/domain/alacard/controller/AlaCardController.java index dca90f6..f39620e 100644 --- a/src/main/java/com/meme/ala/domain/alacard/controller/AlaCardController.java +++ b/src/main/java/com/meme/ala/domain/alacard/controller/AlaCardController.java @@ -113,4 +113,12 @@ public ResponseEntity patchAlaCardSetting(@CurrentUser Member membe return ResponseEntity.status(HttpStatus.NO_CONTENT) .body(ResponseDto.of(HttpStatus.NO_CONTENT, ResponseMessage.SUCCESS)); } + + @GetMapping("/specialCard") + public ResponseEntity assignSpecialCard(@RequestParam String nickname, @RequestParam int size) { + Member member = memberService.findByNickname(nickname); + memberCardService.assignSpecialCard(member, size); + return ResponseEntity.status(HttpStatus.NO_CONTENT) + .body(ResponseDto.of(HttpStatus.NO_CONTENT, ResponseMessage.SUCCESS)); + } } \ No newline at end of file diff --git a/src/main/java/com/meme/ala/domain/alacard/repository/AlaCardRepository.java b/src/main/java/com/meme/ala/domain/alacard/repository/AlaCardRepository.java index edfb3bb..6158c9f 100644 --- a/src/main/java/com/meme/ala/domain/alacard/repository/AlaCardRepository.java +++ b/src/main/java/com/meme/ala/domain/alacard/repository/AlaCardRepository.java @@ -5,6 +5,9 @@ import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface AlaCardRepository extends MongoRepository { + List findAllBySpecial(Boolean special); } diff --git a/src/main/java/com/meme/ala/domain/member/service/MemberCardService.java b/src/main/java/com/meme/ala/domain/member/service/MemberCardService.java index b32a5cd..ccaa32f 100644 --- a/src/main/java/com/meme/ala/domain/member/service/MemberCardService.java +++ b/src/main/java/com/meme/ala/domain/member/service/MemberCardService.java @@ -19,4 +19,6 @@ public interface MemberCardService { List getWordList(String cookieId); void saveSetting(Member member, AlaCardSettingDto alaCardSettingDto); + + void assignSpecialCard(Member member, int num); } \ No newline at end of file diff --git a/src/main/java/com/meme/ala/domain/member/service/MemberCardServiceImpl.java b/src/main/java/com/meme/ala/domain/member/service/MemberCardServiceImpl.java index 3138e6f..5ebbf40 100644 --- a/src/main/java/com/meme/ala/domain/member/service/MemberCardServiceImpl.java +++ b/src/main/java/com/meme/ala/domain/member/service/MemberCardServiceImpl.java @@ -131,4 +131,38 @@ public void saveSetting(Member member, AlaCardSettingDto alaCardSettingDto) { } memberRepository.save(member); } + + @Override + @Transactional + public void assignSpecialCard(Member member, int num) { + List memberAlaCardList = getAlaCardListFromMember(member); + List alaCardList = alaCardRepository.findAllBySpecial(true); + int assignSize = Math.min(num, alaCardList.size()); + + List alaCardSettingList = alaCardService.getBackgrounds().stream() + .map(background -> AlaCardSetting.builder() + .background(background) + .isOpen(true) + .build()) + .collect(Collectors.toList()); + + Collections.shuffle(alaCardList); + Collections.shuffle(alaCardSettingList); + + List selectedAlaCardList = + alaCardList.stream() + .filter(alaCard -> !alaCard.getSpecial()) + .filter(alaCard -> !memberAlaCardList.contains(alaCard)) + .limit(assignSize) + .collect(Collectors.toList()); + + for (int i = 0; i < assignSize; i++) { + member.getAlaCardSettingPairList() + .add(AlaCardSettingPair.builder() + .alaCard(selectedAlaCardList.get(i)) + .alaCardSetting(alaCardSettingList.get(i % alaCardSettingList.size())) + .build()); + } + memberRepository.save(member); + } } From 59dade183f70da17aea7ebc10ad1f44c620aa159 Mon Sep 17 00:00:00 2001 From: Jung Jongmin Date: Thu, 19 Aug 2021 10:47:34 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Fix:=20sepcial=20=ED=95=84=ED=84=B0=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meme/ala/domain/member/service/MemberCardServiceImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/meme/ala/domain/member/service/MemberCardServiceImpl.java b/src/main/java/com/meme/ala/domain/member/service/MemberCardServiceImpl.java index 5ebbf40..33f725d 100644 --- a/src/main/java/com/meme/ala/domain/member/service/MemberCardServiceImpl.java +++ b/src/main/java/com/meme/ala/domain/member/service/MemberCardServiceImpl.java @@ -151,7 +151,6 @@ public void assignSpecialCard(Member member, int num) { List selectedAlaCardList = alaCardList.stream() - .filter(alaCard -> !alaCard.getSpecial()) .filter(alaCard -> !memberAlaCardList.contains(alaCard)) .limit(assignSize) .collect(Collectors.toList()); From e2d01c863cd8d6ea3e333c2d05b37e5af8447863 Mon Sep 17 00:00:00 2001 From: Jung Jongmin Date: Thu, 19 Aug 2021 11:30:13 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Feat:=20assign=20Card=20=EB=A1=9C=EC=A7=81?= =?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 --- .../aggregation/service/AggregationService.java | 11 ++++++----- .../aggregation/service/AggregationServiceImpl.java | 8 +++++--- .../ala/domain/event/component/EventHandler.java | 1 - .../member/service/MemberCardServiceImpl.java | 13 +++++++++++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/meme/ala/domain/aggregation/service/AggregationService.java b/src/main/java/com/meme/ala/domain/aggregation/service/AggregationService.java index 0235515..0d501f0 100644 --- a/src/main/java/com/meme/ala/domain/aggregation/service/AggregationService.java +++ b/src/main/java/com/meme/ala/domain/aggregation/service/AggregationService.java @@ -1,19 +1,20 @@ package com.meme.ala.domain.aggregation.service; import com.meme.ala.domain.aggregation.model.entity.Aggregation; +import com.meme.ala.domain.member.model.entity.AlaCardSettingPair; import com.meme.ala.domain.member.model.entity.Member; import java.io.UnsupportedEncodingException; import java.util.List; public interface AggregationService { - public Aggregation findByMember(Member member); + Aggregation findByMember(Member member); - public void initAggregation(Member member); + void initAggregation(Member member, List alaCardSettingPairList); - public void save(Aggregation aggregation); + void save(Aggregation aggregation); - public void submitWordList(Member member, Aggregation aggregation, List wordIdList) throws UnsupportedEncodingException; + void submitWordList(Member member, Aggregation aggregation, List wordIdList) throws UnsupportedEncodingException; - public Integer getUserCount(); + Integer getUserCount(); } \ No newline at end of file diff --git a/src/main/java/com/meme/ala/domain/aggregation/service/AggregationServiceImpl.java b/src/main/java/com/meme/ala/domain/aggregation/service/AggregationServiceImpl.java index 92c20da..333e6ef 100644 --- a/src/main/java/com/meme/ala/domain/aggregation/service/AggregationServiceImpl.java +++ b/src/main/java/com/meme/ala/domain/aggregation/service/AggregationServiceImpl.java @@ -35,13 +35,15 @@ public Aggregation findByMember(Member member) { @Override @Transactional - public void initAggregation(Member member) { - List wordCountList = member.getAlaCardSettingPairList().stream() + public void initAggregation(Member member, List alaCardSettingPairList) { + Aggregation aggregation = aggregationRepository.findByMemberId(member.getId()) + .orElse(Aggregation.builder().memberId(member.getId()).wordCountList(new ArrayList<>()).build()); + List wordCountList = alaCardSettingPairList.stream() .map(this::toNestedWordCountList) .flatMap(Collection::stream) .flatMap(Collection::stream) .collect(Collectors.toList()); - Aggregation aggregation = Aggregation.builder().memberId(member.getId()).wordCountList(wordCountList).build(); + aggregation.getWordCountList().addAll(wordCountList); aggregationRepository.save(aggregation); } diff --git a/src/main/java/com/meme/ala/domain/event/component/EventHandler.java b/src/main/java/com/meme/ala/domain/event/component/EventHandler.java index 738a1fc..986e018 100644 --- a/src/main/java/com/meme/ala/domain/event/component/EventHandler.java +++ b/src/main/java/com/meme/ala/domain/event/component/EventHandler.java @@ -35,7 +35,6 @@ public void initMember(InitEvent event) { Member member = memberRepository.findByEmail(event.getEmail()) .orElseThrow(() -> new EntityNotFoundException(ErrorCode.ENTITY_NOT_FOUND)); memberCardService.assignCard(member, defaultCardNum); - aggregationService.initAggregation(member); friendInfoService.initFriendInfo(member); } diff --git a/src/main/java/com/meme/ala/domain/member/service/MemberCardServiceImpl.java b/src/main/java/com/meme/ala/domain/member/service/MemberCardServiceImpl.java index 33f725d..2d86325 100644 --- a/src/main/java/com/meme/ala/domain/member/service/MemberCardServiceImpl.java +++ b/src/main/java/com/meme/ala/domain/member/service/MemberCardServiceImpl.java @@ -2,6 +2,7 @@ import com.meme.ala.core.error.ErrorCode; import com.meme.ala.core.error.exception.EntityNotFoundException; +import com.meme.ala.domain.aggregation.service.AggregationService; import com.meme.ala.domain.alacard.model.dto.response.AlaCardSettingDto; import com.meme.ala.domain.alacard.model.dto.response.SelectionWordDto; import com.meme.ala.domain.alacard.model.entity.AlaCard; @@ -22,6 +23,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -38,12 +40,14 @@ public class MemberCardServiceImpl implements MemberCardService { private final TemporalWordListRepository temporalWordListRepository; private final MemberService memberService; private final AlaCardService alaCardService; + private final AggregationService aggregationService; @Override @Transactional public void assignCard(Member member, int num) { List memberAlaCardList = getAlaCardListFromMember(member); List alaCardList = getAlaCardList(); + List newAlaCardList = new ArrayList<>(); List alaCardSettingList = alaCardService.getBackgrounds().stream() .map(background -> AlaCardSetting.builder() @@ -63,13 +67,15 @@ public void assignCard(Member member, int num) { .collect(Collectors.toList()); for (int i = 0; i < num; i++) { - member.getAlaCardSettingPairList() + newAlaCardList .add(AlaCardSettingPair.builder() .alaCard(selectedAlaCardList.get(i)) .alaCardSetting(alaCardSettingList.get(i % alaCardSettingList.size())) .build()); } + member.getAlaCardSettingPairList().addAll(newAlaCardList); memberRepository.save(member); + aggregationService.initAggregation(member, newAlaCardList); } @Cacheable @@ -137,6 +143,7 @@ public void saveSetting(Member member, AlaCardSettingDto alaCardSettingDto) { public void assignSpecialCard(Member member, int num) { List memberAlaCardList = getAlaCardListFromMember(member); List alaCardList = alaCardRepository.findAllBySpecial(true); + List newAlaCardList = new ArrayList<>(); int assignSize = Math.min(num, alaCardList.size()); List alaCardSettingList = alaCardService.getBackgrounds().stream() @@ -156,12 +163,14 @@ public void assignSpecialCard(Member member, int num) { .collect(Collectors.toList()); for (int i = 0; i < assignSize; i++) { - member.getAlaCardSettingPairList() + newAlaCardList .add(AlaCardSettingPair.builder() .alaCard(selectedAlaCardList.get(i)) .alaCardSetting(alaCardSettingList.get(i % alaCardSettingList.size())) .build()); } + member.getAlaCardSettingPairList().addAll(newAlaCardList); memberRepository.save(member); + aggregationService.initAggregation(member, newAlaCardList); } } From 2ecd5b90b882119dbb3626282a86094af4daa204 Mon Sep 17 00:00:00 2001 From: Jung Jongmin Date: Thu, 19 Aug 2021 17:05:38 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Fix:=20AggregationService=20=EB=AA=A8?= =?UTF-8?q?=ED=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ala/domain/member/service/MemberCardServiceTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/java/com/meme/ala/domain/member/service/MemberCardServiceTest.java b/src/test/java/com/meme/ala/domain/member/service/MemberCardServiceTest.java index 6643fc7..31a042c 100644 --- a/src/test/java/com/meme/ala/domain/member/service/MemberCardServiceTest.java +++ b/src/test/java/com/meme/ala/domain/member/service/MemberCardServiceTest.java @@ -1,6 +1,7 @@ package com.meme.ala.domain.member.service; import com.meme.ala.common.EntityFactory; +import com.meme.ala.domain.aggregation.service.AggregationService; import com.meme.ala.domain.alacard.model.entity.AlaCard; import com.meme.ala.domain.alacard.repository.AlaCardRepository; import com.meme.ala.domain.alacard.service.AlaCardService; @@ -21,6 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; @SpringBootTest @@ -34,6 +36,8 @@ public class MemberCardServiceTest { private MemberCardService memberCardService; @MockBean private AlaCardService alaCardService; + @MockBean + private AggregationService aggregationService; @Value("${member.alacardnum}") private int defaultCardNum; @@ -49,6 +53,7 @@ public class MemberCardServiceTest { when(memberRepository.existsMemberByMemberSettingNickname(any(String.class))).thenReturn(false); when(alaCardRepository.findAll()).thenReturn(alaCardList); when(alaCardService.getBackgrounds()).thenReturn(Arrays.asList(EntityFactory.testAlaCardSetting().getBackground())); + doNothing().when(aggregationService).initAggregation(any(Member.class),any(List.class)); Member testMember = Member.builder().build();