Merge "Add option 'S' to projects REST API to support query offset"

This commit is contained in:
Shawn Pearce
2014-04-03 04:46:58 +00:00
committed by Gerrit Code Review
2 changed files with 27 additions and 0 deletions

View File

@@ -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
--

View File

@@ -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;
}