add show and start_date to puzzle
This commit is contained in:
parent
62c2a923ae
commit
6824ced972
3 changed files with 15 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
|||
package dev.peerat.backend.model;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -17,9 +19,10 @@ public class Puzzle {
|
|||
private int scoreMax;
|
||||
private Set<String> tags;
|
||||
private int depend;
|
||||
private Timestamp startDate;
|
||||
|
||||
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.name = name;
|
||||
this.content = content;
|
||||
|
@ -28,6 +31,7 @@ public class Puzzle {
|
|||
this.scoreMax = scoreMax;
|
||||
setTags(tags);
|
||||
this.depend = depend;
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
@ -81,6 +85,13 @@ public class Puzzle {
|
|||
public int getDepend() {
|
||||
return this.depend;
|
||||
}
|
||||
|
||||
public boolean isInCurrentTime(){
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
boolean show = true;
|
||||
if(startDate != null) show &= now.isAfter(startDate.toLocalDateTime());
|
||||
return show;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
|
|
|
@ -45,7 +45,8 @@ public class DatabaseRepository {
|
|||
return new Puzzle(puzzleResult.getInt("id_puzzle"), puzzleResult.getString("name"),
|
||||
puzzleResult.getString("content"), puzzleResult.getBytes("soluce"), puzzleResult.getString("verify"),
|
||||
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 {
|
||||
|
|
|
@ -47,6 +47,7 @@ public class ChapterElement implements Response {
|
|||
if (puzzle.getTags() != null) puzzleJSON.put("tags", puzzle.getJsonTags());
|
||||
int score = this.databaseRepo.getScore(user.getId(), puzzle.getId());
|
||||
if(score >= 0) puzzleJSON.put("score", score);
|
||||
puzzleJSON.put("show", puzzle.isInCurrentTime());
|
||||
puzzles.add(puzzleJSON);
|
||||
}
|
||||
chapterJSON.put("puzzles", puzzles);
|
||||
|
|
Loading…
Add table
Reference in a new issue