Remove verif hour from front

This commit is contained in:
jeffcheasey88 2023-09-07 18:54:17 +02:00
parent 4a499e3540
commit 03e64abf9c
3 changed files with 30 additions and 22 deletions

View file

@ -1,6 +1,7 @@
package be.jeffcheasey88.peeratcode.model; package be.jeffcheasey88.peeratcode.model;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
public class Chapter { public class Chapter {
@ -34,6 +35,14 @@ public class Chapter {
this.puzzles = puzzles; this.puzzles = puzzles;
} }
public boolean isInCurrentTime(){
LocalDateTime now = LocalDateTime.now();
boolean show = true;
if(startDate != null) show &= now.isAfter(startDate.toLocalDateTime());
if(endDate != null) show &= now.isBefore(endDate.toLocalDateTime());
return show;
}
public Timestamp getStartDate() { public Timestamp getStartDate() {
return startDate; return startDate;
} }

View file

@ -33,10 +33,10 @@ public class ChapterElement implements Response {
JSONObject chapterJSON = new JSONObject(); JSONObject chapterJSON = new JSONObject();
chapterJSON.put("id", chapter.getId()); chapterJSON.put("id", chapter.getId());
chapterJSON.put("name", chapter.getName()); chapterJSON.put("name", chapter.getName());
if (chapter.getStartDate() != null) boolean show = chapter.isInCurrentTime();
chapterJSON.put("startDate", chapter.getStartDate().toString()); chapterJSON.put("show", show);
if (chapter.getEndDate() != null)
chapterJSON.put("endDate", chapter.getEndDate().toString()); if(show){
JSONArray puzzles = new JSONArray(); JSONArray puzzles = new JSONArray();
for (Puzzle puzzle : chapter.getPuzzles()){ for (Puzzle puzzle : chapter.getPuzzles()){
JSONObject puzzleJSON = new JSONObject(); JSONObject puzzleJSON = new JSONObject();
@ -49,6 +49,8 @@ public class ChapterElement implements Response {
puzzles.add(puzzleJSON); puzzles.add(puzzleJSON);
} }
chapterJSON.put("puzzles", puzzles); chapterJSON.put("puzzles", puzzles);
}
writer.response(200, "Access-Control-Allow-Origin: *"); writer.response(200, "Access-Control-Allow-Origin: *");
writer.write(chapterJSON.toJSONString()); writer.write(chapterJSON.toJSONString());
} else { } else {

View file

@ -35,10 +35,7 @@ public class ChapterList implements Response {
JSONObject chapterJSON = new JSONObject(); JSONObject chapterJSON = new JSONObject();
chapterJSON.put("id", chapter.getId()); chapterJSON.put("id", chapter.getId());
chapterJSON.put("name", chapter.getName()); chapterJSON.put("name", chapter.getName());
if (chapter.getStartDate() != null) chapterJSON.put("show", chapter.isInCurrentTime());
chapterJSON.put("startDate", chapter.getStartDate().toString());
if (chapter.getEndDate() != null)
chapterJSON.put("endDate", chapter.getEndDate().toString());
chaptersJSON.add(chapterJSON); chaptersJSON.add(chapterJSON);
} }
writer.response(200, "Access-Control-Allow-Origin: *"); writer.response(200, "Access-Control-Allow-Origin: *");