From 5c8203172ea96218daf24fdacab18da02d8643a7 Mon Sep 17 00:00:00 2001 From: thguss Date: Sun, 19 May 2024 10:30:08 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[FIX]=20=EB=B0=B0=EC=A7=80=20=ED=9A=8D?= =?UTF-8?q?=EB=93=9D=EA=B9=8C=EC=A7=80=20=EB=82=A8=EC=9D=80=20=ED=9A=9F?= =?UTF-8?q?=EC=88=98=20=EB=B0=98=ED=99=98=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smeem/api/badge/service/BadgeService.java | 21 ++++++++++--------- .../memberbadge/MemberBadgeCounter.java | 5 ----- .../memberbadge/MemberBadgeFinder.java | 6 ++++++ .../repository/MemberBadgeRepository.java | 5 ++--- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java index 90dccc41..7b20d0bb 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java @@ -7,7 +7,7 @@ import com.smeem.domain.badge.adapter.BadgeFinder; import com.smeem.domain.badge.model.Badge; import com.smeem.domain.badge.model.BadgeType; -import com.smeem.domain.member.adapter.memberbadge.MemberBadgeCounter; +import com.smeem.domain.member.adapter.member.MemberFinder; import com.smeem.domain.member.adapter.memberbadge.MemberBadgeFinder; import com.smeem.domain.member.adapter.memberbadge.MemberBadgeSaver; import com.smeem.domain.member.model.Member; @@ -26,7 +26,7 @@ public class BadgeService { private final BadgeFinder badgeFinder; private final MemberBadgeSaver memberBadgeSaver; private final MemberBadgeFinder memberBadgeFinder; - private final MemberBadgeCounter memberBadgeCounter; + private final MemberFinder memberFinder; public BadgeListServiceResponseV3 getBadgesV3(BadgeListServiceRequestV3 request) { val response = badgeFinder.findAllOrderById() @@ -71,20 +71,21 @@ private void putBadgeMap(Map> badgeMap, Badge badge) { badgeMap.computeIfAbsent(badge.getType(), k -> new ArrayList<>()).add(badge); } - private Integer calculateRemainingNumber(Long badgeId, Long count) { + private Integer calculateRemainingNumber(Long badgeId, int count) { return switch (badgeId.intValue()) { - case 2 -> 1 - count.intValue() > 0 ? 1 - count.intValue() : null; - case 3 -> 10 - count.intValue() > 0 ? 10 - count.intValue() : null; - case 4 -> 30 - count.intValue() > 0 ? 30 - count.intValue() : null; - case 5 -> 50 - count.intValue() > 0 ? 50 - count.intValue() : null; + case 2 -> 1 - count; + case 3 -> 10 - count; + case 4 -> 30 - count; + case 5 -> 50 - count; default -> null; }; } private BadgeGetServiceResponseV3 convertToBadgeGetServiceResponseV3(Badge badge, final long memberId) { - val count = memberBadgeCounter.countByBadgeIdAndMemberId(badge.getId(), memberId); - val hasBadge = count > 0; - val remainingNumber = calculateRemainingNumber(badge.getId(), count); + val member = memberFinder.findById(memberId); + val hasBadge = memberBadgeFinder.isExist(member, badge); + val memberDiaryCount = member.getDiaries().size(); + val remainingNumber = calculateRemainingNumber(badge.getId(), memberDiaryCount); return BadgeGetServiceResponseV3.of(badge, hasBadge, remainingNumber); } } diff --git a/smeem-domain/src/main/java/com/smeem/domain/member/adapter/memberbadge/MemberBadgeCounter.java b/smeem-domain/src/main/java/com/smeem/domain/member/adapter/memberbadge/MemberBadgeCounter.java index a47e2090..124c7c8b 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/member/adapter/memberbadge/MemberBadgeCounter.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/adapter/memberbadge/MemberBadgeCounter.java @@ -1,6 +1,5 @@ package com.smeem.domain.member.adapter.memberbadge; - import com.smeem.domain.badge.model.Badge; import com.smeem.domain.member.repository.MemberBadgeRepository; import com.smeem.domain.support.RepositoryAdapter; @@ -15,8 +14,4 @@ public class MemberBadgeCounter { public long countByBadge(final Badge badge) { return memberBadgeRepository.countByBadge(badge); } - - public long countByBadgeIdAndMemberId(final long badgeId, final long memberId) { - return memberBadgeRepository.countByBadgeIdAndMemberId(badgeId, memberId); - } } diff --git a/smeem-domain/src/main/java/com/smeem/domain/member/adapter/memberbadge/MemberBadgeFinder.java b/smeem-domain/src/main/java/com/smeem/domain/member/adapter/memberbadge/MemberBadgeFinder.java index e6ffc7ec..791d88c8 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/member/adapter/memberbadge/MemberBadgeFinder.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/adapter/memberbadge/MemberBadgeFinder.java @@ -1,7 +1,9 @@ package com.smeem.domain.member.adapter.memberbadge; import com.smeem.common.code.failure.MemberFailureCode; +import com.smeem.domain.badge.model.Badge; import com.smeem.domain.member.exception.MemberException; +import com.smeem.domain.member.model.Member; import com.smeem.domain.member.model.MemberBadge; import com.smeem.domain.member.repository.MemberBadgeRepository; import com.smeem.domain.support.RepositoryAdapter; @@ -24,4 +26,8 @@ public MemberBadge findFirstByMemberIdOrderByCreatedAtDesc(final long id) { .orElseThrow(() -> new MemberException(MemberFailureCode.EMPTY_MEMBER)); } + public boolean isExist(Member member, Badge badge) { + return memberBadgeRepository.existsByMemberAndBadge(member, badge); + } + } diff --git a/smeem-domain/src/main/java/com/smeem/domain/member/repository/MemberBadgeRepository.java b/smeem-domain/src/main/java/com/smeem/domain/member/repository/MemberBadgeRepository.java index 548b1421..dd241479 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/member/repository/MemberBadgeRepository.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/repository/MemberBadgeRepository.java @@ -1,6 +1,7 @@ package com.smeem.domain.member.repository; import com.smeem.domain.badge.model.Badge; +import com.smeem.domain.member.model.Member; import com.smeem.domain.member.model.MemberBadge; import org.springframework.data.jpa.repository.JpaRepository; @@ -11,8 +12,6 @@ public interface MemberBadgeRepository extends JpaRepository List findAllByMemberId(final long memberId); Optional findFirstByMemberIdOrderByCreatedAtDesc(final long memberId); - long countByBadge(Badge badge); - - long countByBadgeIdAndMemberId(final long badgeId, final long memberId); + boolean existsByMemberAndBadge(Member member, Badge badge); } From 38f115de9ffd0f20913859a10b92ca164cd0c5ae Mon Sep 17 00:00:00 2001 From: thguss Date: Sun, 19 May 2024 10:43:15 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[FIX]=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/smeem/api/badge/service/BadgeService.java | 2 +- .../domain/member/adapter/memberbadge/MemberBadgeFinder.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java index 7b20d0bb..ef097aed 100644 --- a/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java +++ b/smeem-api/src/main/java/com/smeem/api/badge/service/BadgeService.java @@ -83,7 +83,7 @@ private Integer calculateRemainingNumber(Long badgeId, int count) { private BadgeGetServiceResponseV3 convertToBadgeGetServiceResponseV3(Badge badge, final long memberId) { val member = memberFinder.findById(memberId); - val hasBadge = memberBadgeFinder.isExist(member, badge); + val hasBadge = memberBadgeFinder.isExistByMemberAndBadge(member, badge); val memberDiaryCount = member.getDiaries().size(); val remainingNumber = calculateRemainingNumber(badge.getId(), memberDiaryCount); return BadgeGetServiceResponseV3.of(badge, hasBadge, remainingNumber); diff --git a/smeem-domain/src/main/java/com/smeem/domain/member/adapter/memberbadge/MemberBadgeFinder.java b/smeem-domain/src/main/java/com/smeem/domain/member/adapter/memberbadge/MemberBadgeFinder.java index 791d88c8..de4d1f12 100644 --- a/smeem-domain/src/main/java/com/smeem/domain/member/adapter/memberbadge/MemberBadgeFinder.java +++ b/smeem-domain/src/main/java/com/smeem/domain/member/adapter/memberbadge/MemberBadgeFinder.java @@ -26,7 +26,7 @@ public MemberBadge findFirstByMemberIdOrderByCreatedAtDesc(final long id) { .orElseThrow(() -> new MemberException(MemberFailureCode.EMPTY_MEMBER)); } - public boolean isExist(Member member, Badge badge) { + public boolean isExistByMemberAndBadge(Member member, Badge badge) { return memberBadgeRepository.existsByMemberAndBadge(member, badge); }