Update show for puzzle and chapter

This commit is contained in:
Francois G 2023-09-16 09:25:38 +02:00
parent fe904774c0
commit 772dd2d23f
4 changed files with 5 additions and 6 deletions

View file

@ -35,11 +35,10 @@ public class Chapter {
this.puzzles = puzzles; this.puzzles = puzzles;
} }
public boolean isInCurrentTime(){ public boolean hasStarted(){
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
boolean show = true; boolean show = true;
if(startDate != null) show &= now.isAfter(startDate.toLocalDateTime()); if(startDate != null) show &= now.isAfter(startDate.toLocalDateTime());
if(endDate != null) show &= now.isBefore(endDate.toLocalDateTime());
return show; return show;
} }

View file

@ -86,7 +86,7 @@ public class Puzzle {
return this.depend; return this.depend;
} }
public boolean isInCurrentTime(){ public boolean hasStarted(){
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
boolean show = true; boolean show = true;
if(startDate != null) show &= now.isAfter(startDate.toLocalDateTime()); if(startDate != null) show &= now.isAfter(startDate.toLocalDateTime());

View file

@ -33,7 +33,7 @@ public class ChapterElement implements Response {
JsonMap chapterJSON = new JsonMap(); JsonMap chapterJSON = new JsonMap();
chapterJSON.set("id", chapter.getId()); chapterJSON.set("id", chapter.getId());
chapterJSON.set("name", chapter.getName()); chapterJSON.set("name", chapter.getName());
boolean show = chapter.isInCurrentTime(); boolean show = chapter.hasStarted();
chapterJSON.set("show", show); chapterJSON.set("show", show);
PeerAtUser user = context.getUser(); PeerAtUser user = context.getUser();
if(show){ if(show){
@ -46,7 +46,7 @@ public class ChapterElement implements Response {
if (puzzle.getTags() != null) puzzleJSON.set("tags", puzzle.getJsonTags()); if (puzzle.getTags() != null) puzzleJSON.set("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.set("score", score); if(score >= 0) puzzleJSON.set("score", score);
puzzleJSON.set("show", puzzle.isInCurrentTime()); puzzleJSON.set("show", puzzle.hasStarted());
puzzles.add(puzzleJSON); puzzles.add(puzzleJSON);
} }
chapterJSON.set("puzzles", puzzles); chapterJSON.set("puzzles", puzzles);

View file

@ -34,7 +34,7 @@ public class ChapterList implements Response {
JsonMap chapterJSON = new JsonMap(); JsonMap chapterJSON = new JsonMap();
chapterJSON.set("id", chapter.getId()); chapterJSON.set("id", chapter.getId());
chapterJSON.set("name", chapter.getName()); chapterJSON.set("name", chapter.getName());
chapterJSON.set("show", chapter.isInCurrentTime()); chapterJSON.set("show", chapter.hasStarted());
chaptersJSON.add(chapterJSON); chaptersJSON.add(chapterJSON);
} }
context.response(200); context.response(200);