Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question loading refactor #544

Merged
merged 6 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/main/java/uk/ac/cam/cl/dtg/isaac/api/GameboardsFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
import uk.ac.cam.cl.dtg.isaac.api.managers.NoWildcardException;
import uk.ac.cam.cl.dtg.isaac.dos.GameboardCreationMethod;
import uk.ac.cam.cl.dtg.isaac.dos.IsaacWildcard;
import uk.ac.cam.cl.dtg.isaac.dos.LightweightQuestionValidationResponse;
import uk.ac.cam.cl.dtg.isaac.dto.GameboardDTO;
import uk.ac.cam.cl.dtg.isaac.dto.GameboardItem;
import uk.ac.cam.cl.dtg.isaac.dto.GameboardListDTO;
import uk.ac.cam.cl.dtg.isaac.dto.users.AnonymousUserDTO;
import uk.ac.cam.cl.dtg.segue.api.managers.QuestionManager;
import uk.ac.cam.cl.dtg.segue.api.managers.UserAccountManager;
import uk.ac.cam.cl.dtg.segue.api.managers.UserAssociationManager;
Expand Down Expand Up @@ -67,6 +69,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.google.common.collect.Maps.immutableEntry;
import static uk.ac.cam.cl.dtg.isaac.api.Constants.*;
Expand Down Expand Up @@ -239,15 +242,22 @@ public final Response getGameboard(@Context final Request request,
GameboardDTO gameboard;

AbstractSegueUserDTO randomUser = this.userManager.getCurrentUser(httpServletRequest);
Map<String, Map<String, List<QuestionValidationResponse>>> userQuestionAttempts = this.questionManager
.getQuestionAttemptsByUser(randomUser);

GameboardDTO unAugmentedGameboard = gameManager.getGameboard(gameboardId);
if (null == unAugmentedGameboard) {
return new SegueErrorResponse(Status.NOT_FOUND, "No Gameboard found for the id specified.")
.toResponse();
}

Map<String, ? extends Map<String, ? extends List<? extends LightweightQuestionValidationResponse>>> userQuestionAttempts;

if (randomUser instanceof AnonymousUserDTO) {
userQuestionAttempts = this.questionManager.getQuestionAttemptsByUser(randomUser);
} else {
List<String> gameboardPageIds = unAugmentedGameboard.getContents().stream().map(GameboardItem::getId).collect(Collectors.toList());
userQuestionAttempts = this.questionManager.getMatchingQuestionAttempts((RegisteredUserDTO) randomUser, gameboardPageIds);
}

// Calculate the ETag
EntityTag etag = new EntityTag(unAugmentedGameboard.toString().hashCode()
+ userQuestionAttempts.toString().hashCode() + "");
Expand Down
Loading