Commit 592b3bee authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

add completeted tasks endpoint

parent 827199c0
package com.telephoners.krakyournet.ctf.repositories;
import com.telephoners.krakyournet.ctf.core.ApplicationConfiguration;
import com.telephoners.krakyournet.ctf.helpers.DBObjectUtils;
import com.telephoners.krakyournet.ctf.beans.Flag;
import com.telephoners.krakyournet.ctf.beans.Solution;
import com.telephoners.krakyournet.ctf.beans.Team;
import com.telephoners.krakyournet.ctf.beans.User;
import com.telephoners.krakyournet.ctf.beans.tasks.Task;
import com.telephoners.krakyournet.ctf.core.ApplicationConfiguration;
import com.telephoners.krakyournet.ctf.helpers.DBObjectUtils;
import javafx.util.Pair;
import org.apache.commons.codec.binary.Hex;
import org.mongodb.morphia.Datastore;
......@@ -174,4 +174,18 @@ public class TasksRepository implements Repository
{
datastore.getCollection(Task.class).drop();
}
//todo: should it be here?
public List<Integer> getCompletedTasks(Team team)
{
Map<Integer, List<String>> teamSolutions = solutionsRepository.getTeamSolutions(team);
return getAll().stream()
.filter(task -> {
int numberOfFlags = task.getFlags().size();
List<String> teamTaskSolutions = teamSolutions.get(task.getLevel());
return teamTaskSolutions != null && teamTaskSolutions.size() == numberOfFlags;
})
.map(Task::getLevel)
.collect(Collectors.toList());
}
}
\ No newline at end of file
......@@ -48,6 +48,14 @@ public class SolutionsResource
return Response.status(Response.Status.NOT_ACCEPTABLE).build();
}
@GET
@Path("/completed")
public List<Integer> getTeamCompletedTasks(@Auth User user)
{
Optional<Team> team = teamsRepository.getTeamByUser(user);
return tasksRepository.getCompletedTasks(team.get());
}
@GET
@Path("/my")
public Map<Integer, List<String>> getTeamSolutions(@Auth User user)
......@@ -58,6 +66,7 @@ public class SolutionsResource
@GET
@Path("/all")
//todo: should return completed, not all flags?
public Map<String, Map<Integer, List<String>>> getTeamsSolutions()
{
return teamsRepository.getAll()
......
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