Merge "Add option 'S' to projects REST API to support query offset"
This commit is contained in:
@@ -92,6 +92,22 @@ List all projects that start with `platform/`:
|
||||
----
|
||||
E.g. this feature can be used by suggestion client UI's to limit results.
|
||||
|
||||
The `/projects/` URL also accepts a limit integer in the `n` parameter.
|
||||
This limits the results to show `n` projects.
|
||||
|
||||
Query the first 25 projects in project list.
|
||||
----
|
||||
GET /projects/?n=25 HTTP/1.0
|
||||
----
|
||||
|
||||
The `/projects/` URL also accepts a start integer in the `S` parameter.
|
||||
The results will skip `S` projects from project list.
|
||||
|
||||
Query 25 projects starting from index 50.
|
||||
----
|
||||
GET /projects/?n=25&S=50 HTTP/1.0
|
||||
----
|
||||
|
||||
[[get-project]]
|
||||
=== Get Project
|
||||
--
|
||||
|
||||
@@ -144,6 +144,11 @@ public class ListProjects implements RestReadView<TopLevelResource> {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
@Option(name = "-S", metaVar = "CNT", usage = "number of projects to skip")
|
||||
public void setStart(int start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
@Option(name = "-p", metaVar = "PREFIX", usage = "match project prefix")
|
||||
public void setMatchPrefix(String matchPrefix) {
|
||||
this.matchPrefix = matchPrefix;
|
||||
@@ -166,6 +171,7 @@ public class ListProjects implements RestReadView<TopLevelResource> {
|
||||
private boolean showDescription;
|
||||
private boolean all;
|
||||
private int limit;
|
||||
private int start;
|
||||
private String matchPrefix;
|
||||
private String matchSubstring;
|
||||
private AccountGroup.UUID groupUuid;
|
||||
@@ -231,6 +237,7 @@ public class ListProjects implements RestReadView<TopLevelResource> {
|
||||
}
|
||||
}
|
||||
|
||||
int foundIndex = 0;
|
||||
int found = 0;
|
||||
Map<String, ProjectInfo> output = Maps.newTreeMap();
|
||||
Map<String, String> hiddenNames = Maps.newHashMap();
|
||||
@@ -363,6 +370,10 @@ public class ListProjects implements RestReadView<TopLevelResource> {
|
||||
}
|
||||
}
|
||||
|
||||
if (foundIndex++ < start) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (limit > 0 && ++found > limit) {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user