Skip to content

Commit aaaff9a

Browse files
committed
refactor: clean up
1 parent c94d8f9 commit aaaff9a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

backend/src/main/java/ch/xxx/aidoclibchat/adapter/client/ImportRestClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public List<Artist> importArtists() {
5555
String result = this.restClient.get().uri(
5656
"https://raw.githubusercontent.com/Angular2Guy/AIDocumentLibraryChat/master/museumDataset/artist.csv")
5757
.retrieve().body(String.class);
58-
return this.mapString(result, ArtistDto.class).stream().map(myDto -> this.tableMapper.map(myDto)).toList();
58+
return this.mapString(result, ArtistDto.class).stream().map(this.tableMapper::map).toList();
5959
}
6060

6161
private <T> List<T> mapString(String result, Class<T> myClass) {

backend/src/main/java/ch/xxx/aidoclibchat/adapter/client/OpenLibraryRestClient.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,27 @@ public class OpenLibraryRestClient implements OpenLibraryClient {
3434
private final RestClient restClient;
3535
@Value("${openlibrary.result-size:10}")
3636
private int resultLimit;
37-
37+
3838
public OpenLibraryRestClient(RestClient restClient) {
3939
this.restClient = restClient;
4040
}
41-
41+
4242
@Override
4343
public Response apply(Request request) {
4444
var authorOpt = this.createParamOpt(request.author(), "author");
4545
var titleOpt = this.createParamOpt(request.title(), "title");
4646
var subjectOpt = this.createParamOpt(request.subject(), "subject");
47-
var paramsStr = List.of(authorOpt, titleOpt, subjectOpt).stream()
48-
.filter(Optional::isPresent).map(Optional::get).collect(Collectors.joining("&"));
49-
var urlStr =
50-
String.format("%s?%s&limit=%d", this.baseUrl, paramsStr, this.resultLimit);
47+
var paramsStr = List.of(authorOpt, titleOpt, subjectOpt).stream().flatMap(Optional::stream)
48+
.collect(Collectors.joining("&"));
49+
var urlStr = String.format("%s?%s&limit=%d", this.baseUrl, paramsStr, this.resultLimit);
5150
LOGGER.info(urlStr);
5251
var response = this.restClient.get().uri(urlStr).retrieve().body(Response.class);
5352
return response;
5453
}
5554

5655
private Optional<String> createParamOpt(String valueStr, String keyStr) {
5756
return Optional.ofNullable(valueStr).stream().filter(Predicate.not(String::isBlank))
58-
.map(myAuthor -> String.format("%s=%s", keyStr, URLEncoder.encode(myAuthor, StandardCharsets.UTF_8))).findFirst();
57+
.map(myAuthor -> String.format("%s=%s", keyStr, URLEncoder.encode(myAuthor, StandardCharsets.UTF_8)))
58+
.findFirst();
5959
}
6060
}

0 commit comments

Comments
 (0)