|
1 | 1 | package cmf.commitField.domain.commit.scheduler; |
2 | 2 |
|
3 | 3 | import cmf.commitField.domain.commit.totalCommit.service.TotalCommitService; |
| 4 | +import cmf.commitField.domain.pet.service.PetService; |
| 5 | +import cmf.commitField.domain.user.dto.UserInfoDto; |
4 | 6 | import cmf.commitField.domain.user.entity.User; |
5 | 7 | import cmf.commitField.domain.user.repository.UserRepository; |
6 | 8 | import lombok.RequiredArgsConstructor; |
7 | | -import org.springframework.security.oauth2.core.user.OAuth2User; |
8 | 9 | import org.springframework.stereotype.Service; |
9 | | -import org.springframework.web.bind.annotation.GetMapping; |
10 | 10 |
|
11 | 11 | import java.time.LocalDateTime; |
12 | 12 |
|
13 | 13 | @Service |
14 | 14 | @RequiredArgsConstructor |
15 | 15 | public class CommitUpdateService { |
16 | | - TotalCommitService totalCommitService; |
17 | | - UserRepository userRepository; |
18 | | - @GetMapping("commit/tier") |
19 | | - public User updateUserTier(OAuth2User oAuth2User){ |
20 | | - User user = userRepository.findByEmail(oAuth2User.getName()).get(); |
| 16 | + private final TotalCommitService totalCommitService; |
| 17 | + private final UserRepository userRepository; |
| 18 | + private final PetService petService; |
| 19 | + |
| 20 | + public UserInfoDto updateUserTier(String username){ |
| 21 | + User user = userRepository.findByUsername(username).get(); |
21 | 22 | long seasonCommitCount; |
22 | | - seasonCommitCount = totalCommitService.getSeasonCommits(user.getUsername(), LocalDateTime.of(2024,12,01,0,0), LocalDateTime.of(2025,2,28,23,59)).getTotalCommitContributions(); |
23 | | -// 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(2024,12,01,0,0), LocalDateTime.of(2025,2,28,23,59)).getTotalCommitContributions(); |
| 24 | + seasonCommitCount = totalCommitService.getSeasonCommits(user.getUsername(), LocalDateTime.of(2025,03,01,0,0), LocalDateTime.of(2025,05,31,23,59)).getTotalCommitContributions(); |
24 | 25 | user.setTier(User.Tier.getLevelByExp((int)seasonCommitCount)); |
| 26 | + userRepository.save(user); |
| 27 | + |
| 28 | + return UserInfoDto.builder() |
| 29 | + .userId(user.getId()) |
| 30 | + .username(user.getUsername()) |
| 31 | + .email(user.getEmail()) |
| 32 | + .avatarUrl(user.getAvatarUrl()) |
| 33 | + .createdAt(user.getCreatedAt()) |
| 34 | + .lastCommitted(user.getLastCommitted()) |
| 35 | + .commitCount(user.getCommitCount()) |
| 36 | + .tier(user.getTier().name()) |
| 37 | + .build(); |
| 38 | + } |
| 39 | + |
| 40 | + public User updateUserPet(String username){ |
| 41 | + User user = userRepository.findByUsername(username).get(); |
| 42 | + |
| 43 | + //추가된 펫 경험치 |
| 44 | + long totalcommits; |
| 45 | + totalcommits = totalCommitService.getUpdateCommits(user.getUsername(), user.getCreatedAt(), LocalDateTime.now()).getTotalCommitContributions(); |
| 46 | + |
| 47 | + petService.getExpPet(user, (int)totalcommits); |
25 | 48 | return user; |
26 | 49 | } |
27 | 50 | } |
0 commit comments