|
2 | 2 |
|
3 | 3 | import cmf.commitField.domain.commit.totalCommit.dto.TotalCommitResponseDto; |
4 | 4 | import cmf.commitField.domain.commit.totalCommit.service.TotalCommitService; |
| 5 | +import cmf.commitField.domain.user.entity.CustomOAuth2User; |
5 | 6 | import lombok.RequiredArgsConstructor; |
| 7 | +import org.springframework.security.core.annotation.AuthenticationPrincipal; |
6 | 8 | import org.springframework.web.bind.annotation.GetMapping; |
7 | | -import org.springframework.web.bind.annotation.PathVariable; |
8 | 9 | import org.springframework.web.bind.annotation.RestController; |
9 | 10 |
|
10 | 11 | import java.time.LocalDateTime; |
|
15 | 16 | public class TotalCommitController { |
16 | 17 | private final TotalCommitService totalCommitService; |
17 | 18 |
|
18 | | - @GetMapping("/api/commits/{username}") |
19 | | - public TotalCommitResponseDto getTotalCommits(@PathVariable String username) { |
| 19 | +// @GetMapping("/api/commits/{username}") |
| 20 | +// public TotalCommitResponseDto getTotalCommits(@PathVariable String username) { |
| 21 | +// return totalCommitService.getTotalCommitCount(username); |
| 22 | +// } |
| 23 | + |
| 24 | + // 로그인한 사용자의 username 이용 |
| 25 | + @GetMapping("/api/commits") |
| 26 | + public TotalCommitResponseDto getTotalCommits(@AuthenticationPrincipal CustomOAuth2User oAuth2User) { |
| 27 | + String username = oAuth2User.getName(); // CustomOAuth2User의 getName()은 user.getUsername()을 반환 |
| 28 | + |
20 | 29 | return totalCommitService.getTotalCommitCount(username); |
21 | 30 | } |
22 | 31 |
|
23 | 32 | // 봄 시즌(3/1 - 5/31) |
24 | | - @GetMapping("/api/commits/{username}/spring") |
25 | | - public TotalCommitResponseDto getSpringSeasonCommits(@PathVariable String username) { |
| 33 | +// @GetMapping("/api/commits/{username}/spring") |
| 34 | +// public TotalCommitResponseDto getSpringSeasonCommits(@PathVariable String username) { |
| 35 | +// int currentYear = LocalDateTime.now().getYear(); // 현재는 테스트용으로 2024 대입 |
| 36 | +// LocalDateTime since = LocalDateTime.of(2024, 3, 1, 0, 0); |
| 37 | +// LocalDateTime until = LocalDateTime.of(2024, 5, 31, 23, 59, 59); |
| 38 | +// return totalCommitService.getSeasonCommits(username, since, until); |
| 39 | +// } |
| 40 | + |
| 41 | + // 마찬가지로 로그인한 사용자의 username 이용 |
| 42 | + @GetMapping("/api/commits/spring") |
| 43 | + public TotalCommitResponseDto getSpringSeasonCommits(@AuthenticationPrincipal CustomOAuth2User oAuth2User) { |
| 44 | + String username = oAuth2User.getName(); |
26 | 45 | int currentYear = LocalDateTime.now().getYear(); // 현재는 테스트용으로 2024 대입 |
27 | 46 | LocalDateTime since = LocalDateTime.of(2024, 3, 1, 0, 0); |
28 | 47 | LocalDateTime until = LocalDateTime.of(2024, 5, 31, 23, 59, 59); |
29 | 48 | return totalCommitService.getSeasonCommits(username, since, until); |
30 | 49 | } |
31 | 50 |
|
32 | 51 | // 여름 시즌(6/1 - 8/31) |
33 | | - @GetMapping("/api/commits/{username}/summer") |
34 | | - public TotalCommitResponseDto getSummerSeasonCommits(@PathVariable String username) { |
| 52 | + @GetMapping("/api/commits/summer") |
| 53 | + public TotalCommitResponseDto getSummerSeasonCommits(@AuthenticationPrincipal CustomOAuth2User oAuth2User) { |
| 54 | + String username = oAuth2User.getName(); |
35 | 55 | int currentYear = LocalDateTime.now().getYear(); // 현재는 테스트용으로 2024 대입 |
36 | 56 | LocalDateTime since = LocalDateTime.of(2024, 6, 1, 0, 0); |
37 | 57 | LocalDateTime until = LocalDateTime.of(2024, 8, 31, 23, 59, 59); |
38 | 58 | return totalCommitService.getSeasonCommits(username, since, until); |
39 | 59 | } |
40 | 60 |
|
41 | 61 | // 가을 시즌(9/1 - 11/30) |
42 | | - @GetMapping("/api/commits/{username}/fall") |
43 | | - public TotalCommitResponseDto getFallSeasonCommits(@PathVariable String username) { |
| 62 | + @GetMapping("/api/commits/fall") |
| 63 | + public TotalCommitResponseDto getFallSeasonCommits(@AuthenticationPrincipal CustomOAuth2User oAuth2User) { |
| 64 | + String username = oAuth2User.getName(); |
44 | 65 | int currentYear = LocalDateTime.now().getYear(); // 현재는 테스트용으로 2024 대입 |
45 | 66 | LocalDateTime since = LocalDateTime.of(2024, 9, 1, 0, 0); |
46 | 67 | LocalDateTime until = LocalDateTime.of(2024, 11, 30, 23, 59, 59); |
47 | 68 | return totalCommitService.getSeasonCommits(username, since, until); |
48 | 69 | } |
49 | 70 |
|
50 | 71 | // 겨울 시즌(이전 년도 12/1 - 다음 년도 2/28) |
51 | | - @GetMapping("/api/commits/{username}/winter") |
52 | | - public TotalCommitResponseDto getWinterSeasonCommits(@PathVariable String username) { |
| 72 | + @GetMapping("/api/commits/winter") |
| 73 | + public TotalCommitResponseDto getWinterSeasonCommits(@AuthenticationPrincipal CustomOAuth2User oAuth2User) { |
| 74 | + String username = oAuth2User.getName(); |
53 | 75 | int currentYear = LocalDateTime.now().getYear(); // 현재는 테스트용으로 2024 대입 |
54 | 76 | LocalDateTime since = LocalDateTime.of(2024 - 1, 12, 1, 0, 0); |
55 | 77 | LocalDateTime until = LocalDateTime.of(2024, 2, 1, 23, 59, 59) |
|
0 commit comments