Fix admin puzzle details + implement puzzle list
This commit is contained in:
parent
710e3eccb8
commit
2560279ef4
2 changed files with 18 additions and 1 deletions
|
@ -25,7 +25,7 @@ public class GetPuzzle implements Response{
|
||||||
JsonMap json = new JsonMap();
|
JsonMap json = new JsonMap();
|
||||||
json.set("name", puzzle.getName());
|
json.set("name", puzzle.getName());
|
||||||
json.set("content", puzzle.getContent());
|
json.set("content", puzzle.getContent());
|
||||||
json.set("soluce", puzzle.getSoluce());
|
json.set("soluce", new String(puzzle.getSoluce()));
|
||||||
json.set("score_max", puzzle.getScoreMax());
|
json.set("score_max", puzzle.getScoreMax());
|
||||||
|
|
||||||
context.response(200);
|
context.response(200);
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
package dev.peerat.backend.routes.admins.puzzle;
|
package dev.peerat.backend.routes.admins.puzzle;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
|
import dev.peerat.backend.model.Puzzle;
|
||||||
import dev.peerat.backend.repository.DatabaseRepository;
|
import dev.peerat.backend.repository.DatabaseRepository;
|
||||||
import dev.peerat.framework.Context;
|
import dev.peerat.framework.Context;
|
||||||
import dev.peerat.framework.HttpReader;
|
import dev.peerat.framework.HttpReader;
|
||||||
import dev.peerat.framework.HttpWriter;
|
import dev.peerat.framework.HttpWriter;
|
||||||
import dev.peerat.framework.Response;
|
import dev.peerat.framework.Response;
|
||||||
import dev.peerat.framework.Route;
|
import dev.peerat.framework.Route;
|
||||||
|
import dev.peerat.framework.utils.json.JsonArray;
|
||||||
|
import dev.peerat.framework.utils.json.JsonMap;
|
||||||
|
|
||||||
public class GetPuzzles implements Response{
|
public class GetPuzzles implements Response{
|
||||||
|
|
||||||
|
@ -19,6 +23,19 @@ public class GetPuzzles implements Response{
|
||||||
|
|
||||||
@Route(path = "^/admin/puzzles/$", needLogin = true)
|
@Route(path = "^/admin/puzzles/$", needLogin = true)
|
||||||
public void exec(Matcher matcher, Context context, HttpReader reader, HttpWriter writer) throws Exception{
|
public void exec(Matcher matcher, Context context, HttpReader reader, HttpWriter writer) throws Exception{
|
||||||
|
List<Puzzle> puzzles = repo.getAdminPuzzles();
|
||||||
|
JsonArray array = new JsonArray();
|
||||||
|
for (Puzzle puzzle : puzzles){
|
||||||
|
JsonMap puzzleJSON = new JsonMap();
|
||||||
|
puzzleJSON.set("id", puzzle.getId());
|
||||||
|
puzzleJSON.set("name", puzzle.getName());
|
||||||
|
puzzleJSON.set("scoreMax", puzzle.getScoreMax());
|
||||||
|
if(puzzle.getTags() != null) puzzleJSON.set("tags", puzzle.getJsonTags());
|
||||||
|
puzzleJSON.set("show", puzzle.hasStarted());
|
||||||
|
array.add(puzzleJSON);
|
||||||
|
}
|
||||||
|
context.response(200);
|
||||||
|
writer.write(array.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue