|
1 | 1 | package io.weaviate.client6.v1.api.backup; |
2 | 2 |
|
3 | | -import java.util.Collections; |
| 3 | +import java.util.HashMap; |
4 | 4 | import java.util.List; |
| 5 | +import java.util.function.Function; |
5 | 6 |
|
6 | 7 | import com.google.gson.reflect.TypeToken; |
7 | 8 |
|
| 9 | +import io.weaviate.client6.v1.internal.ObjectBuilder; |
8 | 10 | import io.weaviate.client6.v1.internal.json.JSON; |
9 | 11 | import io.weaviate.client6.v1.internal.rest.Endpoint; |
10 | 12 | import io.weaviate.client6.v1.internal.rest.SimpleEndpoint; |
11 | 13 |
|
12 | | -public record ListBackupsRequest(String backend) { |
| 14 | +public record ListBackupsRequest(String backend, boolean startingTimeAsc) { |
13 | 15 |
|
14 | 16 | @SuppressWarnings("unchecked") |
15 | 17 | public static Endpoint<ListBackupsRequest, List<Backup>> _ENDPOINT = SimpleEndpoint.noBody( |
16 | 18 | request -> "GET", |
17 | 19 | request -> "/backups/" + request.backend, |
18 | | - request -> Collections.emptyMap(), |
| 20 | + request -> new HashMap<>() { |
| 21 | + { |
| 22 | + if (request.startingTimeAsc) { |
| 23 | + put("order", "asc"); |
| 24 | + } |
| 25 | + } |
| 26 | + }, |
19 | 27 | (statusCode, response) -> (List<Backup>) JSON.deserialize( |
20 | 28 | response, TypeToken.getParameterized(List.class, Backup.class))); |
| 29 | + |
| 30 | + public static ListBackupsRequest of(String backend) { |
| 31 | + return of(backend, ObjectBuilder.identity()); |
| 32 | + } |
| 33 | + |
| 34 | + public static ListBackupsRequest of(String backend, Function<Builder, ObjectBuilder<ListBackupsRequest>> fn) { |
| 35 | + return fn.apply(new Builder(backend)).build(); |
| 36 | + } |
| 37 | + |
| 38 | + public ListBackupsRequest(Builder builder) { |
| 39 | + this(builder.backend, builder.startingTimeAsc); |
| 40 | + } |
| 41 | + |
| 42 | + public static class Builder implements ObjectBuilder<ListBackupsRequest> { |
| 43 | + private final String backend; |
| 44 | + private boolean startingTimeAsc = false; |
| 45 | + |
| 46 | + public Builder(String backend) { |
| 47 | + this.backend = backend; |
| 48 | + } |
| 49 | + |
| 50 | + /** Sort the backups by their starting time, oldest to newest. */ |
| 51 | + public Builder sortByStartingTimeAsc(boolean enable) { |
| 52 | + this.startingTimeAsc = enable; |
| 53 | + return this; |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public ListBackupsRequest build() { |
| 58 | + return new ListBackupsRequest(this); |
| 59 | + } |
| 60 | + } |
21 | 61 | } |
0 commit comments