Commit cb3c2b61 authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

points stub

parent 5e4bf875
package com.telephoners.krakyournet.ctf.beans; package com.telephoners.krakyournet.ctf.beans;
import com.fasterxml.jackson.annotation.JsonIgnore;
public class Flag { public class Flag {
private String value; private String value;
private String description; private String description;
...@@ -14,10 +16,12 @@ public class Flag { ...@@ -14,10 +16,12 @@ public class Flag {
this.points = points; this.points = points;
} }
@JsonIgnore
public String getValue() { public String getValue() {
return value; return value;
} }
@JsonIgnore
public void setValue(String value) { public void setValue(String value) {
this.value = value; this.value = value;
} }
......
package com.telephoners.krakyournet.ctf.repositories; package com.telephoners.krakyournet.ctf.repositories;
import com.telephoners.krakyournet.ctf.beans.Flag;
import com.telephoners.krakyournet.ctf.beans.Solution; import com.telephoners.krakyournet.ctf.beans.Solution;
import com.telephoners.krakyournet.ctf.beans.Team; import com.telephoners.krakyournet.ctf.beans.Team;
import com.telephoners.krakyournet.ctf.beans.tasks.Task; import com.telephoners.krakyournet.ctf.beans.tasks.Task;
...@@ -26,7 +27,7 @@ public class SolutionsRepository extends Repository<Solution> ...@@ -26,7 +27,7 @@ public class SolutionsRepository extends Repository<Solution>
this.tasksRepository = tasksRepository; this.tasksRepository = tasksRepository;
} }
public Map<Integer, List<String>> getTeamSolutions(Team team) public Map<Integer, List<Flag>> getTeamSolutions(Team team)
{ {
//todo: do not identify team by name? conflict in team ids? //todo: do not identify team by name? conflict in team ids?
return datastore.createQuery(Solution.class) return datastore.createQuery(Solution.class)
...@@ -45,7 +46,7 @@ public class SolutionsRepository extends Repository<Solution> ...@@ -45,7 +46,7 @@ public class SolutionsRepository extends Repository<Solution>
.collect(Collectors.toMap( .collect(Collectors.toMap(
taskSolutions -> taskSolutions.getKey().getLevel(), taskSolutions -> taskSolutions.getKey().getLevel(),
taskSolutions -> taskSolutions.getValue().stream() taskSolutions -> taskSolutions.getValue().stream()
.map(solution -> solution.getFlag().getDescription()).collect(Collectors.toList()) .map(Solution::getFlag).collect(Collectors.toList())
)); ));
} }
...@@ -59,10 +60,10 @@ public class SolutionsRepository extends Repository<Solution> ...@@ -59,10 +60,10 @@ public class SolutionsRepository extends Repository<Solution>
public List<Integer> getCompletedTasks(Team team) public List<Integer> getCompletedTasks(Team team)
{ {
Map<Integer, List<String>> teamSolutions = getTeamSolutions(team); Map<Integer, List<Flag>> teamSolutions = getTeamSolutions(team);
return tasksRepository.getAll().stream() return tasksRepository.getAll().stream()
.filter(task -> { .filter(task -> {
List<String> teamTaskSolutions = teamSolutions.get(task.getLevel()); List<Flag> teamTaskSolutions = teamSolutions.get(task.getLevel());
return teamTaskSolutions != null && teamTaskSolutions.size() == task.getFlags().size(); return teamTaskSolutions != null && teamTaskSolutions.size() == task.getFlags().size();
}) })
.map(Task::getLevel) .map(Task::getLevel)
......
...@@ -76,7 +76,7 @@ public class SolutionsResource ...@@ -76,7 +76,7 @@ public class SolutionsResource
@GET @GET
@Path("/all") @Path("/all")
public Map<String, Map<Integer, List<String>>> getTeamsSolutions() public Map<String, Map<Integer, List<Flag>>> getTeamsSolutions()
{ {
return teamsRepository.getAll() return teamsRepository.getAll()
.stream() .stream()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment