Docs: add get-lobby-status javadoc
This commit is contained in:
+21
-2
@@ -8,7 +8,14 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.ErrorRes
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher;
|
||||
import java.util.Optional;
|
||||
|
||||
/** Handler for GET_LOBBY_STATUS: returns lobby details and player list. */
|
||||
/**
|
||||
* Handler for the `GET_LOBBY_STATUS` command.
|
||||
*
|
||||
* <p>Resolves the target lobby either by the optional `ID` parameter or by `USERNAME`. If both are
|
||||
* omitted the handler requires the session to be associated with a logged-in user (see the inline
|
||||
* pre-execution check). On success a {@link GetLobbyStatusResponse} is dispatched, otherwise an
|
||||
* {@link ErrorResponse} with code `LOBBY_NOT_FOUND` is sent.
|
||||
*/
|
||||
public class GetLobbyStatusHandler extends CommandHandler<GetLobbyStatusRequest> {
|
||||
private final LobbyManager lobbyManager;
|
||||
private final UserRegistry userRegistry;
|
||||
@@ -46,10 +53,22 @@ public class GetLobbyStatusHandler extends CommandHandler<GetLobbyStatusRequest>
|
||||
|
||||
@Override
|
||||
public void execute(GetLobbyStatusRequest request) {
|
||||
// Resolve username from request or session when no explicit ID/USERNAME
|
||||
// provided
|
||||
String targetUsername = request.getUsername();
|
||||
if (targetUsername == null) {
|
||||
var maybeUser = userRegistry.getBySessionId(request.getSessionId());
|
||||
if (maybeUser.isPresent()) {
|
||||
targetUsername = maybeUser.get().getName();
|
||||
}
|
||||
}
|
||||
|
||||
var lobby =
|
||||
(request.getId() != null)
|
||||
? lobbyManager.getLobby(LobbyId.of(request.getId()))
|
||||
: lobbyManager.getLobbyByUsername(request.getUsername());
|
||||
: (targetUsername != null
|
||||
? lobbyManager.getLobbyByUsername(targetUsername)
|
||||
: null);
|
||||
|
||||
if (lobby == null) {
|
||||
responseDispatcher.dispatch(
|
||||
|
||||
+15
@@ -5,6 +5,21 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.Primitive
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.accessor.RequestParameterAccessor;
|
||||
|
||||
public class GetLobbyStatusParser implements CommandParser<GetLobbyStatusRequest> {
|
||||
/**
|
||||
* Parse the incoming primitive request into a {@link GetLobbyStatusRequest}.
|
||||
*
|
||||
* <p>Supported optional parameters:
|
||||
*
|
||||
* <ul>
|
||||
* <li>`ID` (int) — numeric lobby id to query
|
||||
* <li>`USERNAME` (String) — username to lookup the lobby for
|
||||
* </ul>
|
||||
*
|
||||
* If both are omitted the handler may require a logged-in session.
|
||||
*
|
||||
* @param primitiveRequest raw request containing parameters and context
|
||||
* @return parsed {@link GetLobbyStatusRequest}
|
||||
*/
|
||||
@Override
|
||||
public GetLobbyStatusRequest parse(PrimitiveRequest primitiveRequest) {
|
||||
RequestParameterAccessor accessor =
|
||||
|
||||
+9
@@ -7,16 +7,25 @@ public class GetLobbyStatusRequest extends Request {
|
||||
private final Integer id;
|
||||
private final String username;
|
||||
|
||||
/**
|
||||
* Create a new GetLobbyStatusRequest.
|
||||
*
|
||||
* @param context request context (session id, source, etc.)
|
||||
* @param id optional numeric lobby id to query, or null
|
||||
* @param username optional username to query the lobby for, or null
|
||||
*/
|
||||
public GetLobbyStatusRequest(RequestContext context, Integer id, String username) {
|
||||
super(context);
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/** Returns the optional lobby id. */
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/** Returns the optional username. */
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
+12
-1
@@ -5,8 +5,19 @@ 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.ResponseBody;
|
||||
|
||||
/** Response with lobby player listing and simple READY placeholders. */
|
||||
/**
|
||||
* Success response for `GET_LOBBY_STATUS`.
|
||||
*
|
||||
* <p>Builds a response with a single `LOBBY` block containing `ID`, `NAME` and a nested `PLAYERS`
|
||||
* collection with repeated `PLAYER` blocks (`USERNAME`, `READY`).
|
||||
*/
|
||||
public class GetLobbyStatusResponse extends SuccessResponse {
|
||||
/**
|
||||
* Create a new response for the provided {@link Lobby}.
|
||||
*
|
||||
* @param context request context to use for the response
|
||||
* @param lobby lobby domain object containing id, name and players
|
||||
*/
|
||||
public GetLobbyStatusResponse(RequestContext context, Lobby lobby) {
|
||||
super(
|
||||
context,
|
||||
|
||||
Reference in New Issue
Block a user