forked from Qortal/qortal
Return statuses in GET /arbitrary/resources endpoint when the "includestatus" parameter is true.
This commit is contained in:
parent
1be8a059f4
commit
8cb06bf451
@ -84,6 +84,7 @@ public class AdminResource {
|
||||
@Parameter(in = ParameterIn.QUERY, name = "limit", description = "Maximum number of entries to return, 0 means unlimited", schema = @Schema(type = "integer", defaultValue = "20"))
|
||||
@Parameter(in = ParameterIn.QUERY, name = "offset", description = "Starting entry in results, 0 is first entry", schema = @Schema(type = "integer"))
|
||||
@Parameter(in = ParameterIn.QUERY, name = "reverse", description = "Reverse results", schema = @Schema(type = "boolean"))
|
||||
@Parameter(in = ParameterIn.QUERY, name = "includestatus", description = "Include status", schema = @Schema(type = "boolean"))
|
||||
public String globalParameters() {
|
||||
return "";
|
||||
}
|
||||
|
@ -81,7 +81,9 @@ public class ArbitraryResource {
|
||||
ref = "offset"
|
||||
) @QueryParam("offset") Integer offset, @Parameter(
|
||||
ref = "reverse"
|
||||
) @QueryParam("reverse") Boolean reverse) {
|
||||
) @QueryParam("reverse") Boolean reverse, @Parameter(
|
||||
ref = "includestatus"
|
||||
) @QueryParam("includestatus") Boolean includeStatus) {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
|
||||
List<ArbitraryResourceInfo> resources = repository.getArbitraryRepository()
|
||||
@ -90,7 +92,23 @@ public class ArbitraryResource {
|
||||
if (resources == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
if (includeStatus == null || includeStatus == false) {
|
||||
return resources;
|
||||
}
|
||||
|
||||
// Determine and add the status of each resource
|
||||
List<ArbitraryResourceInfo> updatedResources = new ArrayList<>();
|
||||
for (ArbitraryResourceInfo resourceInfo : resources) {
|
||||
ArbitraryDataResource resource = new ArbitraryDataResource(resourceInfo.name, ResourceIdType.NAME,
|
||||
resourceInfo.service, resourceInfo.identifier);
|
||||
ArbitraryResourceSummary summary = resource.getSummary();
|
||||
if (summary != null) {
|
||||
resourceInfo.status = summary.status;
|
||||
}
|
||||
updatedResources.add(resourceInfo);
|
||||
}
|
||||
return updatedResources;
|
||||
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.qortal.data.arbitrary;
|
||||
|
||||
import org.qortal.api.model.ArbitraryResourceSummary.ArbitraryResourceStatus;
|
||||
import org.qortal.arbitrary.misc.Service;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
@ -11,6 +12,7 @@ public class ArbitraryResourceInfo {
|
||||
public String name;
|
||||
public Service service;
|
||||
public String identifier;
|
||||
public ArbitraryResourceStatus status;
|
||||
|
||||
public ArbitraryResourceInfo() {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user