Add serverside LIST_USERS command #246
+18
@@ -6,14 +6,32 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.command.execution.CommandH
|
|||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles {@link ListUsersRequest}s by retrieving all users from the {@link UserRegistry} and
|
||||||
|
* dispatching a {@link ListUsersResponse} containing the list of users.
|
||||||
|
*/
|
||||||
public class ListUsersHandler extends CommandHandler<ListUsersRequest> {
|
public class ListUsersHandler extends CommandHandler<ListUsersRequest> {
|
||||||
private final UserRegistry userRegistry;
|
private final UserRegistry userRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new handler for listing all users
|
||||||
|
*
|
||||||
|
* @param responseDispatcher the dispatcher used to send the response
|
||||||
|
* @param userRegistry the registry used to look up existing users
|
||||||
|
*/
|
||||||
public ListUsersHandler(ResponseDispatcher responseDispatcher, UserRegistry userRegistry) {
|
public ListUsersHandler(ResponseDispatcher responseDispatcher, UserRegistry userRegistry) {
|
||||||
super(responseDispatcher);
|
super(responseDispatcher);
|
||||||
this.userRegistry = userRegistry;
|
this.userRegistry = userRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the list users request
|
||||||
|
*
|
||||||
|
* <p>All users are retrieved from the {@link UserRegistry} and returned in a {@link
|
||||||
|
* ListUsersResponse}.
|
||||||
|
*
|
||||||
|
* @param request the request to execute
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute(ListUsersRequest request) {
|
public void execute(ListUsersRequest request) {
|
||||||
Collection<User> users = userRegistry.getAllUsers();
|
Collection<User> users = userRegistry.getAllUsers();
|
||||||
|
|||||||
+7
@@ -3,7 +3,14 @@ package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.list_users;
|
|||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.command.parsing.CommandParser;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.command.parsing.CommandParser;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.PrimitiveRequest;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.PrimitiveRequest;
|
||||||
|
|
||||||
|
/** Parses a primitive request into a {@link ListUsersRequest}. */
|
||||||
public class ListUsersParser implements CommandParser<ListUsersRequest> {
|
public class ListUsersParser implements CommandParser<ListUsersRequest> {
|
||||||
|
/**
|
||||||
|
* Parses a primitive request into a ListUsersRequest.
|
||||||
|
*
|
||||||
|
* @param primitiveRequest the request to parse
|
||||||
|
* @return the created {@link ListUsersRequest}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ListUsersRequest parse(PrimitiveRequest primitiveRequest) {
|
public ListUsersRequest parse(PrimitiveRequest primitiveRequest) {
|
||||||
return new ListUsersRequest(primitiveRequest.context());
|
return new ListUsersRequest(primitiveRequest.context());
|
||||||
|
|||||||
+7
@@ -3,7 +3,14 @@ package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.list_users;
|
|||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.Request;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.Request;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestContext;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestContext;
|
||||||
|
|
||||||
|
/** Request implementation used to retrieve all existing users from the server. */
|
||||||
public class ListUsersRequest extends Request {
|
public class ListUsersRequest extends Request {
|
||||||
|
/**
|
||||||
|
* Constructs a new ListUsersRequest with the given context
|
||||||
|
*
|
||||||
|
* @param context the {@link RequestContext} containing information for responding to the
|
||||||
|
* request
|
||||||
|
*/
|
||||||
public ListUsersRequest(RequestContext context) {
|
public ListUsersRequest(RequestContext context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -6,7 +6,14 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.SuccessR
|
|||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBody;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBody;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/** Response containing a list of all active users on the server */
|
||||||
public class ListUsersResponse extends SuccessResponse {
|
public class ListUsersResponse extends SuccessResponse {
|
||||||
|
/**
|
||||||
|
* Creates a new ListUsersResponse containing the given list of users
|
||||||
|
*
|
||||||
|
* @param context the {@link RequestContext} associated with the request
|
||||||
|
* @param users the collection of users currently active on the server
|
||||||
|
*/
|
||||||
public ListUsersResponse(RequestContext context, Collection<User> users) {
|
public ListUsersResponse(RequestContext context, Collection<User> users) {
|
||||||
super(
|
super(
|
||||||
context,
|
context,
|
||||||
|
|||||||
Reference in New Issue
Block a user