make school group always first in json player
This commit is contained in:
parent
241abea7ad
commit
e983ab5445
2 changed files with 7 additions and 5 deletions
|
@ -2,8 +2,10 @@ package be.jeffcheasey88.peeratcode.model;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
@ -16,7 +18,7 @@ public class Player implements Comparable<Player> {
|
|||
private String firstname;
|
||||
private String lastname;
|
||||
private String description;
|
||||
private Set<String> groups;
|
||||
private LinkedHashSet<String> groups;
|
||||
private byte[] avatar;
|
||||
|
||||
private int totalScore;
|
||||
|
@ -94,7 +96,7 @@ public class Player implements Comparable<Player> {
|
|||
if (groups == null || groups.isEmpty())
|
||||
groups = null;
|
||||
else
|
||||
this.groups = new HashSet<String>(Arrays.asList(groups.split(",")));
|
||||
this.groups = new LinkedHashSet<String>(Arrays.asList(groups.split(",")));
|
||||
}
|
||||
|
||||
public byte[] getAvatar() {
|
||||
|
|
|
@ -34,10 +34,10 @@ public class DatabaseRepository {
|
|||
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 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 = "SELECT p.*, GROUP_CONCAT(g.name) FROM players p WHERE ";
|
||||
private static final String GET_PLAYER = "SELECT p.*, GROUP_CONCAT(g.name ORDER BY g.fk_chapter, g.fk_puzzle) FROM players p WHERE ";
|
||||
private static final String GET_PLAYER_BY_ID = GET_PLAYER + "id_player = ?" + PART_GET_PLAYER_GROUP;
|
||||
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"
|
||||
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 ORDER BY g.fk_chapter, g.fk_puzzle) AS 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) AS badges FROM players p\n"
|
||||
+ "LEFT JOIN completions c ON p.id_player = c.fk_player\n"
|
||||
|
@ -47,7 +47,7 @@ public class DatabaseRepository {
|
|||
+ " 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.*, 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 ALL_PLAYERS_FOR_LEADERBOARD = "SELECT p.*, GROUP_CONCAT(DISTINCT g.name ORDER BY g.fk_chapter, g.fk_puzzle) 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 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 = ?";
|
||||
|
|
Loading…
Add table
Reference in a new issue