Commit 0f5cfb0d authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

stub of registration resource

parent 19918a59
......@@ -5,17 +5,12 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.ClassPath;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.telephoners.krakyournet.ctf.beans.Team;
import com.telephoners.krakyournet.ctf.beans.User;
import com.telephoners.krakyournet.ctf.commands.PurgeDatabaseCommand;
import com.telephoners.krakyournet.ctf.commands.RegisterTasksCommand;
import com.telephoners.krakyournet.ctf.commands.RegisterTeamsCommand;
import com.telephoners.krakyournet.ctf.core.ApplicationConfiguration;
import com.telephoners.krakyournet.ctf.logging.LoggingFilter;
import com.telephoners.krakyournet.ctf.modules.ApplicationModule;
import com.telephoners.krakyournet.ctf.repositories.Repository;
import io.dropwizard.Application;
import io.dropwizard.assets.AssetsBundle;
import io.dropwizard.jersey.setup.JerseyEnvironment;
......@@ -47,8 +42,8 @@ public class CTFApplication extends Application<ApplicationConfiguration>
JerseyEnvironment jersey = environment.jersey();
final ClassPath classPath = ClassPath.from(this.getClass().getClassLoader());
ImmutableSet<ClassPath.ClassInfo> resourceClasses = classPath.getTopLevelClasses("com.telephoners.krakyournet.ctf.resources");
// resourceClasses.stream()
// .forEach(classInfo -> jersey.register(injector.getInstance(classInfo.load())));
resourceClasses.forEach(classInfo -> jersey.register(injector.getInstance(classInfo.load())));
}
private void registerAuthFeatures(Environment environment)
......
package com.telephoners.krakyournet.ctf.resources;
import com.telephoners.krakyournet.ctf.beans.Team;
import com.telephoners.krakyournet.ctf.beans.User;
import com.telephoners.krakyournet.ctf.repositories.Repository;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
@Singleton
@Path(value = "/register")
@Produces(MediaType.APPLICATION_JSON)
public class RegistrationResource
{
private final Repository<Team> teamsRepository;
private final Repository<User> userRepository;
@Inject
public RegistrationResource(final Repository<User> userRepository,
final Repository<Team> teamsRepository)
{
//todo: checkNotNUll
this.teamsRepository = teamsRepository;
this.userRepository = userRepository;
}
@GET
@Path("/team")
public String registerTeam(@QueryParam("teamName") final String teamName)
{
Team team = new Team();
team.setName(teamName);
team.setDescription("descr");
teamsRepository.add(team);
return team.getId();
}
@GET
@Path("/user")
public void register(@QueryParam("userName") final String userName,
@QueryParam("teamId") final String teamId)
{
if (!teamsRepository.contains(teamId))
{
throw new RuntimeException("Team does not exist");
}
User user = new User();
user.setEmail("gpietrusza@gmail.com");
user.setName(userName);
user.setPassword("password");
user.setAdmin(false);
user.setTeamId(teamId);
}
}
package com.telephoners.krakyournet.ctf.resources;
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.repositories.Repository;
import io.dropwizard.auth.Auth;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
import java.util.Map;
@Singleton
@Path(value = "/solutions")
@Produces(MediaType.APPLICATION_JSON)
public class SolutionsResource
{
private final Repository<Team> teamsRepository;
private final Repository<Solution> solutionsRepository;
private final Repository<Task> tasksRepository;
@Inject
public SolutionsResource(Repository<Solution> solutionsRepository,
Repository<Task> tasksRepository,
Repository<Team> teamsRepository)
{
this.solutionsRepository = solutionsRepository;
this.teamsRepository = teamsRepository;
this.tasksRepository = tasksRepository;
@GET
public void get(){
}
// private final Repository<Team> teamsRepository;
// private final Repository<Solution> solutionsRepository;
// private final Repository<Task> tasksRepository;
//
// @Inject
// public SolutionsResource(Repository<Solution> solutionsRepository,
// Repository<Task> tasksRepository,
// Repository<Team> teamsRepository)
// {
// this.solutionsRepository = solutionsRepository;
// this.teamsRepository = teamsRepository;
// this.tasksRepository = tasksRepository;
// }
/*
@POST
@Path("/{task_level}")
public Response submitSolution(@Auth User user,
......@@ -47,7 +39,7 @@ public class SolutionsResource
{
return null;
//todo: this should be by id
/*
Task task = tasksRepository.getByLevel(taskLevel);
Flag flag = task.getFlags()
.stream()
......@@ -56,7 +48,7 @@ public class SolutionsResource
.orElseThrow(InvalidSolutionException::new);
solutionsRepository.submitSolution(new Solution(teamsRepository.getTeamByUser(user), task, flag));
return Response.ok().entity(flag).build();*/
return Response.ok().entity(flag).build();
}
@GET
......@@ -64,8 +56,8 @@ public class SolutionsResource
public List<Integer> getTeamCompletedTasks(@Auth User user)
{
return null;
/*
return solutionsRepository.getCompletedTasks(teamsRepository.getTeamByUser(user));*/
return solutionsRepository.getCompletedTasks(teamsRepository.getTeamByUser(user));
}
@GET
......@@ -73,22 +65,22 @@ return null;
public Map<String, List<Integer>> getAllTeamsCompletedTasks(@Auth User user)
{
return null;
/*
return teamsRepository.getAll()
.stream()
.collect(Collectors.toMap(
Team::getName,
solutionsRepository::getCompletedTasks
));*/
));
}
@GET
@Path("/my")
public Map<Integer, List<Flag>> getTeamSummittedFlags(@Auth User user) {
return null;
/*
Map<Integer, List<Flag>> teamSolutions = solutionsRepository.getTeamSolutions(teamsRepository.getTeamByUser(user));
return teamSolutions;*/
return teamSolutions;
}
@GET
......@@ -96,12 +88,12 @@ return null;
public Map<String, Map<Integer, Integer>> getTeamsSolutions()
{
return null;
/*
return teamsRepository.getAll()
.stream()
.collect(Collectors.toMap(
Team::getName,
solutionsRepository::getPointsSum
));*/
}
));
}*/
}
package com.telephoners.krakyournet.ctf.resources;
import com.telephoners.krakyournet.ctf.beans.User;
import com.telephoners.krakyournet.ctf.beans.tasks.Task;
import com.telephoners.krakyournet.ctf.repositories.Repository;
import io.dropwizard.auth.Auth;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
......@@ -20,13 +17,13 @@ import java.net.URISyntaxException;
@Path(value = "/task")
public class TaskResource
{
private final Repository<Task> tasksRepository;
@Inject
public TaskResource(Repository<Task> tasksRepository)
{
this.tasksRepository = tasksRepository;
}
// private final Repository<Task> tasksRepository;
//
// @Inject
// public TaskResource(Repository<Task> tasksRepository)
// {
// this.tasksRepository = tasksRepository;
// }
@Path("{task_level}/{path: .*}")
......
package com.telephoners.krakyournet.ctf.resources;
import com.telephoners.krakyournet.ctf.beans.tasks.Task;
import com.telephoners.krakyournet.ctf.repositories.Repository;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
......@@ -16,13 +14,13 @@ import java.util.List;
@Produces(MediaType.APPLICATION_JSON)
public class TasksResource
{
private final Repository<Task> tasksRepository;
@Inject
public TasksResource(Repository<Task> tasksRepository)
{
this.tasksRepository = tasksRepository;
}
// private final Repository<Task> tasksRepository;
//
// @Inject
// public TasksResource(Repository<Task> tasksRepository)
// {
// this.tasksRepository = tasksRepository;
// }
@GET
public List<Task> getTasksPublic()
......
package com.telephoners.krakyournet.ctf.resources;
import com.google.common.collect.ImmutableMap;
import com.telephoners.krakyournet.ctf.beans.Team;
import com.telephoners.krakyournet.ctf.beans.User;
import com.telephoners.krakyournet.ctf.core.ApplicationConfiguration;
import com.telephoners.krakyournet.ctf.repositories.Repository;
import io.dropwizard.auth.Auth;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
......@@ -23,22 +19,23 @@ import java.io.IOException;
public class UtilResource
{
private static String redirectHtml = "<!DOCTYPE html><html lang=\"en\" ng-app=\"ctfApp\"><head></head><script type=\"text/javascript\">window.location = \"http://\" + window.location.host;</script></html>";
private final Repository<Team> teamsRepository;
private final ApplicationConfiguration applicationConfiguration;
// private final Repository<Team> teamsRepository;
// private final ApplicationConfiguration applicationConfiguration;
@Inject
public UtilResource(Repository<Team> teamsRepository,
ApplicationConfiguration applicationConfiguration)
{
this.teamsRepository = teamsRepository;
this.applicationConfiguration = applicationConfiguration;
}
// @Inject
// public UtilResource(Repository<Team> teamsRepository,
// ApplicationConfiguration applicationConfiguration)
// {
// this.teamsRepository = teamsRepository;
// this.applicationConfiguration = applicationConfiguration;
// }
@GET
@Path("/startup")
public Response getStartupConfiguration()
{
return Response.ok().entity(applicationConfiguration.getStartupConfiguration()).build();
return null;
// return Response.ok().entity(applicationConfiguration.getStartupConfiguration()).build();
}
@GET
......
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