Skip to content

Commit

Permalink
Korjattu hakukohteiden search-rajapintaa
Browse files Browse the repository at this point in the history
  • Loading branch information
augustk committed Dec 10, 2024
1 parent 98a69a4 commit 5ae532b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public HttpClient(java.net.http.HttpClient client, Gson gson) {
this.gson = gson;
}

public CompletableFuture<String> getString(String url, Duration timeout) {
HttpRequest request =
buildWithCallerIdAndCsrfHeaders(HttpRequest.newBuilder(URI.create(url)))
.header("Accept", "application/json")
.GET()
.timeout(timeout)
.build();
return this.makeRequest(request, null)
.thenApply(this::parseTxt);
}

public <O> CompletableFuture<O> getJson(String url, Duration timeout, Type outputType) {
return this.getJson(url, timeout, outputType, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

@RestController("TarjontaServiceResource")
@RequestMapping("/resources/tarjonta-service")
// @PreAuthorize("isAuthenticated()")
@Tag(
name = "/tarjonta-service",
description = "Proxy-rajapinnat vanhan tarjonnan tietojen hakemiseen")
Expand Down Expand Up @@ -135,11 +134,11 @@ public CompletableFuture<ResultV1RDTO<List<HakuV1RDTO>>> find(
new com.google.gson.reflect.TypeToken<ResultV1RDTO<List<HakuV1RDTO>>>() {}.getType());
}

@GetMapping(value = "/search", produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
@GetMapping(value = "/rest/v1/hakukohde/search", produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
@Operation(
summary = "Palauttaa listan hakukohteista annetuilla parametreilla",
description = "Palauttaa listan hakukohteista annetuilla parametreilla.")
public CompletableFuture<ResultV1RDTO<HakutuloksetV1RDTO<HakukohdeHakutulosV1RDTO>>> search(
public CompletableFuture<String> search(
@RequestParam(value = "searchTerms", required = false) String searchTerms,
@RequestParam(value = "hakukohteenNimiUri", required = false) String hakukohteenNimiUri,
@RequestParam(value = "organisationOid", required = false) List<String> organisationOids,
Expand Down Expand Up @@ -198,10 +197,8 @@ public CompletableFuture<ResultV1RDTO<HakutuloksetV1RDTO<HakukohdeHakutulosV1RDT
.toUri()
.getQuery();

return this.tarjontaClient.<ResultV1RDTO<HakutuloksetV1RDTO<HakukohdeHakutulosV1RDTO>>>getJson(
return this.tarjontaClient.getString(
urlConfiguration.url("tarjonta-service.hakukohde.search") + "?" + queryString,
Duration.ofMinutes(5),
new com.google.gson.reflect.TypeToken<
ResultV1RDTO<HakutuloksetV1RDTO<HakukohdeHakutulosV1RDTO>>>() {}.getType());
Duration.ofMinutes(5));
}
}

0 comments on commit 5ae532b

Please sign in to comment.