Skip to content

Commit fa18079

Browse files
committed
feat: 트렌딩 레포지터리 추천, 카테고리별 레포지터리 생성 완료
1 parent c18d2da commit fa18079

File tree

7 files changed

+63
-12
lines changed

7 files changed

+63
-12
lines changed

src/main/java/Capstone/FOSSistant/global/apiPayload/code/status/ErrorStatus.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public enum ErrorStatus implements BaseErrorCode {
3333
NOT_CONTAIN_TOKEN(HttpStatus.INTERNAL_SERVER_ERROR, "INFRA_500_003", "Redis에 토큰이 없음."),
3434
AI_API_FAIL(HttpStatus.BAD_GATEWAY, "EXT_502_001", "AI API 호출 실패"),
3535
GITHUB_API_FAIL(HttpStatus.BAD_GATEWAY, "EXT_502_002", "Github API 호출 실패"),
36+
GITHUB_NO_REPOSITORY_FOUND(HttpStatus.BAD_GATEWAY, "EXT_502_002", "DB에 저장된 레포지터리 없음"),
3637

3738
// 가장 일반적인 응답
3839
_INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "COMMON500", "서버 에러, 관리자에게 문의 바랍니다."),

src/main/java/Capstone/FOSSistant/global/repository/GithubRepositoryRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77

88
public interface GithubRepositoryRepository extends JpaRepository<GitHubRepository, Long> {
99
List<GitHubRepository> findAllByLanguage(String language);
10+
List<GitHubRepository> findTop15ByLanguage(String language);
1011

1112
}

src/main/java/Capstone/FOSSistant/global/service/githubRepo/GithubRepositoryService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public interface GithubRepositoryService {
77
void fetchAndStoreTrendingRepositories();
88

99
GithubRepoDTO.GithubRepoListDTO recommendTopRepositories(Member member);
10-
}
10+
GithubRepoDTO.GithubRepoListDTO recommendByLanguage(String language);
11+
}
1112

1213

src/main/java/Capstone/FOSSistant/global/service/githubRepo/GithubRepositoryServiceImpl.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package Capstone.FOSSistant.global.service.githubRepo;
22

3+
import Capstone.FOSSistant.global.apiPayload.code.status.ErrorStatus;
4+
import Capstone.FOSSistant.global.apiPayload.exception.GeneralException;
35
import Capstone.FOSSistant.global.domain.entity.GitHubRepository;
46
import Capstone.FOSSistant.global.domain.entity.Member;
57
import Capstone.FOSSistant.global.domain.entity.MemberTopLanguage;
@@ -11,6 +13,7 @@
1113
import org.springframework.stereotype.Service;
1214
import org.springframework.transaction.annotation.Transactional;
1315

16+
import java.util.Collections;
1417
import java.util.List;
1518
import java.util.Objects;
1619

@@ -65,4 +68,32 @@ private GithubRepoDTO.GithubRepoResponseDTO toDto(GitHubRepository repo) {
6568
.stars(repo.getStars())
6669
.build();
6770
}
71+
72+
@Override
73+
public GithubRepoDTO.GithubRepoListDTO recommendByLanguage(String language) {
74+
List<GitHubRepository> repoList = gitHubRepositoryRepository.findTop15ByLanguage(language);
75+
76+
if (repoList.isEmpty()) {
77+
throw new GeneralException(ErrorStatus.GITHUB_NO_REPOSITORY_FOUND);
78+
}
79+
80+
Collections.shuffle(repoList);
81+
List<GitHubRepository> random3 = repoList.stream().limit(3).toList();
82+
83+
List<GithubRepoDTO.GithubRepoResponseDTO> result = random3.stream()
84+
.map(repo -> GithubRepoDTO.GithubRepoResponseDTO.builder()
85+
.name(repo.getName())
86+
.fullName(repo.getFullName())
87+
.url(repo.getUrl())
88+
.description(repo.getDescription())
89+
.language(repo.getLanguage())
90+
.stars(repo.getStars())
91+
.build())
92+
.toList();
93+
94+
return GithubRepoDTO.GithubRepoListDTO.builder()
95+
.results(result)
96+
.build();
97+
}
98+
6899
}

