diff --git a/src/main/java/org/example/githubservice/model/Branch.java b/src/main/java/org/example/githubservice/model/Branch.java index c068776..4cffa22 100644 --- a/src/main/java/org/example/githubservice/model/Branch.java +++ b/src/main/java/org/example/githubservice/model/Branch.java @@ -1,5 +1,7 @@ package org.example.githubservice.model; -public record Branch(String name, Commit commit) { - +public record Branch( + String name, + Commit commit +) { } diff --git a/src/main/java/org/example/githubservice/model/Commit.java b/src/main/java/org/example/githubservice/model/Commit.java index c0b63b1..86f1379 100644 --- a/src/main/java/org/example/githubservice/model/Commit.java +++ b/src/main/java/org/example/githubservice/model/Commit.java @@ -1,4 +1,6 @@ package org.example.githubservice.model; -public record Commit(String sha) { +public record Commit( + String sha +) { } diff --git a/src/main/java/org/example/githubservice/model/Owner.java b/src/main/java/org/example/githubservice/model/Owner.java index bb9bf21..d088b3b 100644 --- a/src/main/java/org/example/githubservice/model/Owner.java +++ b/src/main/java/org/example/githubservice/model/Owner.java @@ -1,5 +1,6 @@ package org.example.githubservice.model; -public record Owner(String login) { - +public record Owner( + String login +) { } diff --git a/src/main/java/org/example/githubservice/model/Repository.java b/src/main/java/org/example/githubservice/model/Repository.java index 165fdeb..d688564 100644 --- a/src/main/java/org/example/githubservice/model/Repository.java +++ b/src/main/java/org/example/githubservice/model/Repository.java @@ -1,6 +1,15 @@ package org.example.githubservice.model; +import com.fasterxml.jackson.annotation.JsonProperty; + import java.util.List; -public record Repository(String name, Owner owner, Boolean fork, String branchesUrl, List branches) { +public record Repository( + String name, + Owner owner, + Boolean fork, + @JsonProperty("branches_url") + String branchesUrl, + List branches +) { } diff --git a/src/main/java/org/example/githubservice/service/GithubService.java b/src/main/java/org/example/githubservice/service/GithubService.java index 20c83b8..3c8dc24 100644 --- a/src/main/java/org/example/githubservice/service/GithubService.java +++ b/src/main/java/org/example/githubservice/service/GithubService.java @@ -6,9 +6,6 @@ import org.example.githubservice.model.dtos.RepositoryDTO; import org.springframework.stereotype.Service; import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import java.util.List; @Service public class GithubService { @@ -21,16 +18,13 @@ public GithubService(GithubClient githubClient) { public Flux getRepositoriesWithBranchesByUser(String username) { return githubClient.getAllRepositoriesByUser(username) .filter(repositoryDTO -> !repositoryDTO.fork()) - .flatMap(repository -> { - new RepositoryDTO(repository.name(), repository.owner().login(), getListOfBranchesDTO(repository)) - - }); - + .concatMap(repository -> getListOfBranchesDTO(repository) + .collectList() + .map(branches -> new RepositoryDTO(repository.name(), repository.owner().login(), branches))); } - private Mono> getListOfBranchesDTO(Repository repository) { + private Flux getListOfBranchesDTO(Repository repository) { return githubClient.getAllBranches(repository) - .map(branch -> new BranchDTO(branch.name(), branch.commit().sha())) - .collectList(); + .map(branch -> new BranchDTO(branch.name(), branch.commit().sha())); } }