Skip to content

Commit

Permalink
REFACTORING: new constructor in RepositoryDTO (with usage in GithubSe…
Browse files Browse the repository at this point in the history
…rviceImpl) and in GithubController
  • Loading branch information
Janek1010 committed Feb 15, 2024
1 parent 1a92f31 commit 6c981b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.example.githubservice.controller;

import lombok.RequiredArgsConstructor;
import org.example.githubservice.model.dtos.RepositoryDTO;
import org.example.githubservice.model.dtos.UserNotFoundErrorResponseDTO;
import org.example.githubservice.service.api.GithubService;
Expand All @@ -14,11 +13,14 @@
import reactor.core.publisher.Flux;

@RestController
@RequiredArgsConstructor
public class GithubController {
private final String REPOS_OF_USER = "/api/v1/users/{username}/repos";
private final GithubService githubService;

public GithubController(GithubService githubService) {
this.githubService = githubService;
}

@GetMapping(value = REPOS_OF_USER, produces = MediaType.APPLICATION_JSON_VALUE)
public Flux<RepositoryDTO> listAllRepositoriesOfUser(@PathVariable String username) {
return githubService.listAllRepositoriesOfUser(username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ public record RepositoryDTO(
//@JsonProperty("ownerLogin")
OwnerDTO owner,
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
boolean fork,
Boolean fork,
@JsonProperty(value = "branches_url", access = JsonProperty.Access.WRITE_ONLY)
String branchesUrl,
List<BranchDTO> branches
) {}
) {
public RepositoryDTO(String name, OwnerDTO owner, List<BranchDTO> branches) {
this(name, owner,null, null, branches);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Mono<RepositoryDTO> listAllBranches(RepositoryDTO repositoryDTO) {
.retrieve()
.bodyToFlux(BranchDTO.class)
.collectList()
.map(branches -> new RepositoryDTO(repositoryDTO.name(), repositoryDTO.owner(), repositoryDTO.fork(), repositoryDTO.branchesUrl(), branches));
.map(branches -> new RepositoryDTO(repositoryDTO.name(), repositoryDTO.owner(), branches));
}

}

0 comments on commit 6c981b8

Please sign in to comment.