Add serverside LOGOUT command #239
+15
@@ -2,18 +2,33 @@ package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.logout;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.domain.user.UserRegistry;
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.command.execution.CommandHandler;
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.ErrorResponse;
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.OkResponse;
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher;
|
||||
|
||||
/** Handles {@link LogoutRequest} to logout connected user. */
|
||||
public class LogoutHandler implements CommandHandler<LogoutRequest> {
|
||||
private final ResponseDispatcher responseDispatcher;
|
||||
private final UserRegistry userRegistry;
|
||||
|
||||
/**
|
||||
* Creates a new logout handler to logout user.
|
||||
*
|
||||
* @param responseDispatcher dispatcher used to send the logout result back to the client
|
||||
* @param userRegistry registry responsible for tracking connected user sessions
|
||||
*/
|
||||
public LogoutHandler(ResponseDispatcher responseDispatcher, UserRegistry userRegistry) {
|
||||
this.responseDispatcher = responseDispatcher;
|
||||
this.userRegistry = userRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the logout request for the given request.
|
||||
*
|
||||
* <p>The user is removed from the {@link UserRegistry}.
|
||||
*
|
||||
* @param request the request to execute
|
||||
*/
|
||||
@Override
|
||||
public void execute(LogoutRequest request) {
|
||||
boolean was_removed = userRegistry.removeBySessionId(request.getSessionId());
|
||||
|
||||
+8
@@ -3,7 +3,15 @@ package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.logout;
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.command.parsing.CommandParser;
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.PrimitiveRequest;
|
||||
|
||||
/** Parses a primitive request into a {@link LogoutRequest}. */
|
||||
public class LogoutParser implements CommandParser<LogoutRequest> {
|
||||
|
||||
/**
|
||||
* Parses a primitive request into a LogoutRequest.
|
||||
*
|
||||
* @param primitiveRequest the request to parse
|
||||
* @return the created {@link LogoutRequest}
|
||||
*/
|
||||
@Override
|
||||
public LogoutRequest parse(PrimitiveRequest primitiveRequest) {
|
||||
return new LogoutRequest(primitiveRequest.context());
|
||||
|
||||
+8
@@ -3,7 +3,15 @@ package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.logout;
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.Request;
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestContext;
|
||||
|
||||
/** Request implementation used to logout a currently logged in user */
|
||||
public class LogoutRequest extends Request {
|
||||
|
||||
/**
|
||||
* Constructs a new LogoutRequest with the given context.
|
||||
*
|
||||
* @param context the {@link RequestContext} containing information for responding to the
|
||||
* request
|
||||
*/
|
||||
public LogoutRequest(RequestContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user