Skip to content

Commit 8157243

Browse files
authored
Merge pull request #108 from Team-Wable/fix/#102
[FIX] calculate preinCommuiryMember percent logic
2 parents d641f00 + 788ca42 commit 8157243

4 files changed

Lines changed: 49 additions & 9 deletions

File tree

WableServer/src/main/java/com/wable/www/WableServer/api/community/domain/Community.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,4 @@ public class Community {
2424
public void increaseCommunityNumber() {
2525
this.communityNumber++;
2626
}
27-
28-
public double calculatePercent() {
29-
int communityNumber = this.communityNumber;
30-
final int TOTAL = 50;
31-
if (communityNumber == 0) return 0.0;
32-
return Math.round(((double) communityNumber / TOTAL * 100.0) * 10) / 10.0;
33-
}
3427
}

WableServer/src/main/java/com/wable/www/WableServer/api/community/service/CommunityCommandService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.wable.www.WableServer.api.community.repository.CommunityRepository;
77
import com.wable.www.WableServer.api.member.domain.Member;
88
import com.wable.www.WableServer.api.member.repository.MemberRepository;
9+
import com.wable.www.WableServer.common.util.CommunityUtil;
910
import lombok.RequiredArgsConstructor;
1011
import org.springframework.stereotype.Service;
1112
import org.springframework.transaction.annotation.Transactional;
@@ -32,6 +33,6 @@ public PreinCommunityResponseDto preinCommunityVer2(Long memberId, CommunityPrei
3233
Community community = communityRepository.getCommunityByCommunityName(communityPreinRequestDto.communityName());
3334
community.increaseCommunityNumber();
3435

35-
return PreinCommunityResponseDto.of(community.calculatePercent());
36+
return PreinCommunityResponseDto.of(CommunityUtil.calculatePercent(community.getCommunityName(), community.getCommunityNumber()));
3637
}
3738
}

WableServer/src/main/java/com/wable/www/WableServer/api/community/service/CommunityQueryService.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import com.wable.www.WableServer.api.community.dto.response.GetMemberCommunityResponseDto;
66
import com.wable.www.WableServer.api.community.repository.CommunityRepository;
77
import com.wable.www.WableServer.api.member.repository.MemberRepository;
8+
import com.wable.www.WableServer.common.util.CommunityUtil;
89
import lombok.RequiredArgsConstructor;
910
import org.springframework.stereotype.Service;
1011
import org.springframework.transaction.annotation.Transactional;
1112

1213
import java.util.List;
14+
import java.util.Map;
1315
import java.util.stream.Collectors;
1416

1517
@Service
@@ -19,6 +21,19 @@ public class CommunityQueryService {
1921
private final MemberRepository memberRepository;
2022
private final CommunityRepository communityRepository;
2123

24+
private static final Map<String, Integer> TOTAL_MAP = Map.of(
25+
"T1", 80,
26+
"DK", 18,
27+
"GEN", 20,
28+
"KT", 10,
29+
"HLE", 22,
30+
"BFX", 8,
31+
"DNF", 8,
32+
"NS", 8,
33+
"DRX", 18,
34+
"BRO", 8
35+
);
36+
2237
public GetMemberCommunityResponseDto getMemberCommunity(Long memberId) {
2338
String memberCommunity = memberRepository.findMemberByIdOrThrow(memberId).getMemberCommunity();
2439
return GetMemberCommunityResponseDto.of(memberCommunity);
@@ -27,7 +42,10 @@ public GetMemberCommunityResponseDto getMemberCommunity(Long memberId) {
2742
public List<GetCommunityListResponseDto> getCommunityList() {
2843
List<Community> communities = communityRepository.findAll();
2944
return communities.stream()
30-
.map(community -> GetCommunityListResponseDto.of(community.getCommunityName(), community.calculatePercent()))
45+
.map(community -> {
46+
double percent = CommunityUtil.calculatePercent(community.getCommunityName(), community.getCommunityNumber());
47+
return GetCommunityListResponseDto.of(community.getCommunityName(), percent);
48+
})
3149
.collect(Collectors.toList());
3250
}
3351
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.wable.www.WableServer.common.util;
2+
3+
import lombok.RequiredArgsConstructor;
4+
5+
import java.util.Map;
6+
7+
@RequiredArgsConstructor
8+
public class CommunityUtil {
9+
private static final Map<String, Integer> TOTAL_MAP = Map.of(
10+
"T1", 80,
11+
"DK", 18,
12+
"GEN", 20,
13+
"KT", 10,
14+
"HLE", 22,
15+
"BFX", 8,
16+
"DNF", 8,
17+
"NS", 8,
18+
"DRX", 18,
19+
"BRO", 8
20+
);
21+
22+
public static double calculatePercent(String communityName, int communityNumber) {
23+
int total = TOTAL_MAP.getOrDefault(communityName, 50);
24+
if (total == 0 || communityNumber == 0) return 0.0;
25+
if (communityNumber >= total) return 100.0;
26+
return Math.round(((double) communityNumber / total * 100.0) * 10) / 10.0;
27+
}
28+
}

0 commit comments

Comments
 (0)