Temp to get Xavier changes
This commit is contained in:
parent
5926d1d245
commit
7bc013bb46
2 changed files with 24 additions and 1 deletions
|
@ -26,6 +26,7 @@ import org.jose4j.jwt.consumer.JwtConsumerBuilder;
|
||||||
import org.jose4j.lang.JoseException;
|
import org.jose4j.lang.JoseException;
|
||||||
|
|
||||||
import be.jeffcheasey88.peeratcode.repository.DatabaseRepository;
|
import be.jeffcheasey88.peeratcode.repository.DatabaseRepository;
|
||||||
|
import be.jeffcheasey88.peeratcode.routes.BadgeDetails;
|
||||||
import be.jeffcheasey88.peeratcode.routes.ChapterElement;
|
import be.jeffcheasey88.peeratcode.routes.ChapterElement;
|
||||||
import be.jeffcheasey88.peeratcode.routes.ChapterList;
|
import be.jeffcheasey88.peeratcode.routes.ChapterList;
|
||||||
import be.jeffcheasey88.peeratcode.routes.Leaderboard;
|
import be.jeffcheasey88.peeratcode.routes.Leaderboard;
|
||||||
|
@ -102,6 +103,7 @@ public class Main {
|
||||||
router.register(new PuzzleResponse(router.getDataBase()));
|
router.register(new PuzzleResponse(router.getDataBase()));
|
||||||
router.register(new Leaderboard(router.getDataBase()));
|
router.register(new Leaderboard(router.getDataBase()));
|
||||||
router.register(new PlayerDetails(router.getDataBase()));
|
router.register(new PlayerDetails(router.getDataBase()));
|
||||||
|
router.register(new BadgeDetails(router.getDataBase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void startWebServer(Configuration config, Router router) throws IOException {
|
private static void startWebServer(Configuration config, Router router) throws IOException {
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class DatabaseRepository {
|
||||||
private static final String GET_PLAYER_BY_PSEUDO = GET_PLAYER + "pseudo = ?";
|
private static final String GET_PLAYER_BY_PSEUDO = GET_PLAYER + "pseudo = ?";
|
||||||
private static final String GET_PLAYER_DETAILS = "SELECT p.pseudo, p.email, p.firstname, p.lastname, p.description, p.avatar, p.sgroup,\n"
|
private static final String GET_PLAYER_DETAILS = "SELECT p.pseudo, p.email, p.firstname, p.lastname, p.description, p.avatar, p.sgroup,\n"
|
||||||
+ " SUM(c.score) AS playerScore, COUNT(c.id_completion) AS playerCompletions, SUM(c.tries) AS playerTries,\n"
|
+ " SUM(c.score) AS playerScore, COUNT(c.id_completion) AS playerCompletions, SUM(c.tries) AS playerTries,\n"
|
||||||
+ " GROUP_CONCAT(DISTINCT b.id_badge ORDER BY b.id_badge ASC SEPARATOR ', ') AS badges\n"
|
+ " GROUP_CONCAT(DISTINCT b.name ORDER BY b.name ASC SEPARATOR ', ') AS badges\n"
|
||||||
+ "FROM players p\n"
|
+ "FROM players p\n"
|
||||||
+ "LEFT JOIN completions c ON p.id_player = c.fk_player\n"
|
+ "LEFT JOIN completions c ON p.id_player = c.fk_player\n"
|
||||||
+ "LEFT JOIN containsBadges cb ON p.id_player = cb.fk_player\n"
|
+ "LEFT JOIN containsBadges cb ON p.id_player = cb.fk_player\n"
|
||||||
|
@ -46,6 +46,7 @@ public class DatabaseRepository {
|
||||||
private static final String GET_PLAYER_DETAILS_BY_ID = GET_PLAYER_DETAILS + "WHERE p.id_player = ? GROUP BY p.id_player;";
|
private static final String GET_PLAYER_DETAILS_BY_ID = GET_PLAYER_DETAILS + "WHERE p.id_player = ? GROUP BY p.id_player;";
|
||||||
private static final String GET_PLAYER_DETAILS_BY_PSEUDO = GET_PLAYER_DETAILS + "WHERE p.pseudo = ? GROUP BY p.pseudo;";
|
private static final String GET_PLAYER_DETAILS_BY_PSEUDO = GET_PLAYER_DETAILS + "WHERE p.pseudo = ? GROUP BY p.pseudo;";
|
||||||
private static final String ALL_PLAYERS_FOR_LEADERBOARD = "SELECT p.*, sum(c.score) AS playerScore, count(c.id_completion) AS playerCompletions, sum(c.tries) AS playerTries FROM players p LEFT JOIN completions c ON c.fk_player = p.id_player GROUP BY p.id_player ORDER BY playerScore DESC";
|
private static final String ALL_PLAYERS_FOR_LEADERBOARD = "SELECT p.*, sum(c.score) AS playerScore, count(c.id_completion) AS playerCompletions, sum(c.tries) AS playerTries FROM players p LEFT JOIN completions c ON c.fk_player = p.id_player GROUP BY p.id_player ORDER BY playerScore DESC";
|
||||||
|
private static final String GET_BADGE = "SELECT * FROM badges WHERE id_badge = ?";
|
||||||
private static final String INSERT_COMPLETION = "INSERT INTO completions (fk_puzzle, fk_player, tries, code, fileName, score) values (?, ?, ?, ?, ?, ?)";
|
private static final String INSERT_COMPLETION = "INSERT INTO completions (fk_puzzle, fk_player, tries, code, fileName, score) values (?, ?, ?, ?, ?, ?)";
|
||||||
private static final String UPDATE_COMPLETION = "UPDATE completions SET tries = ?, filename = ?, score = ? WHERE fk_puzzle = ? AND fk_player = ?";
|
private static final String UPDATE_COMPLETION = "UPDATE completions SET tries = ?, filename = ?, score = ? WHERE fk_puzzle = ? AND fk_player = ?";
|
||||||
|
|
||||||
|
@ -94,6 +95,11 @@ public class DatabaseRepository {
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Badge makeBadge(ResultSet rs) throws SQLException {
|
||||||
|
return new Badge(rs.getString("name"), rs.getBytes("logo"), rs.getInt("level"));
|
||||||
|
}
|
||||||
|
|
||||||
private boolean hasColumn(ResultSet rs, String columnName) throws SQLException {
|
private boolean hasColumn(ResultSet rs, String columnName) throws SQLException {
|
||||||
// Found on StackOverflow
|
// Found on StackOverflow
|
||||||
ResultSetMetaData rsmd = rs.getMetaData();
|
ResultSetMetaData rsmd = rs.getMetaData();
|
||||||
|
@ -231,6 +237,21 @@ public class DatabaseRepository {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Badge getBadge(int badgeId) {
|
||||||
|
try {
|
||||||
|
ensureConnection();
|
||||||
|
PreparedStatement completionsStmt = con.prepareStatement(GET_BADGE);
|
||||||
|
completionsStmt.setInt(1, badgeId);
|
||||||
|
ResultSet result = completionsStmt.executeQuery();
|
||||||
|
if (result.next()) {
|
||||||
|
return makeBadge(result);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a specific chapter
|
* Get a specific chapter
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue