feat: Add API to get template filters (#12969)

Adds a new API to get available filters for application templates from Appsmith cloud services. It acts as a proxy to the API.
This commit is contained in:
Nayan 2022-04-21 15:52:27 +06:00 committed by GitHub
parent d14d8d356e
commit 15394207a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

View File

@ -40,6 +40,12 @@ public class ApplicationTemplateControllerCE {
.map(templates -> new ResponseDTO<>(HttpStatus.OK.value(), templates, null));
}
@GetMapping("filters")
public Mono<ResponseDTO<ApplicationTemplate>> getFilters() {
return applicationTemplateService.getFilters()
.map(filters -> new ResponseDTO<>(HttpStatus.OK.value(), filters, null));
}
@PostMapping("{templateId}/import/{organizationId}")
public Mono<ResponseDTO<Application>> importApplicationFromTemplate(@PathVariable String templateId,
@PathVariable String organizationId) {

View File

@ -10,4 +10,5 @@ public interface ApplicationTemplateServiceCE {
Flux<ApplicationTemplate> getSimilarTemplates(String templateId);
Mono<ApplicationTemplate> getTemplateDetails(String templateId);
Mono<Application> importApplicationFromTemplate(String templateId, String organizationId);
Mono<ApplicationTemplate> getFilters();
}

View File

@ -137,6 +137,24 @@ public class ApplicationTemplateServiceCEImpl implements ApplicationTemplateServ
});
}
@Override
public Mono<ApplicationTemplate> getFilters() {
final String baseUrl = cloudServicesConfig.getBaseUrl();
return WebClient
.create(baseUrl + "/api/v1/app-templates/filters")
.get()
.exchangeToMono(clientResponse -> {
if (clientResponse.statusCode().equals(HttpStatus.OK)) {
return clientResponse.bodyToMono(ApplicationTemplate.class);
} else if (clientResponse.statusCode().isError()) {
return Mono.error(new AppsmithException(AppsmithError.CLOUD_SERVICES_ERROR, clientResponse.statusCode()));
} else {
return clientResponse.createException().flatMap(Mono::error);
}
});
}
public static class NoEncodingUriBuilderFactory extends DefaultUriBuilderFactory {
public NoEncodingUriBuilderFactory(String baseUriTemplate) {
super(UriComponentsBuilder.fromHttpUrl(baseUriTemplate));