Add players count in group list for a chapter

This commit is contained in:
jeffcheasey88 2024-03-31 12:06:35 +02:00
parent f23904d860
commit 15f0791777
3 changed files with 10 additions and 3 deletions

View file

@ -15,6 +15,7 @@ public class Group implements Comparable<Group> {
private Integer linkToChapter;
// private Integer linkToPuzzle;
private List<Player> players;
private int playerCount;
@Override
public String toString(){
@ -29,10 +30,15 @@ public class Group implements Comparable<Group> {
// this.linkToPuzzle = ((Number) json.get("puzzle")).intValue();
}
public Group(String name, Integer initChap, Integer initPuzz) {
public Group(String name, Integer initChap, Integer initPuzz, int playerCount) {
this.name = name;
this.linkToChapter = initChap;
// this.linkToPuzzle = initPuzz;
this.playerCount = playerCount;
}
public int getPlayerCount(){
return this.playerCount;
}
@SeaBottle
@ -113,6 +119,7 @@ public class Group implements Comparable<Group> {
}
groupJSON.put("players", groupsPlayerJSON);
}
groupJSON.put("playerCount", this.playerCount);
return groupJSON;
}

View file

@ -21,7 +21,7 @@ public enum DatabaseQuery {
// GROUPS
ALL_GROUPS("SELECT * FROM groups"),
ALL_GROUPS_BY_CHAPTER("SELECT * FROM groups WHERE fk_chapter = ?"),
ALL_GROUPS_BY_CHAPTER("select g.*, count(cg.fk_player) as countPlayer from groups g left join containsGroups cg on cg.fk_group = g.id_group where g.fk_chapter = ? group by g.id_group"),
GET_GROUP_FOR_PLAYER("SELECT g.* FROM groups g JOIN containsGroups cg ON cg.fk_group = g.id_group WHERE cg.fk_player = ? AND g.fk_chapter = ?"), // AND g.fk_puzzle = ?
GET_GROUP_ID_BY_DATA("SELECT id_group FROM groups WHERE name = ? AND (fk_chapter = ?)"), // OR fk_puzzle = ?
GET_GROUP_USERS_COUNT("SELECT count(*) as howmany FROM containsGroups WHERE fk_group = ?"),

View file

@ -98,7 +98,7 @@ public class DatabaseRepository {
}
private Group makeGroup(ResultSet result) throws SQLException {
return new Group(result.getString("name"), result.getInt("fk_chapter"), result.getInt("fk_puzzle"));
return new Group(result.getString("name"), result.getInt("fk_chapter"), result.getInt("fk_puzzle"), ((hasColumn(result, "countPlayer")) ? result.getInt("countPlayer") : 0));
}
private Player makeGroupPlayer(ResultSet result) throws SQLException {