Add depend field on PuzzleElement response if puzzle is nextPart from another
This commit is contained in:
parent
61f6046659
commit
69acf0966e
4 changed files with 37 additions and 19 deletions
|
@ -8,14 +8,19 @@ public class Puzzle {
|
|||
private byte[] soluce;
|
||||
private String verify;
|
||||
private int scoreMax;
|
||||
private int depend;
|
||||
|
||||
public Puzzle(int id, String name, String content, byte[] soluce, String verify, int scoreMax){
|
||||
this(id, name, content, soluce, verify, scoreMax, -1);
|
||||
}
|
||||
public Puzzle(int id, String name, String content, byte[] soluce, String verify, int scoreMax, int depend){
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.content = content;
|
||||
this.soluce = soluce;
|
||||
this.verify = verify;
|
||||
this.scoreMax = scoreMax;
|
||||
this.depend = depend;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
@ -66,6 +71,14 @@ public class Puzzle {
|
|||
this.scoreMax = max;
|
||||
}
|
||||
|
||||
public int getDepend(){
|
||||
return this.depend;
|
||||
}
|
||||
|
||||
public void setDepend(int depend){
|
||||
this.depend = depend;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if(this == object) return true;
|
||||
|
|
|
@ -23,7 +23,7 @@ import be.jeffcheasey88.peeratcode.model.Player;
|
|||
import be.jeffcheasey88.peeratcode.model.Puzzle;
|
||||
|
||||
public class DatabaseRepository {
|
||||
private static final String SPECIFIC_PUZZLE_QUERY = "SELECT * FROM puzzles WHERE id_puzzle = ?";
|
||||
private static final String SPECIFIC_PUZZLE_QUERY = "SELECT p.*, np.origin FROM puzzles p LEFT JOIN nextPart np ON p.id_puzzle = np.next WHERE p.id_puzzle = ?;";
|
||||
private static final String SPECIFIC_CHAPTER_QUERY = "SELECT * FROM chapters WHERE id_chapter = ?";
|
||||
private static final String PUZZLES_IN_CHAPTER_QUERY = "SELECT * FROM puzzles WHERE fk_chapter = ?";
|
||||
private static final String ALL_CHAPTERS_QUERY = "SELECT * FROM chapters WHERE id_chapter > 0";
|
||||
|
@ -38,13 +38,14 @@ public class DatabaseRepository {
|
|||
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"
|
||||
+ " 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 SEPARATOR ', ') AS badges\n" + "FROM players p\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 badges b ON cb.fk_badge = b.id_badge\n";
|
||||
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_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 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 (?, ?, ?, ?, ?, ?)";
|
||||
|
@ -67,7 +68,7 @@ public class DatabaseRepository {
|
|||
|
||||
private Puzzle makePuzzle(ResultSet puzzleResult) throws SQLException {
|
||||
return new Puzzle(puzzleResult.getInt("id_puzzle"), puzzleResult.getString("name"),
|
||||
puzzleResult.getString("content"), null, "", 0);
|
||||
puzzleResult.getString("content"), null, "", 0, puzzleResult.getInt("origin"));
|
||||
}
|
||||
|
||||
private Chapter makeChapter(ResultSet chapterResult) throws SQLException {
|
||||
|
@ -102,14 +103,14 @@ public class DatabaseRepository {
|
|||
|
||||
private boolean hasColumn(ResultSet rs, String columnName) throws SQLException {
|
||||
// Found on StackOverflow
|
||||
ResultSetMetaData rsmd = rs.getMetaData();
|
||||
int columns = rsmd.getColumnCount();
|
||||
for (int x = 1; x <= columns; x++) {
|
||||
if (columnName.equals(rsmd.getColumnName(x))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
ResultSetMetaData rsmd = rs.getMetaData();
|
||||
int columns = rsmd.getColumnCount();
|
||||
for (int x = 1; x <= columns; x++) {
|
||||
if (columnName.equals(rsmd.getColumnName(x))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<Puzzle> getPuzzlesInChapter(int id) throws SQLException {
|
||||
|
@ -204,6 +205,7 @@ public class DatabaseRepository {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Player getPlayerDetails(String pseudoPlayer) {
|
||||
try {
|
||||
ensureConnection();
|
||||
|
@ -226,7 +228,7 @@ public class DatabaseRepository {
|
|||
ResultSet result = playersStmt.executeQuery();
|
||||
SortedSet<Player> players = new TreeSet<Player>();
|
||||
Player tmpPlayer;
|
||||
while (result.next()){
|
||||
while (result.next()) {
|
||||
tmpPlayer = makePlayer(result);
|
||||
players.add(tmpPlayer);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ public class PuzzleElement implements Response {
|
|||
puzzleJSON.put("id", puzzle.getId());
|
||||
puzzleJSON.put("name", puzzle.getName());
|
||||
puzzleJSON.put("content", puzzle.getContent());
|
||||
if (puzzle.getDepend() > 0)
|
||||
puzzleJSON.put("depend", puzzle.getDepend());
|
||||
writer.write(puzzleJSON.toJSONString());
|
||||
}
|
||||
}
|
||||
|
|
1
testApi/test.java
Normal file
1
testApi/test.java
Normal file
|
@ -0,0 +1 @@
|
|||
ceci est du code source java
|
Loading…
Add table
Reference in a new issue