src/main/java/Capstone/FOSSistant/global/web/controller/GithubRepoController.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import Capstone.FOSSistant.global.web.dto.util.custom.ApiErrorCodeExamples;
1212
import io.swagger.v3.oas.annotations.Operation;
1313
import io.swagger.v3.oas.annotations.Parameter;
14+
import io.swagger.v3.oas.annotations.media.Schema;
1415
import io.swagger.v3.oas.annotations.tags.Tag;
1516
import lombok.RequiredArgsConstructor;
1617
import lombok.extern.slf4j.Slf4j;
@@ -26,14 +27,14 @@ public class GithubRepoController {
2627

2728
private final GithubRepositoryServiceImpl githubRepositoryService;
2829

29-
@PostMapping("/trending")
30-
@Operation(summary = "트렌딩 레포지터리 저장", description = "언어별 트렌딩 레포지터리 15개씩 가져와 DB에 저장")
31-
@ApiErrorCodeExamples({ErrorStatus.GITHUB_API_FAIL, ErrorStatus._INTERNAL_SERVER_ERROR})
32-
public APiResponse<Void> storeTrendingRepositories() {
33-
log.info("트렌딩 레포지터리 저장 요청 수신");
34-
githubRepositoryService.fetchAndStoreTrendingRepositories();
35-
return APiResponse.onSuccess(SuccessStatus.REPO_CRAWLING_OK, null);
36-
}
30+
// @PostMapping("/trending")
31+
// @Operation(summary = "트렌딩 레포지터리 저장", description = "언어별 트렌딩 레포지터리 15개씩 가져와 DB에 저장")
32+
// @ApiErrorCodeExamples({ErrorStatus.GITHUB_API_FAIL, ErrorStatus._INTERNAL_SERVER_ERROR})
33+
// public APiResponse<Void> storeTrendingRepositories() {
34+
// log.info("트렌딩 레포지터리 저장 요청 수신");
35+
// githubRepositoryService.fetchAndStoreTrendingRepositories();
36+
// return APiResponse.onSuccess(SuccessStatus.REPO_CRAWLING_OK, null);
37+
// }
3738

3839
@GetMapping("/personal")
3940
@Operation(
@@ -45,6 +46,22 @@ public APiResponse<GithubRepoDTO.GithubRepoListDTO> recommendUserTopLangRepos(@A
4546
githubRepositoryService.recommendTopRepositories(member));
4647
}
4748

48-
49+
@GetMapping("/category/{language}")
50+
@Operation(
51+
summary = "언어별 레포지터리 추천",
52+
description = "지정한 언어(Java, TypeScript, JavaScript, Python, Jupyter Notebook)에 해당하는 무작위 레포지터리 3개를 반환합니다."
53+
)
54+
public APiResponse<GithubRepoDTO.GithubRepoListDTO> recommendByLanguage(
55+
@Parameter(
56+
description = "프론트에서 선택한 언어. 다음 중 하나여야 합니다: Java, TypeScript, JavaScript, Python, Jupyter Notebook",
57+
schema = @Schema(allowableValues = {
58+
"Java", "TypeScript", "JavaScript", "Python", "Jupyter Notebook"
59+
})
60+
)
61+
@PathVariable String language
62+
) {
63+
return APiResponse.onSuccess(SuccessStatus.REPO_RECOMMEND_OK,
64+
githubRepositoryService.recommendByLanguage(language));
65+
}
4966

5067
}

src/main/java/Capstone/FOSSistant/global/web/dto/GithubRepo/GithubRepoDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package Capstone.FOSSistant.global.web.dto.GithubRepo;
22

3+
import io.swagger.v3.oas.annotations.media.Schema;
34
import lombok.*;
45

56
import java.util.List;
@@ -28,5 +29,4 @@ public static class GithubRepoResponseDTO {
2829
public static class GithubRepoListDTO {
2930
private List<GithubRepoResponseDTO> results;
3031
}
31-
3232
}

src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ spring:
2727

2828
data:
2929
redis:
30-
host: localhost # ※운영 환경에서는 localhost → redis
30+
host: redis # ※운영 환경에서는 localhost → redis
3131
port: 6379
3232

3333
gemini:

0 commit comments

Comments
 (0)