Commit 8765dfc9 authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

solutions refactored

parent de0d0c6f
......@@ -37,7 +37,7 @@ public class SolutionsResource {
.collect(Collectors.groupingBy(new Function<Solution, String>() {
@Override
public String apply(Solution solution) {
return solution.getTaskId();
return solution.getTaskName();
}
}))
.entrySet()
......
......@@ -2,23 +2,29 @@ package objects;
import com.google.common.collect.ImmutableMap;
import org.bson.Document;
import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Entity;
import java.util.Map;
/**
* Created by gpietrus on 20.02.2016.
*/
@Entity("solutions")
public class Solution {
private String taskId;
private ObjectId id;
private String taskName;
private String teamId;
public Solution(String teamId, String taskId) {
public Solution(String teamId, String taskName) {
this.teamId = teamId;
this.taskId = taskId;
this.taskName = taskName;
}
public String getTaskId() {
return taskId;
public Solution() {}
public String getTaskName() {
return taskName;
}
public String getTeamId() {
......@@ -26,7 +32,7 @@ public class Solution {
}
public Solution(Document document) {
this.taskId = document.get("taskId").toString(); //todo: refactor mapping
this.taskName = document.get("taskName").toString(); //todo: refactor mapping
this.teamId = document.get("teamId").toString();
}
......@@ -34,7 +40,7 @@ public class Solution {
public Map<String, String> toMap() {
return ImmutableMap.<String, String>builder()
.put("teamId",teamId)
.put("taskId", taskId)
.put("taskName", taskName)
.build();
}
}
......@@ -5,9 +5,6 @@ import org.mongodb.morphia.Datastore;
import javax.inject.Inject;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Created by gpietrus on 20.02.2016.
......@@ -25,25 +22,15 @@ public class SolutionsRepository implements Repository {
// }
public List<Solution> getAll() {
return null; //todo
/* return mongoDBConnector.getCollection("solutions")
.stream()
.map(Solution::new)
.collect(Collectors.toList());*/ //todo: revert
return datastore.createQuery(Solution.class).asList();
}
public void add(Solution solution) { //todo
//todo: object/string
Map<String, Object> retypedMap = solution.toMap().entrySet().stream()
.collect(Collectors.toMap(
(Function<Map.Entry<String, String>, String>) Map.Entry::getKey,
(Function<Map.Entry<String, String>, Object>) Map.Entry::getValue
));
// mongoDBConnector.addDocument("solutions", new Document(retypedMap)); //todo: revert
datastore.save(solution); //todo: error handling?
}
public void clean() {
// mongoDBConnector.removeCollection("solutions"); //todo: revert
datastore.getCollection(Solution.class).drop();
}
}
......
......@@ -40,6 +40,9 @@ public class UsersRepository implements Repository {
// }
public Optional<User> authenticateUser(BasicCredentials basicCredentials) {
return null;
/*
Optional<User> userOptional = 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