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;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;
public class Chapter {
@ -34,6 +35,14 @@ public class Chapter {
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() {
return startDate;
}

View file

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

View file

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