Skip to content

Commit

Permalink
removed code smells #124
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazlunn committed Mar 24, 2021
1 parent 1904c31 commit 3715768
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
@Service("gitHubClient")
public class GitHubServiceRest implements GitHubService {

private final String HTTPS = "https";
private final String REPOS = "/repos/";
private final String ISSUES = "/issues";
private final String UNEXPECTED_ERROR = "Unexpected error. GitHub Service.";

private String gitHubUri;
private String gitHubOwner;
private String gitHubRepo;
Expand Down Expand Up @@ -44,20 +49,20 @@ public Mono<Issue> read(Integer number) {
return this.webClientBuilder.build()
.get()
.uri(uriBuilder -> uriBuilder
.scheme("https")
.scheme(HTTPS)
.host(gitHubUri)
.path("/repos/" + gitHubOwner + "/" + gitHubRepo + "/issues/" + number)
.path(REPOS + gitHubOwner + "/" + gitHubRepo + ISSUES + "/" + number)
.build())
.exchange()
.onErrorResume(exception ->
Mono.error(new BadGatewayException("Unexpected error. GitHub Service. " + exception.getMessage())))
Mono.error(new BadGatewayException(UNEXPECTED_ERROR + exception.getMessage())))
.flatMap(response -> {
if (HttpStatus.UNAUTHORIZED.equals(response.statusCode())) {
return Mono.error(new ForbiddenException("Forbidden: GitHub Issue Details"));
} else if (HttpStatus.NOT_FOUND.equals(response.statusCode())) {
return Mono.error(new NotFoundException("Not Found: GitHub Issue Details"));
} else if (response.statusCode().isError()) {
return Mono.error(new BadGatewayException("Unexpected error: GitHub Service."));
return Mono.error(new BadGatewayException(UNEXPECTED_ERROR));
} else {
return response.bodyToMono(Issue.class);
}
Expand All @@ -74,21 +79,21 @@ public Flux<Issue> search(String labels, String state, String assignee) {
return this.webClientBuilder.build()
.get()
.uri(uriBuilder -> uriBuilder
.scheme("https")
.scheme(HTTPS)
.host(gitHubUri)
.path("/repos/" + gitHubOwner + "/" + gitHubRepo + "/issues")
.path(REPOS + gitHubOwner + "/" + gitHubRepo + ISSUES)
.query(query)
.build())
.exchange()
.onErrorResume(exception ->
Mono.error(new BadGatewayException("Unexpected error. GitHub Service. " + exception.getMessage())))
Mono.error(new BadGatewayException(UNEXPECTED_ERROR + exception.getMessage())))
.flatMapMany(response -> {
if (HttpStatus.UNAUTHORIZED.equals(response.statusCode())) {
return Mono.error(new ForbiddenException("Forbidden: GitHub Issue Search"));
} else if (HttpStatus.NOT_FOUND.equals(response.statusCode())) {
return Mono.error(new NotFoundException("Not Found: GitHub Issue Search"));
} else if (response.statusCode().isError()) {
return Mono.error(new BadGatewayException("Unexpected error: GitHub Service."));
return Mono.error(new BadGatewayException(UNEXPECTED_ERROR));
} else {
return response.bodyToFlux(Issue.class);
}
Expand All @@ -102,21 +107,21 @@ public Mono<Issue> create(IssueCreationDto issueCreationDto) {
.mutate().defaultHeader("Authorization", "token " + gitHubAPIKey).build()
.post()
.uri(uriBuilder -> uriBuilder
.scheme("https")
.scheme(HTTPS)
.host(gitHubUri)
.path("/repos/" + gitHubOwner + "/" + gitHubRepo + "/issues")
.path(REPOS + gitHubOwner + "/" + gitHubRepo + ISSUES)
.build())
.body(Mono.just(issueCreationDto), IssueCreationDto.class)
.exchange()
.onErrorResume(exception ->
Mono.error(new BadGatewayException("Unexpected error. GitHub Service. " + exception.getMessage())))
Mono.error(new BadGatewayException(UNEXPECTED_ERROR + exception.getMessage())))
.flatMap(response -> {
if (HttpStatus.UNAUTHORIZED.equals(response.statusCode())) {
return Mono.error(new ForbiddenException("Forbidden: GitHub Issue Creation"));
} else if (HttpStatus.NOT_FOUND.equals(response.statusCode())) {
return Mono.error(new NotFoundException("Not Found: GitHub Issue Creation"));
} else if (response.statusCode().isError()) {
return Mono.error(new BadGatewayException("Unexpected error: GitHub Service."));
return Mono.error(new BadGatewayException(UNEXPECTED_ERROR));
} else {
return response.bodyToMono(Issue.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import static org.mockito.ArgumentMatchers.*;

@RestTestConfig
public class IssueResourceIT {
class IssueResourceIT {

@Autowired
private WebTestClient webTestClient;
Expand Down

0 comments on commit 3715768

Please sign in to comment.