Tries
This commit is contained in:
parent
76c8ec7a87
commit
7858752406
3 changed files with 30 additions and 9 deletions
|
@ -43,6 +43,8 @@ public enum DatabaseQuery {
|
||||||
// COMPLETIONS
|
// COMPLETIONS
|
||||||
GET_COMPLETION(
|
GET_COMPLETION(
|
||||||
"SELECT id_completion, tries, fileName, score FROM completions WHERE fk_puzzle = ? AND fk_player = ?"),
|
"SELECT id_completion, tries, fileName, score FROM completions WHERE fk_puzzle = ? AND fk_player = ?"),
|
||||||
|
GET_COMPLETION_GROUP(
|
||||||
|
"SELECT c.* FROM containsGroups cg LEFT JOIN groups g ON cg.fk_group = g.id_group LEFT JOIN completions c ON cg.fk_player = c.fk_player WHERE cg.fk_player = ? AND g.fk_puzzle = ? AND c.fk_puzzle = g.fk_puzzle"),
|
||||||
INSERT_COMPLETION(
|
INSERT_COMPLETION(
|
||||||
"INSERT INTO completions (fk_puzzle, fk_player, tries, code, fileName, score) values (?, ?, ?, ?, ?, ?)"),
|
"INSERT INTO completions (fk_puzzle, fk_player, tries, code, fileName, score) values (?, ?, ?, ?, ?, ?)"),
|
||||||
UPDATE_COMPLETION(
|
UPDATE_COMPLETION(
|
||||||
|
@ -189,14 +191,16 @@ BEGIN
|
||||||
WHERE fk_badge = @badge AND fk_player = NEW.fk_player;
|
WHERE fk_badge = @badge AND fk_player = NEW.fk_player;
|
||||||
|
|
||||||
IF (@contain = 0) THEN
|
IF (@contain = 0) THEN
|
||||||
INSERT INTO containsBadges(fk_player, fk_badge) VALUES (NEW.fk_player, @badge);
|
|
||||||
|
IF (NEW.score >= 0 AND NEW.tries < 2) THEN
|
||||||
|
INSERT INTO containsBadges(fk_player, fk_badge) VALUES (NEW.fk_player, @badge);
|
||||||
|
END IF;
|
||||||
END IF;
|
END IF;
|
||||||
END IF;
|
END IF;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CREATE OR REPLACE TRIGGER EventParticipation
|
CREATE OR REPLACE TRIGGER EventParticipation
|
||||||
AFTER INSERT
|
AFTER INSERT
|
||||||
ON completions FOR EACH ROW
|
ON completions FOR EACH ROW
|
||||||
|
|
|
@ -219,6 +219,19 @@ public class DatabaseRepository {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Completion getCompletionGroup(int user, int puzzle){
|
||||||
|
try {
|
||||||
|
PreparedStatement stmt = DatabaseQuery.GET_COMPLETION_GROUP.prepare(this.con);
|
||||||
|
stmt.setInt(1, user);
|
||||||
|
stmt.setInt(2, puzzle);
|
||||||
|
ResultSet result = stmt.executeQuery();
|
||||||
|
if (result.next()) return makeCompletion(user, puzzle, result);
|
||||||
|
} catch (SQLException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return getCompletion(user, puzzle);
|
||||||
|
}
|
||||||
|
|
||||||
public Completion getCompletion(int playerId, int puzzleId) {
|
public Completion getCompletion(int playerId, int puzzleId) {
|
||||||
try {
|
try {
|
||||||
PreparedStatement completionsStmt = DatabaseQuery.GET_COMPLETION.prepare(this.con);
|
PreparedStatement completionsStmt = DatabaseQuery.GET_COMPLETION.prepare(this.con);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import be.jeffcheasey88.peeratcode.framework.HttpWriter;
|
||||||
import be.jeffcheasey88.peeratcode.framework.Response;
|
import be.jeffcheasey88.peeratcode.framework.Response;
|
||||||
import be.jeffcheasey88.peeratcode.framework.Route;
|
import be.jeffcheasey88.peeratcode.framework.Route;
|
||||||
import be.jeffcheasey88.peeratcode.framework.User;
|
import be.jeffcheasey88.peeratcode.framework.User;
|
||||||
|
import be.jeffcheasey88.peeratcode.model.Completion;
|
||||||
import be.jeffcheasey88.peeratcode.model.Puzzle;
|
import be.jeffcheasey88.peeratcode.model.Puzzle;
|
||||||
import be.jeffcheasey88.peeratcode.repository.DatabaseRepository;
|
import be.jeffcheasey88.peeratcode.repository.DatabaseRepository;
|
||||||
|
|
||||||
|
@ -31,8 +32,11 @@ public class PuzzleElement implements Response {
|
||||||
puzzleJSON.put("content", puzzle.getContent());
|
puzzleJSON.put("content", puzzle.getContent());
|
||||||
puzzleJSON.put("scoreMax", puzzle.getScoreMax());
|
puzzleJSON.put("scoreMax", puzzle.getScoreMax());
|
||||||
if(puzzle.getTags() != null) puzzleJSON.put("tags", puzzle.getJsonTags());
|
if(puzzle.getTags() != null) puzzleJSON.put("tags", puzzle.getJsonTags());
|
||||||
int score = this.databaseRepo.getScore(user.getId(), puzzle.getId());
|
Completion completion = this.databaseRepo.getCompletionGroup(user.getId(), puzzle.getId());
|
||||||
if(score >= 0) puzzleJSON.put("score", score);
|
if(completion != null && completion.getScore() >= 0){
|
||||||
|
puzzleJSON.put("score", completion.getScore());
|
||||||
|
puzzleJSON.put("tries", completion.getTries());
|
||||||
|
}
|
||||||
if(puzzle.getDepend() > 0) puzzleJSON.put("depend", puzzle.getDepend());
|
if(puzzle.getDepend() > 0) puzzleJSON.put("depend", puzzle.getDepend());
|
||||||
HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *", "Content-Type: application/json");
|
HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *", "Content-Type: application/json");
|
||||||
writer.write(puzzleJSON.toJSONString());
|
writer.write(puzzleJSON.toJSONString());
|
||||||
|
|
Loading…
Add table
Reference in a new issue