Remove verif hour from front
This commit is contained in:
parent
4a499e3540
commit
03e64abf9c
3 changed files with 30 additions and 22 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -33,22 +33,24 @@ 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());
|
||||
JSONArray puzzles = new JSONArray();
|
||||
for (Puzzle puzzle : chapter.getPuzzles()){
|
||||
JSONObject puzzleJSON = new JSONObject();
|
||||
puzzleJSON.put("id", puzzle.getId());
|
||||
puzzleJSON.put("name", puzzle.getName());
|
||||
puzzleJSON.put("scoreMax", puzzle.getScoreMax());
|
||||
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);
|
||||
puzzles.add(puzzleJSON);
|
||||
boolean show = chapter.isInCurrentTime();
|
||||
chapterJSON.put("show", show);
|
||||
|
||||
if(show){
|
||||
JSONArray puzzles = new JSONArray();
|
||||
for (Puzzle puzzle : chapter.getPuzzles()){
|
||||
JSONObject puzzleJSON = new JSONObject();
|
||||
puzzleJSON.put("id", puzzle.getId());
|
||||
puzzleJSON.put("name", puzzle.getName());
|
||||
puzzleJSON.put("scoreMax", puzzle.getScoreMax());
|
||||
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);
|
||||
puzzles.add(puzzleJSON);
|
||||
}
|
||||
chapterJSON.put("puzzles", puzzles);
|
||||
}
|
||||
chapterJSON.put("puzzles", puzzles);
|
||||
|
||||
writer.response(200, "Access-Control-Allow-Origin: *");
|
||||
writer.write(chapterJSON.toJSONString());
|
||||
} else {
|
||||
|
|
|
@ -27,23 +27,20 @@ public class ChapterList implements Response {
|
|||
@RouteDoc(responseCode = 400, responseDescription = "Aucun chapitre trouver")
|
||||
|
||||
@Route(path = "^\\/chapters$", needLogin = true)
|
||||
public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception {
|
||||
public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception{
|
||||
List<Chapter> allChapters = databaseRepo.getAllChapters();
|
||||
if (allChapters != null) {
|
||||
if(allChapters != null){
|
||||
JSONArray chaptersJSON = new JSONArray();
|
||||
for (Chapter chapter : allChapters) {
|
||||
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: *");
|
||||
writer.write(chaptersJSON.toJSONString());
|
||||
} else {
|
||||
}else{
|
||||
writer.response(400, "Access-Control-Allow-Origin: *");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue