Skip to content

Commit 0a068d6

Browse files
committed
Feat: 로그인 정보 이용해서 커밋 정보 불러오기
1 parent d3e8104 commit 0a068d6

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

src/main/java/cmf/commitField/domain/commit/totalCommit/controller/TotalCommitController.java

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import cmf.commitField.domain.commit.totalCommit.dto.TotalCommitResponseDto;
44
import cmf.commitField.domain.commit.totalCommit.service.TotalCommitService;
5+
import cmf.commitField.domain.user.entity.CustomOAuth2User;
56
import lombok.RequiredArgsConstructor;
7+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
68
import org.springframework.web.bind.annotation.GetMapping;
7-
import org.springframework.web.bind.annotation.PathVariable;
89
import org.springframework.web.bind.annotation.RestController;
910

1011
import java.time.LocalDateTime;
@@ -15,41 +16,62 @@
1516
public class TotalCommitController {
1617
private final TotalCommitService totalCommitService;
1718

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+
2029
return totalCommitService.getTotalCommitCount(username);
2130
}
2231

2332
// 봄 시즌(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();
2645
int currentYear = LocalDateTime.now().getYear(); // 현재는 테스트용으로 2024 대입
2746
LocalDateTime since = LocalDateTime.of(2024, 3, 1, 0, 0);
2847
LocalDateTime until = LocalDateTime.of(2024, 5, 31, 23, 59, 59);
2948
return totalCommitService.getSeasonCommits(username, since, until);
3049
}
3150

3251
// 여름 시즌(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();
3555
int currentYear = LocalDateTime.now().getYear(); // 현재는 테스트용으로 2024 대입
3656
LocalDateTime since = LocalDateTime.of(2024, 6, 1, 0, 0);
3757
LocalDateTime until = LocalDateTime.of(2024, 8, 31, 23, 59, 59);
3858
return totalCommitService.getSeasonCommits(username, since, until);
3959
}
4060

4161
// 가을 시즌(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();
4465
int currentYear = LocalDateTime.now().getYear(); // 현재는 테스트용으로 2024 대입
4566
LocalDateTime since = LocalDateTime.of(2024, 9, 1, 0, 0);
4667
LocalDateTime until = LocalDateTime.of(2024, 11, 30, 23, 59, 59);
4768
return totalCommitService.getSeasonCommits(username, since, until);
4869
}
4970

5071
// 겨울 시즌(이전 년도 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();
5375
int currentYear = LocalDateTime.now().getYear(); // 현재는 테스트용으로 2024 대입
5476
LocalDateTime since = LocalDateTime.of(2024 - 1, 12, 1, 0, 0);
5577
LocalDateTime until = LocalDateTime.of(2024, 2, 1, 23, 59, 59)

0 commit comments

Comments
 (0)