Skip to content

Commit

Permalink
skrrrrrt
Browse files Browse the repository at this point in the history
  • Loading branch information
GodCipher committed Oct 2, 2023
1 parent 7644441 commit f6450c5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,27 @@ public DatabaseResult<Integer> getIdForRegion(String region) {
}
}

public DatabaseResult<String[]> getAllMaps() {
try(Connection connection = DATA_SOURCE.getConnection()) {
try (Statement statement = connection.createStatement()) {
ResultSet resultSet = statement.executeQuery("SELECT mapName FROM MapInfo");
List<String> maps = new ArrayList<>();
while(resultSet.next()) {
maps.add(resultSet.getString(1));
}
return new DatabaseResult<>(maps.toArray(new String[0]), null, DatabaseResult.DatabaseResultType.SUCCESS);
} catch (SQLException e) {
Webservice.DATABASE_LOGGER.log(Level.SEVERE, "Could not get maps", e);
return new DatabaseResult<>(null, "Could not get maps: " + e.getMessage(),
DatabaseResult.DatabaseResultType.ERROR);
}
} catch (SQLException e) {
Webservice.DATABASE_LOGGER.log(Level.SEVERE, "Error getting connection", e);
return new DatabaseResult<>(null, "Error getting connection: " + e.getMessage(),
DatabaseResult.DatabaseResultType.ERROR);
}
}

public DatabaseResult<Integer> getIdForMap(String mapName) {
try(Connection connection = DATA_SOURCE.getConnection()) {
int id = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public DatabaseResult<Void> saveGameData(GameDto gameDto) {

return gameInfoResult;
}

public String[] getAllMaps() {
return database.getAllMaps().getResult().orElse(new String[0]);
}

/**
* This method checks if the given matchIds are already in the database and returns the ones that are not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ApplicationAccessPoint {
public static final String DEBUG = API_KEY + "/debug"; // /{apiKey}/debug
public static final String LATEST_LOG_DOWNLOAD = "/latestlog"; // /{apiKey}/debug/latestlog
public static final String FREE_MATCH_IDS = "/freematchids"; // /{apiKey}/debug/freematchids
public static final String ALL_MAPS = "/allmaps"; // /{apiKey}/debug/allmaps

// game - main paths
public static final String GAME = API_KEY + "/game"; // /{apiKey}/game
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,23 @@ public ResponseEntity<byte[]> downloadLatestLog(@PathVariable String apiKey, Htt
Webservice.REST_LOGGER.severe("Could not find latest log file.");
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}

@GetMapping(ApplicationAccessPoint.ALL_MAPS)
@ResponseStatus(HttpStatus.OK)
public DeferredResult<?> getAllMaps(@PathVariable String apiKey) {
if(couldNotVerifyApiKey(apiKey)) {
Webservice.REST_LOGGER.info("Received unauthorized request to get all maps.");

DeferredResult<Object> result = new DeferredResult<>();
result.setResult(new ResponseEntity<>(HttpStatus.UNAUTHORIZED));
return result;
}

DeferredResult<ResponseEntity<?>> result = new DeferredResult<>();
TaskForce1.order(() -> timing(
() -> result.setResult(new ResponseEntity<>(gameDao.getAllMaps(),
HttpStatus.OK)),
"All maps have been requested."));
return result;
}
}

0 comments on commit f6450c5

Please sign in to comment.