add tags support

This commit is contained in:
Francois G 2023-03-17 22:44:20 +01:00
parent 77283bdf75
commit 2bb0328206
4 changed files with 19 additions and 8 deletions

View file

@ -8,18 +8,20 @@ public class Puzzle {
private byte[] soluce;
private String verify;
private int scoreMax;
private String tags;
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, String tags){
this(id, name, content, soluce, verify, scoreMax, tags, -1);
}
public Puzzle(int id, String name, String content, byte[] soluce, String verify, int scoreMax, int depend){
public Puzzle(int id, String name, String content, byte[] soluce, String verify, int scoreMax, String tags, int depend){
this.id = id;
this.name = name;
this.content = content;
this.soluce = soluce;
this.verify = verify;
this.scoreMax = scoreMax;
this.tags = tags;
this.depend = depend;
}
@ -71,6 +73,14 @@ public class Puzzle {
this.scoreMax = max;
}
public String getTags(){
return this.tags;
}
public void setTags(int tags){
this.scoreMax = tags;
}
public int getDepend(){
return this.depend;
}

View file

@ -23,9 +23,9 @@ import be.jeffcheasey88.peeratcode.model.Player;
import be.jeffcheasey88.peeratcode.model.Puzzle;
public class DatabaseRepository {
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_PUZZLE_QUERY = "SELECT p.*, np.origin, GROUP_CONCAT(t.name) AS tags FROM puzzles p LEFT JOIN nextPart np ON p.id_puzzle = np.next LEFT JOIN containsTags ct ON ct.fk_puzzle = p.id_puzzle LEFT JOIN tags t ON t.id_tag = ct.fk_tag WHERE p.id_puzzle = ? GROUP BY 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 PUZZLES_IN_CHAPTER_QUERY = "SELECT p.*, GROUP_CONCAT(t.name) AS tags FROM puzzles p LEFT JOIN containsTags ct ON ct.fk_puzzle = p.id_puzzle LEFT JOIN tags t ON t.id_tag = ct.fk_tag WHERE fk_chapter = ? GROUP BY p.id_puzzle";
private static final String ALL_CHAPTERS_QUERY = "SELECT * FROM chapters WHERE id_chapter > 0";
private static final String CHECK_PSEUDO_AVAILABLE_QUERY = "SELECT * FROM players WHERE pseudo = ?";
private static final String CHECK_EMAIL_AVAILABLE_QUERY = "SELECT * FROM players WHERE email = ?";
@ -69,7 +69,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.getString("tags"),
hasColumn(puzzleResult, "origin") ? puzzleResult.getInt("origin") : -1);
}

View file

@ -38,6 +38,7 @@ public class ChapterElement implements Response {
JSONObject puzzleJSON = new JSONObject();
puzzleJSON.put("id", puzzle.getId());
puzzleJSON.put("name", puzzle.getName());
if (puzzle.getTags() != null) puzzleJSON.put("tags", puzzle.getTags());
puzzles.add(puzzleJSON);
}
chapterJSON.put("puzzles", puzzles);

View file

@ -33,8 +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());
if (puzzle.getTags() != null) puzzleJSON.put("tags", puzzle.getTags());
if (puzzle.getDepend() > 0) puzzleJSON.put("depend", puzzle.getDepend());
writer.write(puzzleJSON.toJSONString());
}
}