Skip to content

Commit 0f07b9a

Browse files
authored
Merge pull request #105 from CommitField/feat/#97
feat: ์Šคํ”„๋ง ์ด๋ฒคํŠธ๋ฅผ ์ด์šฉํ•ด ๊ฒฝํ—˜์น˜, ํŽซ์— ์—ฐ๋™ ์™„๋ฃŒ
2 parents b589f0c + 8bd8b2d commit 0f07b9a

File tree

14 files changed

+195
-121
lines changed

14 files changed

+195
-121
lines changed

โ€Žsrc/main/java/cmf/commitField/domain/commit/scheduler/CommitScheduler.javaโ€Ž

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
import cmf.commitField.domain.user.repository.UserRepository;
66
import lombok.RequiredArgsConstructor;
77
import lombok.extern.slf4j.Slf4j;
8+
import org.springframework.context.ApplicationEventPublisher;
89
import org.springframework.data.redis.core.StringRedisTemplate;
910
import org.springframework.scheduling.annotation.Scheduled;
1011
import org.springframework.stereotype.Service;
1112

1213
import java.time.LocalDateTime;
13-
import java.time.format.DateTimeFormatter;
14-
import java.time.format.DateTimeParseException;
1514
import java.util.Set;
1615
import java.util.concurrent.TimeUnit;
1716
import java.util.concurrent.atomic.AtomicInteger;
@@ -21,11 +20,13 @@
2120
@RequiredArgsConstructor
2221
public class CommitScheduler {
2322
private final TotalCommitService totalCommitService;
24-
private final CommitCacheService commitCacheService;
2523
private final UserRepository userRepository;
2624
private final StringRedisTemplate redisTemplate;
2725
private final AtomicInteger counter = new AtomicInteger(0);
2826

27+
private final ApplicationEventPublisher eventPublisher;
28+
29+
2930
@Scheduled(fixedRate = 60000) // 1๋ถ„๋งˆ๋‹ค ์‹คํ–‰
3031
public void updateUserCommits() {
3132
log.info("๐Ÿ” updateUserCommits ์‹คํ–‰์ค‘");
@@ -43,62 +44,43 @@ public void updateUserCommits() {
4344
String lastcmKey = "commit_lastCommitted:" + username; // active์œ ์ €์˜ key
4445
String lastCommitted = redisTemplate.opsForValue().get(lastcmKey); // ๋งˆ์ง€๋ง‰ ์ปค๋ฐ‹ ์‹œ๊ฐ„
4546

46-
System.out.println("username: "+username);
47-
System.out.println("user lastCommitted: "+lastCommitted);
47+
System.out.println("username: "+username+"/ user lastCommitted: "+lastCommitted);
4848
if(username!=null && lastCommitted!=null) processUserCommit(username);
4949
}
5050
}
5151

5252
// ๐Ÿ”น ์œ ์ € ์ปค๋ฐ‹ ๊ฒ€์‚ฌ ๋ฐ ๋ฐ˜์˜
5353
private void processUserCommit(String username) {
5454
// ์œ ์ €๊ฐ€ ์ ‘์†ํ•œ ๋™์•ˆ ์ถ”๊ฐ€ํ•œ commit์ˆ˜๋ฅผ ํ™•์ธ.
55-
String key = "commit_active:" + username; // active์œ ์ €์˜ key
55+
String activeKey = "commit_active:" + username; // active์œ ์ €์˜ key
5656
String lastcmKey = "commit_lastCommitted:" + username; // active์œ ์ €์˜ key
57-
String currentCommit = redisTemplate.opsForValue().get(key); // ํ˜„์žฌ๊นŒ์ง€ ํ™•์ธํ•œ ์ปค๋ฐ‹ ๊ฐœ์ˆ˜
57+
Long currentCommit = Long.parseLong(redisTemplate.opsForValue().get(activeKey)); // ํ˜„์žฌ๊นŒ์ง€ ํ™•์ธํ•œ ์ปค๋ฐ‹ ๊ฐœ์ˆ˜
5858
String lastcommitted = redisTemplate.opsForValue().get(lastcmKey); // ๋งˆ์ง€๋ง‰ ์ปค๋ฐ‹ ์‹œ๊ฐ„
5959
long updateTotalCommit, newCommitCount;
6060

61+
// ํ˜„์žฌ ์ปค๋ฐ‹ ๊ฐœ์ˆ˜ ์กฐํšŒ
62+
updateTotalCommit = totalCommitService.getTotalCommitCount(
63+
username
64+
).getTotalCommitContributions();
6165

62-
LocalDateTime lastCommittedTime;
63-
try {
64-
lastCommittedTime = LocalDateTime.parse(lastcommitted, DateTimeFormatter.ISO_DATE_TIME);
65-
} catch (DateTimeParseException e) {
66-
System.out.println("lastcommitted ๊ฐ’์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Œ: " + lastcommitted);
67-
lastCommittedTime = LocalDateTime.now().minusHours(1);
68-
}
66+
newCommitCount = updateTotalCommit - currentCommit; // ์ƒˆ๋กœ ์ถ”๊ฐ€๋œ ์ปค๋ฐ‹ ์ˆ˜
6967

70-
// ํ˜„์žฌ ์ปค๋ฐ‹ ๊ฐœ์ˆ˜ ์กฐํšŒ
71-
updateTotalCommit = totalCommitService.getUpdateCommits(
72-
username,
73-
lastCommittedTime, // ๐Ÿš€ Redis์— ์ €์žฅ๋œ lastCommitted ๊ธฐ์ค€์œผ๋กœ ์กฐํšŒ
74-
LocalDateTime.now()
75-
).getCommits();
76-
System.out.println("์ปค๋ฐ‹ ๊ฐœ์ˆ˜ ๋ถˆ๋Ÿฌ๋“ค์ด๊ธฐ ์™„๋ฃŒ, ํ˜„์žฌ๊นŒ์ง€ ์—…๋ฐ์ดํŠธ ๋œ ์ปค๋ฐ‹ ์ˆ˜ : "+updateTotalCommit);
77-
78-
if(currentCommit.equals("0") && updateTotalCommit > 0){
68+
if(newCommitCount > 0){
7969
User user = userRepository.findByUsername(username).get();
8070
LocalDateTime now = LocalDateTime.now();
81-
//์ด๋ฒˆ ๊ธฐ๊ฐ„์— ์ฒ˜์Œ์œผ๋กœ ์ปค๋ฐ‹ ์ˆ˜๊ฐ€ ๊ฐฑ์‹ ๋œ ๊ฒฝ์šฐ, ์ด ์‹œ๊ฐ„์„ ๊ธฐ์ ์œผ๋กœ commitCount๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค.
71+
//์ปค๋ฐ‹ ์ˆ˜๊ฐ€ ๊ฐฑ์‹ ๋œ ๊ฒฝ์šฐ, ์ด ์‹œ๊ฐ„์„ ๊ธฐ์ ์œผ๋กœ lastCommitted๋ฅผ ๋ณ€๊ฒฝํ•œ๋‹ค.
8272
user.setLastCommitted(now);
8373
userRepository.save(user);
8474

85-
String redisKey = "commit_update:" + username; // ๋ณ€๊ฒฝ ์•Œ๋ฆผ์„ ์œ„ํ•œ ๋ณ€์ˆ˜
86-
redisTemplate.opsForValue().set(redisKey, String.valueOf(updateTotalCommit), 3, TimeUnit.HOURS);
87-
75+
redisTemplate.opsForValue().set(activeKey, String.valueOf(updateTotalCommit), 3, TimeUnit.HOURS);
8876
redisTemplate.opsForValue().set(lastcmKey, String.valueOf(now), 3, TimeUnit.HOURS);
89-
}
90-
91-
//๊ธฐ์กด ์ปค๋ฐ‹์ด ์žˆ๊ณ  ์ปค๋ฐ‹ ์ˆ˜์— ๋ณ€ํ™”๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ์ฒ˜๋ฆฌ
92-
newCommitCount = updateTotalCommit - Long.parseLong(currentCommit); // ์ƒˆ๋กœ ์ถ”๊ฐ€๋œ ์ปค๋ฐ‹ ์ˆ˜
93-
if(newCommitCount>0){
94-
String redisKey = "commit_update:" + username; // ๋ณ€๊ฒฝ ์•Œ๋ฆผ์„ ์œ„ํ•œ ๋ณ€์ˆ˜
95-
redisTemplate.opsForValue().set(redisKey, String.valueOf(newCommitCount), 3, TimeUnit.HOURS);
9677

97-
updateTotalCommit+=newCommitCount;
98-
redisTemplate.opsForValue().set(key, String.valueOf(updateTotalCommit), 3, TimeUnit.HOURS);
78+
CommitUpdateEvent event = new CommitUpdateEvent(this, username, newCommitCount);
79+
eventPublisher.publishEvent(event); // ์ด๋ฒคํŠธ ๋ฐœ์ƒ
80+
System.out.println("CommitCreatedEvent published for user: " + username);
9981
}
10082

10183
// FIXME: ์ฐจํ›„ ๋ฆฌํŒฉํ† ๋ง ํ•„์š”
102-
log.info("๐Ÿ” User: {}, LastCommitted: {}, New Commits: {}, Total Commits: {}", username, lastcommitted, newCommitCount, currentCommit);
84+
log.info("๐Ÿ” User: {}, LastCommitted: {}, New Commits: {}, Total Commits: {}", username, lastcommitted, newCommitCount, updateTotalCommit);
10385
}
10486
}
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
package cmf.commitField.domain.commit.scheduler;
22

3+
import lombok.Getter;
34
import org.springframework.context.ApplicationEvent;
45

6+
@Getter
57
public class CommitUpdateEvent extends ApplicationEvent {
6-
private final Long userId;
7-
private final int commitCount;
8+
private final String username;
9+
private final long newCommitCount;
810

9-
public CommitUpdateEvent(Object source, Long userId, int commitCount) {
11+
public CommitUpdateEvent(Object source, String username, long newCommitCount) {
1012
super(source);
11-
this.userId = userId;
12-
this.commitCount = commitCount;
13-
}
14-
15-
public Long getUserId() {
16-
return userId;
17-
}
18-
19-
public int getCommitCount() {
20-
return commitCount;
13+
this.username = username;
14+
this.newCommitCount = newCommitCount;
2115
}
2216
}
Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
11
package cmf.commitField.domain.commit.scheduler;
22

3+
import cmf.commitField.domain.pet.service.PetService;
4+
import cmf.commitField.domain.user.service.UserService;
5+
import lombok.RequiredArgsConstructor;
36
import org.springframework.context.event.EventListener;
4-
import org.springframework.stereotype.Service;
7+
import org.springframework.stereotype.Component;
58

6-
@Service
9+
@Component
10+
@RequiredArgsConstructor
711
public class CommitUpdateListener {
12+
private final UserService userService;
13+
private final PetService petService;
14+
private final CommitUpdateService commitUpdateService;
815

916
@EventListener
10-
public void handleCommitUpdateEvent(CommitUpdateEvent event) {
17+
public void handleCommitUserUpdateEvent(CommitUpdateEvent event) {
18+
String username = event.getUsername();
19+
long commitCount = event.getNewCommitCount();
20+
21+
System.out.println("์œ ์ € ์‹œ์ฆŒ ๊ฒฝํ—˜์น˜ ์—…๋ฐ์ดํŠธ: " + event.getUsername());
22+
// ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ ๋กœ์ง
23+
boolean levelUp = userService.getExpUser(username,commitCount);
24+
if(levelUp) commitUpdateService.updateUserTier(username);
25+
26+
// ๋ชจ๋“  ์ž‘์—…์ด ๋๋‚ฌ๋‹ค๋ฉด
27+
userService.updateUserCommitCount(username, commitCount);
28+
// ์ปค๋ฐ‹ ๊ฐฑ์‹  ํ›„์— ๋‹ค๋ฅธ ์„œ๋น„์Šค์—์„œ ํ•„์š”ํ•œ ์ž‘์—… ์ˆ˜ํ–‰ (์˜ˆ: DB ์—…๋ฐ์ดํŠธ, ์ƒํƒœ ๊ฐฑ์‹  ๋“ฑ)
29+
System.out.println("์œ ์ €๋ช…: " + username + " has updated " + commitCount + " commits.");
30+
}
31+
32+
@EventListener
33+
public void handleCommitPetUpdateEvent(CommitUpdateEvent event) {
34+
String username = event.getUsername();
35+
long commitCount = event.getNewCommitCount();
36+
37+
System.out.println("์œ ์ € ํŽซ ๊ฒฝํ—˜์น˜ ์—…๋ฐ์ดํŠธ: " + event.getUsername());
1138
// ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ ๋กœ์ง
12-
Long userId = event.getUserId();
13-
int commitCount = event.getCommitCount();
39+
petService.getExpPet(username,commitCount);
1440

1541
// ์ปค๋ฐ‹ ๊ฐฑ์‹  ํ›„์— ๋‹ค๋ฅธ ์„œ๋น„์Šค์—์„œ ํ•„์š”ํ•œ ์ž‘์—… ์ˆ˜ํ–‰ (์˜ˆ: DB ์—…๋ฐ์ดํŠธ, ์ƒํƒœ ๊ฐฑ์‹  ๋“ฑ)
16-
System.out.println("User ID: " + userId + " has updated " + commitCount + " commits.");
42+
System.out.println("์œ ์ €๋ช…: " + username + "'s pet has updated " + commitCount + " commits.");
1743
}
1844
}

โ€Žsrc/main/java/cmf/commitField/domain/commit/scheduler/CommitUpdateService.javaโ€Ž

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import cmf.commitField.domain.user.entity.User;
77
import cmf.commitField.domain.user.repository.UserRepository;
88
import lombok.RequiredArgsConstructor;
9-
import org.springframework.context.ApplicationEventPublisher;
109
import org.springframework.stereotype.Service;
1110

1211
import java.time.LocalDateTime;
@@ -18,14 +17,12 @@ public class CommitUpdateService {
1817
private final UserRepository userRepository;
1918
private final PetService petService;
2019

21-
private final ApplicationEventPublisher eventPublisher;
22-
2320
public UserInfoDto updateUserTier(String username){
2421
User user = userRepository.findByUsername(username).get();
2522
long seasonCommitCount;
26-
// seasonCommitCount = totalCommitService.getSeasonCommits(user.getUsername(), LocalDateTime.of(2024,12,01,0,0), LocalDateTime.of(2025,2,28,23,59)).getTotalCommitContributions();
27-
seasonCommitCount = totalCommitService.getSeasonCommits(user.getUsername(), LocalDateTime.of(2025,03,01,0,0), LocalDateTime.of(2025,05,31,23,59)).getTotalCommitContributions();
23+
seasonCommitCount = totalCommitService.getSeasonCommits(user.getUsername(), LocalDateTime.of(2025,03,01,0,0), LocalDateTime.of(2025,05,31,23,59)).getTotalCommitContributions();
2824
user.setTier(User.Tier.getLevelByExp((int)seasonCommitCount));
25+
System.out.println(username+"์œ ์ € ๋ ˆ๋ฒจ ์—…! ํ˜„์žฌ ํ‹ฐ์–ด: "+user.getTier());
2926
userRepository.save(user);
3027

3128
return UserInfoDto.builder()

โ€Žsrc/main/java/cmf/commitField/domain/commit/totalCommit/service/TotalCommitService.javaโ€Ž

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package cmf.commitField.domain.commit.totalCommit.service;
22

3-
import cmf.commitField.domain.commit.totalCommit.dto.CommitUpdateDTO;
43
import cmf.commitField.domain.commit.totalCommit.dto.TotalCommitGraphQLResponse;
54
import cmf.commitField.domain.commit.totalCommit.dto.TotalCommitResponseDto;
65
import lombok.RequiredArgsConstructor;
@@ -216,24 +215,25 @@ private StreakResult calculateStreaks(List<LocalDate> commitDates) {
216215
}
217216

218217
// ์‹œ๊ฐ„๋ณ„ ์ปค๋ฐ‹ ๋ถ„์„
219-
public CommitUpdateDTO getUpdateCommits(String username, LocalDateTime since, LocalDateTime until) {
218+
public long getUpdateCommits(String username, LocalDateTime since, LocalDateTime until) {
220219
String query = String.format("""
221220
query {
222221
user(login: "%s") {
223222
contributionsCollection(from: "%s", to: "%s") {
224223
commitContributionsByRepository {
225224
contributions(first: 100) {
226225
nodes {
227-
occurredAt # ์‹œ๊ฐ„ ์ •๋ณด ํฌํ•จ
226+
occurredAt
228227
}
229228
}
230229
}
231230
}
232231
}
233-
}""", username, since.format(DateTimeFormatter.ISO_DATE_TIME), until.format(DateTimeFormatter.ISO_DATE_TIME));
232+
}
233+
""", username, since.format(DateTimeFormatter.ISO_DATE_TIME), until.format(DateTimeFormatter.ISO_DATE_TIME));
234234

235235
Map<String, String> requestBody = Map.of("query", query);
236-
236+
System.out.println(username);
237237
TotalCommitGraphQLResponse response = webClient.post()
238238
.header("Authorization", "bearer " + PAT)
239239
.bodyValue(requestBody)
@@ -244,14 +244,52 @@ public CommitUpdateDTO getUpdateCommits(String username, LocalDateTime since, Lo
244244
if (response == null || response.getData() == null || response.getData().getUser() == null) {
245245
throw new RuntimeException("Failed to fetch GitHub data");
246246
}
247+
System.out.println(response);
247248

248-
249-
System.out.println("๋ฉ”์†Œ๋“œ ์ž‘๋™ ํ™•์ธ : "+response.getData().getUser());
250249
TotalCommitGraphQLResponse.ContributionsCollection contributions =
251250
response.getData().getUser().getContributionsCollection();
251+
// ์ปค๋ฐ‹ ๋ฐœ์ƒ ์‹œ๊ฐ„ ๋ฆฌ์ŠคํŠธ ์ถ”์ถœ
252+
List<LocalDateTime> commitTimes = extractCommitTimes(contributions.getContributionCalendar());
252253

253-
return new CommitUpdateDTO(
254-
contributions.getTotalCommitContributions()
255-
);
254+
// ์ดˆ ๋‹จ์œ„๋กœ ์ปค๋ฐ‹ ์ˆ˜ ๊ณ„์‚ฐ
255+
long commitCount = calculateCommitsInTimeRange(commitTimes, since, until);
256+
257+
return commitCount;
258+
}
259+
260+
// ์ปค๋ฐ‹ ๋ฐœ์ƒ ์‹œ๊ฐ„์„ LocalDateTime ํ˜•์‹์œผ๋กœ ์ถ”์ถœํ•˜๋Š” ๋ฉ”์„œ๋“œ
261+
private List<LocalDateTime> extractCommitTimes(TotalCommitGraphQLResponse.ContributionCalendar contributionCalendar) {
262+
List<LocalDateTime> commitTimes = new ArrayList<>();
263+
264+
if (contributionCalendar == null) {
265+
System.out.println("contributionCalendar is null");
266+
return commitTimes; // ๋นˆ ๋ฆฌ์ŠคํŠธ ๋ฐ˜ํ™˜
267+
}
268+
269+
// contributionCalendar์—์„œ ๊ฐ ์ฃผ ๋‹จ์œ„๋กœ ๋ฐ์ดํ„ฐ ์ถ”์ถœ
270+
contributionCalendar.getWeeks().forEach(week -> {
271+
week.getContributionDays().forEach(contributionDay -> {
272+
if (contributionDay.getContributionCount() > 0) {
273+
// ๊ฐ ๋‚ ์งœ์— ์ปค๋ฐ‹์ด ์žˆ๋Š” ๊ฒฝ์šฐ ๊ทธ ๋‚ ์งœ๋ฅผ ์ปค๋ฐ‹ ์‹œ๊ฐ„์œผ๋กœ ์ถ”๊ฐ€
274+
LocalDate commitDate = LocalDate.parse(contributionDay.getDate());
275+
// LocalDate๋ฅผ LocalDateTime์œผ๋กœ ๋ณ€ํ™˜ (์‹œ๊ฐ„์€ 00:00:00๋กœ ์„ค์ •)
276+
LocalDateTime commitTime = commitDate.atStartOfDay();
277+
commitTimes.add(commitTime);
278+
}
279+
});
280+
});
281+
282+
return commitTimes;
256283
}
284+
285+
286+
287+
// ์ปค๋ฐ‹ ์‹œ๊ฐ„ ๋ฆฌ์ŠคํŠธ์—์„œ since์™€ until ์‚ฌ์ด์— ๋ฐœ์ƒํ•œ ์ปค๋ฐ‹ ์ˆ˜ ๊ณ„์‚ฐ
288+
private long calculateCommitsInTimeRange(List<LocalDateTime> commitTimes, LocalDateTime since, LocalDateTime until) {
289+
return commitTimes.stream()
290+
.filter(commitTime -> !commitTime.isBefore(since) && !commitTime.isAfter(until))
291+
.count();
292+
}
293+
294+
257295
}

โ€Žsrc/main/java/cmf/commitField/domain/pet/entity/Pet.javaโ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Pet extends BaseEntity {
2222
private int type; // ํŽซ ํƒ€์ž… ๋„˜๋ฒ„, ํ˜„์žฌ 0~2๊นŒ์ง€ ์กด์žฌ
2323
private String name;
2424
private String imageUrl;
25-
private int exp; // ํŽซ ๊ฒฝํ—˜์น˜
25+
private long exp; // ํŽซ ๊ฒฝํ—˜์น˜
2626

2727
@Enumerated(EnumType.STRING) // DB์— ์ €์žฅ๋  ๋•Œ String ํ˜•ํƒœ๋กœ ์ €์žฅ๋จ
2828
private PetGrow grow; // ์„ฑ์žฅ ์ •๋„
@@ -48,9 +48,8 @@ public Pet(String name, User user){
4848
@JoinColumn(name = "user_id", nullable = false)
4949
private User user;
5050

51-
public int addExp(int commit){
51+
public long addExp(long commit){
5252
exp+=commit;
53-
5453
return exp;
5554
}
5655
}

โ€Žsrc/main/java/cmf/commitField/domain/pet/entity/PetGrow.javaโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public int getRequiredExp() {
1919
}
2020

2121
// ํ˜„์žฌ ๊ฒฝํ—˜์น˜์— ๋งž๋Š” ๋ ˆ๋ฒจ ์ฐพ๊ธฐ
22-
public static PetGrow getLevelByExp(int exp) {
22+
public static PetGrow getLevelByExp(long exp) {
2323
PetGrow currentLevel = EGG;
2424
for (PetGrow level : values()) {
2525
if (exp >= level.getRequiredExp()) {

โ€Žsrc/main/java/cmf/commitField/domain/pet/service/PetService.javaโ€Ž

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import cmf.commitField.global.aws.s3.S3Service;
1010
import lombok.RequiredArgsConstructor;
1111
import org.springframework.stereotype.Service;
12+
import org.springframework.transaction.annotation.Transactional;
1213
import org.springframework.web.multipart.MultipartFile;
1314

1415
import java.io.IOException;
@@ -53,15 +54,15 @@ public void deletePet(Long petId) {
5354
}
5455

5556
// ํŽซ ์„ฑ์žฅ
56-
public UserPetDto getExpPet(String username, int commitCount) {
57+
@Transactional
58+
public UserPetDto getExpPet(String username, long commitCount) {
5759
User user = userRepository.findByUsername(username).get();
5860
Pet pet = user.getPets().get(0);
5961
pet.addExp(commitCount); // ๊ฒฝํ—˜์น˜ ์ฆ๊ฐ€
62+
petRepository.save(pet);
6063

6164
// ๊ฒฝํ—˜์น˜ ์ฆ๊ฐ€ ํ›„, ๋งŒ์•ฝ ๋ ˆ๋ฒจ์—…ํ•œ๋‹ค๋ฉด ๋ ˆ๋ฒจ์—… ์‹œํ‚จ๋‹ค.
62-
if( (pet.getGrow()== PetGrow.EGG && pet.getExp()>= PetGrow.EGG.getRequiredExp()) ||
63-
(pet.getGrow()== PetGrow.HATCH && pet.getExp()>= PetGrow.HATCH.getRequiredExp())) {
64-
System.out.println("ํŽซ ๋ ˆ๋ฒจ ์—…, ํ˜„์žฌ ๊ฒฝํ—˜์น˜ : "+pet.getExp());
65+
if(!PetGrow.getLevelByExp(pet.getExp()).equals(pet.getGrow())){
6566
levelUp(pet);
6667
}
6768

@@ -76,13 +77,7 @@ public UserPetDto getExpPet(String username, int commitCount) {
7677

7778
// ํŽซ ๋ ˆ๋ฒจ ์—…
7879
public void levelUp(Pet pet){
79-
switch (pet.getGrow()){
80-
case EGG :
81-
pet.setGrow(PetGrow.HATCH);
82-
break;
83-
case HATCH :
84-
pet.setGrow(PetGrow.GROWN);
85-
break;
86-
}
80+
pet.setGrow(PetGrow.getLevelByExp(pet.getExp()));
81+
petRepository.save(pet);
8782
}
8883
}

0 commit comments

Comments
ย (0)