From 6c981b85919ad66ced1a60eb0d49f12a323e51e1 Mon Sep 17 00:00:00 2001 From: Janek1010 Date: Thu, 15 Feb 2024 16:38:57 +0100 Subject: [PATCH] REFACTORING: new constructor in RepositoryDTO (with usage in GithubServiceImpl) and in GithubController --- .../githubservice/controller/GithubController.java | 6 ++++-- .../example/githubservice/model/dtos/RepositoryDTO.java | 8 ++++++-- .../githubservice/service/impl/GithubServiceImpl.java | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/example/githubservice/controller/GithubController.java b/src/main/java/org/example/githubservice/controller/GithubController.java index 12675c5..dec4d08 100644 --- a/src/main/java/org/example/githubservice/controller/GithubController.java +++ b/src/main/java/org/example/githubservice/controller/GithubController.java @@ -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; @@ -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 listAllRepositoriesOfUser(@PathVariable String username) { return githubService.listAllRepositoriesOfUser(username); diff --git a/src/main/java/org/example/githubservice/model/dtos/RepositoryDTO.java b/src/main/java/org/example/githubservice/model/dtos/RepositoryDTO.java index 1e842ee..36dd311 100644 --- a/src/main/java/org/example/githubservice/model/dtos/RepositoryDTO.java +++ b/src/main/java/org/example/githubservice/model/dtos/RepositoryDTO.java @@ -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 branches -) {} +) { + public RepositoryDTO(String name, OwnerDTO owner, List branches) { + this(name, owner,null, null, branches); + } +} diff --git a/src/main/java/org/example/githubservice/service/impl/GithubServiceImpl.java b/src/main/java/org/example/githubservice/service/impl/GithubServiceImpl.java index b7993fd..456e2fe 100644 --- a/src/main/java/org/example/githubservice/service/impl/GithubServiceImpl.java +++ b/src/main/java/org/example/githubservice/service/impl/GithubServiceImpl.java @@ -45,7 +45,7 @@ public Mono 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)); } }