forked from Qortal/qortal
API call for lists #1
@@ -8,12 +8,15 @@ import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.qortal.api.ApiError;
|
||||
import org.qortal.api.ApiErrors;
|
||||
import org.qortal.api.ApiExceptionFactory;
|
||||
import org.qortal.api.Security;
|
||||
import org.qortal.api.model.ListRequest;
|
||||
import org.qortal.list.ResourceListManager;
|
||||
import org.qortal.settings.Settings;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.*;
|
||||
@@ -28,6 +31,47 @@ public class ListsResource {
|
||||
@Context
|
||||
HttpServletRequest request;
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Operation(
|
||||
summary = "Fetch all lists and items",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "A JSON object whose keys are list names and values are the arrays of items in each list",
|
||||
content = @Content(
|
||||
mediaType = MediaType.APPLICATION_JSON,
|
||||
schema = @Schema(implementation = Object.class)
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
@SecurityRequirement(name = "apiKey")
|
||||
public String getAllLists(@HeaderParam(Security.API_KEY_HEADER) String apiKey) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
JSONObject allLists = new JSONObject();
|
||||
|
||||
String listsPath = Settings.getInstance().getListsPath();
|
||||
java.io.File dir = new java.io.File(listsPath);
|
||||
String[] files = dir.list();
|
||||
|
||||
if (files != null) {
|
||||
for (String fileName : files) {
|
||||
if (!fileName.endsWith(".json"))
|
||||
continue;
|
||||
|
||||
String listName = fileName.substring(0, fileName.length() - 5);
|
||||
|
||||
String listJson = ResourceListManager.getInstance().getJSONStringForList(listName);
|
||||
if (listJson == null)
|
||||
continue;
|
||||
|
||||
allLists.put(listName, new JSONArray(listJson));
|
||||
}
|
||||
}
|
||||
|
||||
return allLists.toString();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/{listName}")
|
||||
|
||||
Reference in New Issue
Block a user