Docs: Write JavaDoc for components related to LOGIN command

This commit is contained in:
Lars Simon Winzer
2026-04-07 20:12:22 +02:00
parent 06c5e5ab83
commit 160ad8f2bb
4 changed files with 46 additions and 0 deletions
@@ -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.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.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.dispatcher.ResponseDispatcher;
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> {
private final ResponseDispatcher responseDispatcher;
private final UserRegistry userRegistry;
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) {
this.responseDispatcher = responseDispatcher;
this.userRegistry = 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
public void execute(LoginRequest request) {
Optional<User> existingUser = userRegistry.getBySessionId(request.getSessionId());
@@ -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.accessor.RequestParameterAccessor;
/** Parses a primitive request into a {@link 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
public LoginRequest parse(PrimitiveRequest primitiveRequest) {
RequestParameterAccessor accessor =
@@ -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.RequestContext;
/** Request implementation used to create server-side user instance based on provided username */
public class LoginRequest extends Request {
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) {
super(context);
this.username = username;
}
/**
* Returns the desired username requested for login
*
* @return the desired username
*/
public String getUsername() {
return username;
}
@@ -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.builder.ResponseBodyBuilder;
/** Response containing the assigned username and id of said user */
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) {
super(
context,