Include overall number of results and other data in entpoints for retrieving all entities
Former-commit-id: c4dee6362c
restapi
parent
38d541c18d
commit
1a2c3087e3
|
|
@ -23,9 +23,11 @@ import org.libreccm.core.api.IdentifierExtractor;
|
|||
import org.libreccm.core.api.JsonArrayCollector;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
|
|
@ -67,9 +69,6 @@ public class GroupsApi {
|
|||
@Inject
|
||||
private RoleRepository roleRepository;
|
||||
|
||||
@Inject
|
||||
private UserManager userManager;
|
||||
|
||||
@Inject
|
||||
private UserRepository userRepository;
|
||||
|
||||
|
|
@ -79,16 +78,27 @@ public class GroupsApi {
|
|||
@AuthorizationRequired
|
||||
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public JsonArray getGroups(
|
||||
public JsonObject getGroups(
|
||||
@QueryParam("limit") @DefaultValue("20") final int limit,
|
||||
@QueryParam("offset") @DefaultValue("0") final int offset
|
||||
) {
|
||||
return groupRepository
|
||||
.findAll(limit, offset)
|
||||
final long count = groupRepository.countAll();
|
||||
final List<Group> groups = groupRepository.findAll();
|
||||
|
||||
return Json
|
||||
.createObjectBuilder()
|
||||
.add("count", count)
|
||||
.add("limit", limit)
|
||||
.add("offset", offset)
|
||||
.add(
|
||||
"groups",
|
||||
groups
|
||||
.stream()
|
||||
.map(Group::buildJson)
|
||||
.map(JsonObjectBuilder::build)
|
||||
.collect(new JsonArrayCollector());
|
||||
.collect(new JsonArrayCollector())
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
@GET
|
||||
|
|
|
|||
|
|
@ -24,9 +24,11 @@ import org.libreccm.core.api.IdentifierExtractor;
|
|||
import org.libreccm.core.api.JsonArrayCollector;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
|
|
@ -90,16 +92,26 @@ public class UsersApi {
|
|||
@AuthorizationRequired
|
||||
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public JsonArray getUsers(
|
||||
public JsonObject getUsers(
|
||||
@QueryParam("limit") @DefaultValue("20") final int limit,
|
||||
@QueryParam("offset") @DefaultValue("0") final int offset
|
||||
) {
|
||||
return userRepository
|
||||
.findAll(limit, offset)
|
||||
final long count = userRepository.countAll();
|
||||
final List<User> users = userRepository.findAll(limit, offset);
|
||||
|
||||
return Json
|
||||
.createObjectBuilder()
|
||||
.add("count", count)
|
||||
.add("limit", limit)
|
||||
.add("offset", offset)
|
||||
.add(
|
||||
"users",
|
||||
users
|
||||
.stream()
|
||||
.map(User::buildJson)
|
||||
.map(JsonObjectBuilder::build)
|
||||
.collect(new JsonArrayCollector());
|
||||
.map(User::toJson)
|
||||
.collect(new JsonArrayCollector())
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -278,6 +290,7 @@ public class UsersApi {
|
|||
* Deletes a user.
|
||||
*
|
||||
* @param userIdentifier The identifier of the user to delete.
|
||||
*
|
||||
* @return A 200 (OK) response if the user was deleted successfully.
|
||||
*/
|
||||
@DELETE
|
||||
|
|
|
|||
Loading…
Reference in New Issue