Add V2 API for counting total datasets (#938)

This commit is contained in:
Yi (Alan) Wang 2018-01-18 10:53:00 -08:00 committed by GitHub
parent e25ae33d40
commit 675a8e0f68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -17,6 +17,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.persistence.EntityManagerFactory;
import lombok.extern.slf4j.Slf4j;
import wherehows.dao.table.DictDatasetDao;
@ -95,7 +96,7 @@ public class DatasetViewDao extends BaseViewDao {
return view;
}
public PagedCollection<DatasetView> listDatasets(@Nonnull String platform, @Nonnull String prefix, int start,
public PagedCollection<DatasetView> listDatasets(@Nullable String platform, @Nonnull String prefix, int start,
int count) throws Exception {
throw new RuntimeException("Not implemented yet");
}

View File

@ -80,6 +80,19 @@ public class Dataset extends Controller {
}
}
public static Promise<Result> totalDatasets() {
try {
String platform = request().getQueryString("platform");
String prefix = StringUtils.defaultIfBlank(request().getQueryString("prefix"), "");
return Promise.promise(
() -> ok(String.valueOf(DATASET_VIEW_DAO.listDatasets(platform, prefix, 0, 1).getTotal())));
} catch (Exception e) {
Logger.error("Fail to count total datasets", e);
return Promise.promise(() -> internalServerError("Fetch data Error: " + e.toString()));
}
}
public static Promise<Result> getComplianceDataTypes() {
try {
return Promise.promise(() -> ok(

View File

@ -270,6 +270,12 @@ GET /api/v2/dataset/listNames
GET /api/v2/dataset/listDatasets controllers.api.v2.Dataset.listDatasets()
GET /api/v2/dataset/totalDatasets controllers.api.v2.Dataset.totalDatasets()
GET /api/v2/list/platforms controllers.api.v2.Dataset.getDataPlatforms()
GET /api/v2/list/complianceDataTypes controllers.api.v2.Dataset.getComplianceDataTypes()
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)