Skip to content

Commit

Permalink
REFACTORING: changing readability of records and repairing reactive s…
Browse files Browse the repository at this point in the history
…treams in GithubService
  • Loading branch information
Janek1010 committed Feb 16, 2024
1 parent 4a1aa4c commit 670d5d8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/main/java/org/example/githubservice/model/Branch.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.example.githubservice.model;

public record Branch(String name, Commit commit) {

public record Branch(
String name,
Commit commit
) {
}
4 changes: 3 additions & 1 deletion src/main/java/org/example/githubservice/model/Commit.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package org.example.githubservice.model;

public record Commit(String sha) {
public record Commit(
String sha
) {
}
5 changes: 3 additions & 2 deletions src/main/java/org/example/githubservice/model/Owner.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.example.githubservice.model;

public record Owner(String login) {

public record Owner(
String login
) {
}
11 changes: 10 additions & 1 deletion src/main/java/org/example/githubservice/model/Repository.java
Original file line number Diff line number Diff line change
@@ -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<Branch> branches) {
public record Repository(
String name,
Owner owner,
Boolean fork,
@JsonProperty("branches_url")
String branchesUrl,
List<Branch> branches
) {
}
16 changes: 5 additions & 11 deletions src/main/java/org/example/githubservice/service/GithubService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -21,16 +18,13 @@ public GithubService(GithubClient githubClient) {
public Flux<RepositoryDTO> 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<List<BranchDTO>> getListOfBranchesDTO(Repository repository) {
private Flux<BranchDTO> 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()));
}
}

0 comments on commit 670d5d8

Please sign in to comment.