Solve compatibility problem with new DB schema. To test use pac_test instead of pc in config.txt
This commit is contained in:
parent
d3c9ad22e5
commit
d74013a13a
4 changed files with 32 additions and 13 deletions
|
@ -1,5 +1,7 @@
|
||||||
package be.jeffcheasey88.peeratcode.model;
|
package be.jeffcheasey88.peeratcode.model;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Chapter {
|
public class Chapter {
|
||||||
|
@ -7,10 +9,14 @@ public class Chapter {
|
||||||
private int id;
|
private int id;
|
||||||
private String name;
|
private String name;
|
||||||
private List<Puzzle> puzzles;
|
private List<Puzzle> puzzles;
|
||||||
|
private Timestamp startDate;
|
||||||
|
private Timestamp endDate;
|
||||||
|
|
||||||
public Chapter(int id, String name) {
|
public Chapter(int id, String name, Timestamp startDate, Timestamp endDate) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.startDate = startDate;
|
||||||
|
this.endDate = endDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
@ -37,6 +43,14 @@ public class Chapter {
|
||||||
this.puzzles = puzzles;
|
this.puzzles = puzzles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Timestamp getStartDate() {
|
||||||
|
return startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getEndDate() {
|
||||||
|
return endDate;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object object){
|
public boolean equals(Object object){
|
||||||
if(this == object) return true;
|
if(this == object) return true;
|
||||||
|
|
|
@ -33,20 +33,21 @@ public class DatabaseRepository {
|
||||||
private static final String CHECK_PASSWORD = "SELECT id_player, passwd FROM players WHERE pseudo=?";
|
private static final String CHECK_PASSWORD = "SELECT id_player, passwd FROM players WHERE pseudo=?";
|
||||||
private static final String SCORE = "SELECT score FROM completions WHERE fk_player = ? AND fk_puzzle = ?";
|
private static final String SCORE = "SELECT score FROM completions WHERE fk_player = ? AND fk_puzzle = ?";
|
||||||
private static final String GET_COMPLETION = "SELECT id_completion, tries, fileName, score FROM completions WHERE fk_puzzle = ? AND fk_player = ?";
|
private static final String GET_COMPLETION = "SELECT id_completion, tries, fileName, score FROM completions WHERE fk_puzzle = ? AND fk_player = ?";
|
||||||
private static final String GET_PLAYER = "SELECT * FROM players WHERE ";
|
private static final String PART_GET_PLAYER_GROUP = " LEFT JOIN containsGroups cg ON p.id_player = cg.fk_player LEFT JOIN groups g ON cg.fk_group = g.id_group ";
|
||||||
private static final String GET_PLAYER_BY_ID = GET_PLAYER + "id_player = ?";
|
private static final String GET_PLAYER = "SELECT p.*, GROUP_CONCAT(g.name) FROM players p WHERE ";
|
||||||
private static final String GET_PLAYER_BY_PSEUDO = GET_PLAYER + "pseudo = ?";
|
private static final String GET_PLAYER_BY_ID = GET_PLAYER + "id_player = ?" + PART_GET_PLAYER_GROUP;
|
||||||
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_BY_PSEUDO = GET_PLAYER + "pseudo = ?" + PART_GET_PLAYER_GROUP;;
|
||||||
|
private static final String GET_PLAYER_DETAILS = "SELECT p.pseudo, p.email, p.firstname, p.lastname, p.description, p.avatar, GROUP_CONCAT(DISTINCT g.name) AS 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.name ORDER BY b.name ASC SEPARATOR ', ') AS badges\n" + "FROM players p\n"
|
+ " GROUP_CONCAT(DISTINCT b.name ORDER BY b.name ASC) AS badges 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"
|
||||||
+ "LEFT JOIN badges b ON cb.fk_badge = b.id_badge\n";
|
+ "LEFT JOIN badges b ON cb.fk_badge = b.id_badge\n" + PART_GET_PLAYER_GROUP;
|
||||||
private static final String GET_PLAYER_DETAILS_BY_ID = GET_PLAYER_DETAILS
|
private static final String GET_PLAYER_DETAILS_BY_ID = GET_PLAYER_DETAILS
|
||||||
+ " WHERE p.id_player = ? GROUP BY p.id_player;";
|
+ " WHERE p.id_player = ? GROUP BY p.id_player;";
|
||||||
private static final String GET_PLAYER_DETAILS_BY_PSEUDO = GET_PLAYER_DETAILS
|
private static final String GET_PLAYER_DETAILS_BY_PSEUDO = GET_PLAYER_DETAILS
|
||||||
+ " WHERE p.pseudo = ? GROUP BY p.pseudo;";
|
+ " 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.*, GROUP_CONCAT(DISTINCT g.name) AS sgroup, sum(c.score) AS playerScore, count(c.id_completion) AS playerCompletions, sum(c.tries) AS playerTries FROM players p " + PART_GET_PLAYER_GROUP + "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 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 = ?";
|
||||||
|
@ -68,11 +69,12 @@ public class DatabaseRepository {
|
||||||
|
|
||||||
private Puzzle makePuzzle(ResultSet puzzleResult) throws SQLException {
|
private Puzzle makePuzzle(ResultSet puzzleResult) throws SQLException {
|
||||||
return new Puzzle(puzzleResult.getInt("id_puzzle"), puzzleResult.getString("name"),
|
return new Puzzle(puzzleResult.getInt("id_puzzle"), puzzleResult.getString("name"),
|
||||||
puzzleResult.getString("content"), null, "", 0, hasColumn(puzzleResult, "origin") ? puzzleResult.getInt("origin") : -1);
|
puzzleResult.getString("content"), null, "", 0,
|
||||||
|
hasColumn(puzzleResult, "origin") ? puzzleResult.getInt("origin") : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Chapter makeChapter(ResultSet chapterResult) throws SQLException {
|
private Chapter makeChapter(ResultSet chapterResult) throws SQLException {
|
||||||
return new Chapter(chapterResult.getInt("id_chapter"), chapterResult.getString("name"));
|
return new Chapter(chapterResult.getInt("id_chapter"), chapterResult.getString("name"), chapterResult.getTimestamp("start_date"), chapterResult.getTimestamp("end_date"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Completion makeCompletion(int playerId, int puzzleId, ResultSet completionResult) throws SQLException {
|
private Completion makeCompletion(int playerId, int puzzleId, ResultSet completionResult) throws SQLException {
|
||||||
|
|
|
@ -31,6 +31,8 @@ public class ChapterElement implements Response {
|
||||||
JSONObject chapterJSON = new JSONObject();
|
JSONObject chapterJSON = new JSONObject();
|
||||||
chapterJSON.put("id", chapter.getId());
|
chapterJSON.put("id", chapter.getId());
|
||||||
chapterJSON.put("name", chapter.getName());
|
chapterJSON.put("name", chapter.getName());
|
||||||
|
if (chapter.getStartDate() != null) chapterJSON.put("startDate", chapter.getStartDate());
|
||||||
|
if (chapter.getEndDate() != null) chapterJSON.put("endDate", chapter.getEndDate());
|
||||||
JSONArray puzzles = new JSONArray();
|
JSONArray puzzles = new JSONArray();
|
||||||
for (Puzzle puzzle : chapter.getPuzzles()) {
|
for (Puzzle puzzle : chapter.getPuzzles()) {
|
||||||
JSONObject puzzleJSON = new JSONObject();
|
JSONObject puzzleJSON = new JSONObject();
|
||||||
|
|
|
@ -11,6 +11,7 @@ import be.jeffcheasey88.peeratcode.webserver.User;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -33,7 +34,7 @@ public class Leaderboard implements Response {
|
||||||
JSONObject playerJSON = new JSONObject();
|
JSONObject playerJSON = new JSONObject();
|
||||||
playerJSON.put("pseudo", player.getPseudo());
|
playerJSON.put("pseudo", player.getPseudo());
|
||||||
playerJSON.put("group", player.getGroup());
|
playerJSON.put("group", player.getGroup());
|
||||||
// chapterJSON.put("avatar", player.);
|
if(player.getAvatar() != null) playerJSON.put("avatar", new String(Base64.getEncoder().encode(player.getAvatar())));
|
||||||
playerJSON.put("score", player.getTotalScore());
|
playerJSON.put("score", player.getTotalScore());
|
||||||
playerJSON.put("completions", player.getTotalCompletion());
|
playerJSON.put("completions", player.getTotalCompletion());
|
||||||
playerJSON.put("tries", player.getTotalTries());
|
playerJSON.put("tries", player.getTotalTries());
|
||||||
|
|
Loading…
Add table
Reference in a new issue