Docs: Write JavaDoc for components related to LOGIN command
This commit is contained in:
+20
@@ -2,23 +2,43 @@ package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.login;
|
|||||||
|
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.domain.user.User;
|
import ch.unibas.dmi.dbis.cs108.casono.server.domain.user.User;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.domain.user.UserFactory;
|
import ch.unibas.dmi.dbis.cs108.casono.server.domain.user.UserFactory;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.domain.user.UserId;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.domain.user.UserRegistry;
|
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.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.ErrorResponse;
|
||||||
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.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles {@link LoginRequest}s to create a user for a session, if the session has not assigned one
|
||||||
|
* already
|
||||||
|
*/
|
||||||
public class LoginHandler implements CommandHandler<LoginRequest> {
|
public class LoginHandler implements CommandHandler<LoginRequest> {
|
||||||
private final ResponseDispatcher responseDispatcher;
|
private final ResponseDispatcher responseDispatcher;
|
||||||
private final UserRegistry userRegistry;
|
private final UserRegistry userRegistry;
|
||||||
private final UserFactory userFactory;
|
private final UserFactory userFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new handler for checking for existing user and creating a new one
|
||||||
|
*
|
||||||
|
* @param responseDispatcher the dispatcher used to send the response
|
||||||
|
* @param userRegistry the registry used to look up existing users and create the new one
|
||||||
|
*/
|
||||||
public LoginHandler(ResponseDispatcher responseDispatcher, UserRegistry userRegistry) {
|
public LoginHandler(ResponseDispatcher responseDispatcher, UserRegistry userRegistry) {
|
||||||
this.responseDispatcher = responseDispatcher;
|
this.responseDispatcher = responseDispatcher;
|
||||||
this.userRegistry = userRegistry;
|
this.userRegistry = userRegistry;
|
||||||
this.userFactory = new UserFactory(userRegistry);
|
this.userFactory = new UserFactory(userRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the login request
|
||||||
|
*
|
||||||
|
* <p>If no user is already assigned to the session, a new user is created and its name and
|
||||||
|
* {@link UserId} returned in the response. If the session has already a user assigned, a {@code
|
||||||
|
* ALREADY_LOGGED_IN} error is responded with.
|
||||||
|
*
|
||||||
|
* @param request the request to execute
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute(LoginRequest request) {
|
public void execute(LoginRequest request) {
|
||||||
Optional<User> existingUser = userRegistry.getBySessionId(request.getSessionId());
|
Optional<User> existingUser = userRegistry.getBySessionId(request.getSessionId());
|
||||||
|
|||||||
+7
@@ -4,7 +4,14 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.command.parsing.CommandPar
|
|||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.PrimitiveRequest;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.PrimitiveRequest;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.accessor.RequestParameterAccessor;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.accessor.RequestParameterAccessor;
|
||||||
|
|
||||||
|
/** Parses a primitive request into a {@link LoginRequest}. */
|
||||||
public class LoginParser implements CommandParser<LoginRequest> {
|
public class LoginParser implements CommandParser<LoginRequest> {
|
||||||
|
/**
|
||||||
|
* Extracts the required {@code USERNAME} parameter from the incoming request.
|
||||||
|
*
|
||||||
|
* @param primitiveRequest the request to parse
|
||||||
|
* @return {@link LoginRequest} containing the username
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public LoginRequest parse(PrimitiveRequest primitiveRequest) {
|
public LoginRequest parse(PrimitiveRequest primitiveRequest) {
|
||||||
RequestParameterAccessor accessor =
|
RequestParameterAccessor accessor =
|
||||||
|
|||||||
+13
@@ -3,14 +3,27 @@ package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.login;
|
|||||||
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 create server-side user instance based on provided username */
|
||||||
public class LoginRequest extends Request {
|
public class LoginRequest extends Request {
|
||||||
private final String username;
|
private final String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new LoginRequest with the given context and desired username
|
||||||
|
*
|
||||||
|
* @param context the {@link RequestContext} containing information for responding to the
|
||||||
|
* request
|
||||||
|
* @param username the desired username when creating the user
|
||||||
|
*/
|
||||||
public LoginRequest(RequestContext context, String username) {
|
public LoginRequest(RequestContext context, String username) {
|
||||||
super(context);
|
super(context);
|
||||||
this.username = username;
|
this.username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the desired username requested for login
|
||||||
|
*
|
||||||
|
* @return the desired username
|
||||||
|
*/
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -5,7 +5,13 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestCo
|
|||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.SuccessResponse;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.SuccessResponse;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBodyBuilder;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBodyBuilder;
|
||||||
|
|
||||||
|
/** Response containing the assigned username and id of said user */
|
||||||
public class LoginResponse extends SuccessResponse {
|
public class LoginResponse extends SuccessResponse {
|
||||||
|
/**
|
||||||
|
* @param context the {@link RequestContext} associated with the request
|
||||||
|
* @param assignedUsername the assigned username to this user
|
||||||
|
* @param id of the created user
|
||||||
|
*/
|
||||||
public LoginResponse(RequestContext context, String assignedUsername, UserId id) {
|
public LoginResponse(RequestContext context, String assignedUsername, UserId id) {
|
||||||
super(
|
super(
|
||||||
context,
|
context,
|
||||||
|
|||||||
Reference in New Issue
Block a user