Commit bf3e805b authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

/solutions/all - return points instead of flags

parent fc51bc66
...@@ -79,4 +79,19 @@ public class SolutionsRepository extends Repository<Solution> ...@@ -79,4 +79,19 @@ public class SolutionsRepository extends Repository<Solution>
} }
add(solution); add(solution);
} }
private int calculatePointsSum(List<Flag> flags) {
return flags.stream()
.mapToInt(Flag::getPoints)
.sum();
}
public Map<Integer, Integer> getPointsSum(Team team) {
return getTeamSolutions(team).entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> calculatePointsSum(entry.getValue())
));
}
} }
\ No newline at end of file
...@@ -76,14 +76,13 @@ public class SolutionsResource ...@@ -76,14 +76,13 @@ public class SolutionsResource
@GET @GET
@Path("/all") @Path("/all")
public Map<String, Map<Integer, List<Flag>>> getTeamsSolutions() public Map<String, Map<Integer, Integer>> getTeamsSolutions()
{ {
return teamsRepository.getAll() return teamsRepository.getAll()
.stream() .stream()
.collect(Collectors.toMap( .collect(Collectors.toMap(
Team::getName, Team::getName,
solutionsRepository::getTeamSolutions solutionsRepository::getPointsSum
)); ));
} }
} }
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