add show and start_date to puzzle

This commit is contained in:
Francois G 2023-09-11 14:06:27 +02:00
parent 62c2a923ae
commit 6824ced972
3 changed files with 15 additions and 2 deletions

View file

@ -1,5 +1,7 @@
package dev.peerat.backend.model; package dev.peerat.backend.model;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -17,9 +19,10 @@ public class Puzzle {
private int scoreMax; private int scoreMax;
private Set<String> tags; private Set<String> tags;
private int depend; private int depend;
private Timestamp startDate;
public Puzzle(int id, String name, String content, byte[] soluce, String verify, int scoreMax, String tags, public Puzzle(int id, String name, String content, byte[] soluce, String verify, int scoreMax, String tags,
int depend) { int depend, Timestamp startDate) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.content = content; this.content = content;
@ -28,6 +31,7 @@ public class Puzzle {
this.scoreMax = scoreMax; this.scoreMax = scoreMax;
setTags(tags); setTags(tags);
this.depend = depend; this.depend = depend;
this.startDate = startDate;
} }
public int getId() { public int getId() {
@ -82,6 +86,13 @@ public class Puzzle {
return this.depend; return this.depend;
} }
public boolean isInCurrentTime(){
LocalDateTime now = LocalDateTime.now();
boolean show = true;
if(startDate != null) show &= now.isAfter(startDate.toLocalDateTime());
return show;
}
@Override @Override
public boolean equals(Object object) { public boolean equals(Object object) {
if (this == object) if (this == object)

View file

@ -45,7 +45,8 @@ public class DatabaseRepository {
return new Puzzle(puzzleResult.getInt("id_puzzle"), puzzleResult.getString("name"), return new Puzzle(puzzleResult.getInt("id_puzzle"), puzzleResult.getString("name"),
puzzleResult.getString("content"), puzzleResult.getBytes("soluce"), puzzleResult.getString("verify"), puzzleResult.getString("content"), puzzleResult.getBytes("soluce"), puzzleResult.getString("verify"),
puzzleResult.getInt("score_max"), puzzleResult.getString("tags"), puzzleResult.getInt("score_max"), puzzleResult.getString("tags"),
hasColumn(puzzleResult, "origin") ? puzzleResult.getInt("origin") : -1); hasColumn(puzzleResult, "origin") ? puzzleResult.getInt("origin") : -1,
puzzleResult.getTimestamp("start_date"));
} }
private Chapter makeChapter(ResultSet chapterResult) throws SQLException { private Chapter makeChapter(ResultSet chapterResult) throws SQLException {

View file

@ -47,6 +47,7 @@ public class ChapterElement implements Response {
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()); int score = this.databaseRepo.getScore(user.getId(), puzzle.getId());
if(score >= 0) puzzleJSON.put("score", score); if(score >= 0) puzzleJSON.put("score", score);
puzzleJSON.put("show", puzzle.isInCurrentTime());
puzzles.add(puzzleJSON); puzzles.add(puzzleJSON);
} }
chapterJSON.put("puzzles", puzzles); chapterJSON.put("puzzles", puzzles);